You are on page 1of 45

💜

Av. Java QB
1. Explain OSI model in brief with diagram.

physical layer:

lowest layer

responsible for the actual physical connection between the devices

information ⇒ bits
When receiving data, this layer will convert it into bits and send them to the
Data Link layer, which will put the frame back together.

Functions of this layer:

Bit synchronization

Bit rate control

Physical topologies

Transmission mode

Data Link Layer

node-to-node delivery of the message

make sure data transfer is error-free

Av. Java QB 1
When a packet arrives in a network, DLL transmits it to the Host using its
MAC address.

Sublayers:

1. Logical Link Control (LLC)

2. Media Access Control (MAC)

Functions:

Framing

Physical addressing

Error control

Flow Control

Access control

Network Layer:

transmission of data

takes care of packet routing

Functions:

Routing

Logical Addressing

Transport Layer:

provides services to the application layer

takes services from the network layer

End to End Delivery of the message

At sender’s side

performs Segmentation on data received from above layers

implements Flow & Error control

forwards the segmented data to the Network Layer.

At receiver’s side:

forwards the Data to the respective application

functions:

Av. Java QB 2
Segmentation and Reassembly

Service Point Addressing

Session Layer

establishment of connection, maintenance of sessions, authentication, and


also ensures security.

Functions:

Session establishment, maintenance, and termination

Synchronization

Dialog Controller

Presentation Layer

Translation layer

extraction and manipulation of data

Functions:

Translation

Encryption/ Decryption

Compression

Application Layer

implemented by the network applications

window for the application services to access the network and for displaying
information to the user.

Functions:

Network Virtual Terminal

FTAM-File transfer access and management

Mail Services

Directory Services

2. Write a short note on socket programming with server socket and client
socket.

used for communication between the applications running on different JRE

Av. Java QB 3
connection-oriented ⇒ Socket and ServerSocket classes
or connection-less ⇒ DatagramSocket and DatagramPacket classes

client must know: IP Address of Server & Port number

Socket class

used to create a socket.

Method Description

returns the InputStream attached with this


1) public InputStream getInputStream()
socket.

2) public OutputStream returns the OutputStream attached with this


getOutputStream() socket.

3) public synchronized void close() closes this socket

ServerSocket class

create a server socket

Method Description

returns the socket and establish a connection between


1) public Socket accept()
server and client.
2) public synchronized void
closes the server socket
close()

Example

Creating Server:

Av. Java QB 4
create the instance of ServerSocket class

accept() ⇒ If clients connect with port number, it returns an instance of


Socket.

ServerSocket ss=new ServerSocket(6666);


Socket s=ss.accept();//establishes connection and waits for the client

Creating Client

create the instance of Socket class.

Socket s=new Socket("localhost",6666);

MyServer.java

import java.io.*;
import java.net.*;
public class MyServer {
public static void main(String[] args){
try{
ServerSocket ss=new ServerSocket(6666);
Socket s=ss.accept();//establishes connection
DataInputStream dis=new DataInputStream(s.getInputStream());
String str=(String)dis.readUTF();
System.out.println("message= "+str);
ss.close();
}catch(Exception e){System.out.println(e);}
}
}

MyClient.java

import java.io.*;
import java.net.*;
public class MyClient {
public static void main(String[] args) {
try{
Socket s=new Socket("localhost",6666);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("Hello Server");
dout.flush();
dout.close();
s.close();
}catch(Exception e){System.out.println(e);}
}
}

Av. Java QB 5
3. Write a short note on:

RPC

technique for constructing distributed, client-server based applications.

based on extending the conventional local procedure calling so that


the called procedure need not exist in the same address space as the
calling procedure

The following steps take place during a RPC

A client invokes a client stub procedure, passing parameters in the


usual way.

The client stub marshalls(pack) the parameters into a message.

The client stub passes the message to the transport layer, which sends
it to the remote server machine.

On the server, server stub, which demarshalls(unpack) the


parameters and calls the desired server routine using the regular
procedure call mechanism.

When the server procedure completes, it returns to the server stub,


which marshalls the return values into a message. The server stub then
hands the message to the transport layer.

Av. Java QB 6
The transport layer sends the result message back to the client
transport layer

The client stub demarshalls the return parameters and execution


returns to the caller.

Stub and Skeleton

A stub for a remote object acts as a client’s local representative or proxy for the
remote object. The caller invokes a method on the local stub which is
responsible for carrying out the method call on the remote object.
The stub hides the serialization of parameters and the network-level
communication in order to present a simple invocation mechanism to the caller.

The skeleton is responsible for dispatching the call to the actual remote object
implementation.
When a skeleton receives an incoming method invocation it does the following:

1.reads the parameters for the remote method,

2.invokes the method on the actual remote object implementation.

3.writes and transmits the result (return value or exception) to the caller.

Multicast Socket

useful for sending and receiving IP multicast packets

is a (UDP) DatagramSocket, with additional capabilities for joining "groups"


of other multicast hosts

A multicast group is specified by a class D IP address and by a standard


UDP port number.

When one sends a message to a multicast group, all subscribing recipients


to that host and port receive the message

The socket needn't be a member of the multicast group to send messages


to it.

When a socket subscribes to a multicast group/port, it receives datagrams


sent by other hosts to the group/port, as do all other members of the group
and port.

4. Explain the process of creating a simple RMI application.

Steps to create RMI Application

Step 1: Defining a remote interface

Av. Java QB 7
create an interface ⇒ provide a description of the methods
Step 2: Implementation of remote interface

implement the remote interface

class should extend to the UnicastRemoteObject class of java.rmi


package

Step 3: Creating Stub and Skeleton objects from the implementation


class using rmic

The RMIC tool is used to invoke the RMI compiler that creates the Stub
and Skeleton objects. Its prototype is RMIC class name.

STEP 4: Start the RMIregistry

You need to start the registry service by issuing the command at the
command prompt start RMIregistry

STEP 5: Create and execute the server application program

The server program uses the createRegistry to create rmiregistry

rebind method ⇒ bind the remote object to the new name.


Step 6: Create and execute the Client Application program

create the Client Application program and execute it on a separate


command prompt

💡 The RMI is an API that provides a mechanism to create a distributed


application in Java. The RMI allows an object to invoke methods on an
object running in another JVM.

5. Explain computer network with network devices.

💡 A computer network is a system that connects two or more


computing devices for transmitting and sharing information.

Repeater

operates at the physical layer

regenerates the signal over the same network before the signal becomes
too weak

Av. Java QB 8
do not amplify the signal

When the signal becomes weak, they copy it bit by bit and regenerate it at
its star topology connectors

Hub

multi-port repeater

for example, the connector in star topology which connects different


stations

data packets are sent to all connected devices.

cannot find the best path for data packets

Types of Hub

Active Hub

These are the hubs that have their power supply and can clean,
boost, and relay the signal along with the network.

Passive Hub

These are the hubs that collect wiring from nodes and power supply
from the active hub.

relay signals onto the network without cleaning and boosting them

Intelligent Hub

It works like an active hub and includes remote management


capabilities.

Bridge

A bridge is a repeater, with add on the functionality of filtering content by


reading the MAC addresses of the source and destination

Types of Bridges

Transparent Bridges

stations are completely unaware of the bridge’s existence

Source Routing Bridges

routing operation is performed by the source station and the frame


specifies which route to follow.

Switch

Av. Java QB 9
a multiport bridge with a buffer and a design that can boost its efficiency
and performance

can perform error checking before forwarding data

Routers

routes data packets based on their IP addresses.

a Network Layer device

connect LANs and WANs and have a dynamically updating routing table

Gateway

passage to connect two networks that may work upon different networking
models.

Gateways are also called protocol converters

Brouter

the bridging router

can work either at the data link layer or a network layer

it is capable of routing packets across networks and it is capable of filtering


local area network traffic.

NIC

a network adapter that is used to connect the computer to the network.

It is installed in the computer to establish a LAN.

Av. Java QB 10
6. Brief note on computer network with network types.

Personal Area Network (PAN)

network is restrained to a single person

network range of 10 meters from a person to the device

USB, computer, phone, tablet, printer, PDA, etc.

Local Area Network (LAN)

most frequently used

connects computers together through a common communication path

Examples of LAN are networking in a home, school, library, laboratory,


college, office, etc.

Wide Area Network (WAN)

connects computers over a large geographical distance

extends over many locations

a group of local area networks that communicate with each other.

Wireless Local Area Network (WLAN)

acts as a local area network but makes use of wireless network

The most common example is Wi-Fi.

Campus Area Network (CAN)

bigger than a LAN but smaller than a MAN

Examples of CAN are networks that cover schools, colleges, buildings, etc.

Metropolitan Area Network (MAN)

larger than a LAN but smaller than a WAN

Examples are networking in towns, cities, a single large city, large area
within multiple buildings, etc.

Storage Area Network (SAN)

high speed and connects groups of storage devices to several servers.

does not depend on LAN or WAN

Av. Java QB 11
Examples are a network of disks accessed by a network of servers.

System Area Network (SAN)

connects a cluster of high-performance computers

connection-oriented and high bandwidth network

Passive Optical Local Area Network (POLAN)

alternative to a LAN

uses optical splitters to split of single mode optical fibre to multiple signals
to distribute users and devices.

Enterprise Private Network (EPN)

mostly used by businesses that want a secure connection over various


locations to share computer resources.

Virtual Private Network (VPN)

extends a private network across the internet and lets the user send and
receive data as if they were connected to a private network even though
they are not.

Home Area Network (HAN)

local area network (LAN) within that home.

7. Short note on:

network types

Personal Area Network (PAN)

network is restrained to a single person

network range of 10 meters from a person to the device

USB, computer, phone, tablet, printer, PDA, etc.

Local Area Network (LAN)

most frequently used

connects computers together through a common communication path

Av. Java QB 12
Examples of LAN are networking in a home, school, library, laboratory,
college, office, etc.

Wide Area Network (WAN)

connects computers over a large geographical distance

extends over many locations

a group of local area networks that communicate with each other.

Wireless Local Area Network (WLAN)

acts as a local area network but makes use of wireless network

The most common example is Wi-Fi.

Campus Area Network (CAN)

bigger than a LAN but smaller than a MAN

Examples of CAN are networks that cover schools, colleges, buildings,


etc.

Metropolitan Area Network (MAN)

larger than a LAN but smaller than a WAN

Examples are networking in towns, cities, a single large city, large area
within multiple buildings, etc.

Storage Area Network (SAN)

high speed and connects groups of storage devices to several servers.

does not depend on LAN or WAN

Examples are a network of disks accessed by a network of servers.

System Area Network (SAN)

connects a cluster of high-performance computers

connection-oriented and high bandwidth network

Passive Optical Local Area Network (POLAN)

alternative to a LAN

Av. Java QB 13
uses optical splitters to split of single mode optical fibre to multiple
signals to distribute users and devices.

Enterprise Private Network (EPN)

mostly used by businesses that want a secure connection over various


locations to share computer resources.

Virtual Private Network (VPN)

extends a private network across the internet and lets the user send
and receive data as if they were connected to a private network even
though they are not.

Home Area Network (HAN)

local area network (LAN) within that home.

topologies

Mesh Topology:

every device is connected to another device via a particular channel.

protocols used are AHCP, DHCP

total number of ports that are required by each device is N-1

total number of dedicated links required to connect them is N


C2

Advantages

fast communication

Av. Java QB 14
fault is diagnosed easily

secure and private

Problems

Installation and configuration are difficult.

The cost of cables is high

The cost of maintenance is high.

Star Topology:

all the devices are connected to a single hub through a cable.

hub can be passive or active in nature

Advantages

easy to set up.

requires only 1 port

robust

easy fault identification

cost-effective

Problems

hub failure = system failure

high installation cost

Performance is based on the hub.

Bus Topology:

Av. Java QB 15
every computer and network device is connected to a single cable

bi-directional

multi-point connection and a non-robust topology

Advantages

1 cable for N devices

Coaxial or twisted pair cables are mainly used in bus-based


networks

The cost of the cable is less

familiar technology

Problems

lot of cabling

common cable failure = system crash

heavy network traffic ⇒ collisions


adding devices ⇒ slow network
less secure

Ring Topology:

A number of repeaters are used to prevent data loss

Av. Java QB 16
data flows in one direction

most common access method

Token passing

Token

Advantages

The data transmission is high-speed.

collision is minimum

Cheap to install and expand

less costly

Problems

failure of a single node ⇒ network fail


Troubleshooting is difficult

addition or removal of stations can disturb the whole topology

Tree Topology:

variation of the Star topology

has a hierarchical flow of data

protocols like DHCP and SAC (Standard Automatic Configuration ) are


used.

Advantages

allows more devices to be attached to a single central hub

Av. Java QB 17
It allows the network to get isolated and also prioritize from different
computers.

can add new devices to the existing network.

Error detection and error correction are very easy

Problems

central hub fails ⇒ system failure


cost is high

difficult to reconfigure.

network devices

Repeater

operates at the physical layer

regenerates the signal over the same network before the signal
becomes too weak

do not amplify the signal

When the signal becomes weak, they copy it bit by bit and regenerate it
at its star topology connectors

Hub

multi-port repeater

for example, the connector in star topology which connects different


stations

data packets are sent to all connected devices.

cannot find the best path for data packets

Types of Hub

Active Hub

These are the hubs that have their power supply and can clean,
boost, and relay the signal along with the network.

Passive Hub

These are the hubs that collect wiring from nodes and power
supply from the active hub.

Av. Java QB 18
relay signals onto the network without cleaning and boosting
them

Intelligent Hub

It works like an active hub and includes remote management


capabilities.

Bridge

A bridge is a repeater, with add on the functionality of filtering content


by reading the MAC addresses of the source and destination

Types of Bridges

Transparent Bridges

stations are completely unaware of the bridge’s existence

Source Routing Bridges

routing operation is performed by the source station and the


frame specifies which route to follow.

Switch

a multiport bridge with a buffer and a design that can boost its efficiency
and performance

can perform error checking before forwarding data

Routers

Av. Java QB 19
routes data packets based on their IP addresses.

a Network Layer device

connect LANs and WANs and have a dynamically updating routing


table

Gateway

passage to connect two networks that may work upon different


networking models.

Gateways are also called protocol converters

Brouter

the bridging router

can work either at the data link layer or a network layer

it is capable of routing packets across networks and it is capable of


filtering local area network traffic.

NIC

a network adapter that is used to connect the computer to the network.

It is installed in the computer to establish a LAN.

8. Elaborate web application development with 2 and 3 tier architecture.

2 tier architecture

like client server application

direct communication

no intermediate between client and server

tight coupling ⇒ faster application


two parts:

1. Client tier

2. Data tier

Av. Java QB 20
the code is written for saving the data in the SQL server database.

Client sends the request to the server and it processes the request
& sends it back with data.

main problem of two tier architecture is the server cannot respond


to multiple requests at the same time ⇒ data integrity issue.
Advantages:

1. Easy to maintain and modification is bit easy

2. Communication is faster

Disadvantages:

1. In two tier architecture application performance will be


degraded as soon as the number of users increases.

2. Cost-ineffective

When you design the solution for web- application you have to keep
in mind the below points:

1. Availability

2. Security

3. Performance

4. Reliability

5. Cost Optimization

3 tier architecture

Av. Java QB 21
it is a modular client-server architecture

consists of presentation tier, an application tier and a data tier.

Presentation tier

built with HTML5, cascading style sheets and JavaScript

deployed to a computing device through a web browser

communicates with the other tiers through application program interface


calls.

Application tier

written in a programming language such as java and contains


the business logic that supports the application's core functions.

can either be hosted on distributed servers in the cloud or on a


dedicated in-house server

Data tier

consists of a database and a program for managing read and write


access to a database.

can be hosted on premises or in the cloud

Benefits

1. horizontal scalability

2. performance

Av. Java QB 22
3. availability

4. concurrent development

5. relocation of modules without affecting other tiers

6. easy to evolve

7. critical parts can be permanently encapsulated within new tier

9. Explain servlet with lifecycle and an example.

https://www.geeksforgeeks.org/life-cycle-of-a-servlet/

https://www.tutorialspoint.com/servlets/servlets-first-example.htm#

10. Difference between:

Servlet vs CGI

Basis Servlet CGI

It is thread based i.e. for


It is process-based i.e. for every new
Approach every new request new
request new process is created.
thread is created.
The codes are written in
The codes are written any programming
Language Used JAVA programming
language.
language.

Since codes are written in Since codes are written in any language,
Java, it is object oriented all the languages are not object-oriented
Object-Oriented
and the user will get the thread-based. So, the user will not get
benefits of OOPs the benefits of OOPs

Portability It is portable. It is not portable.

It remains in the memory It is removed from the memory after the


Persistence until it is not explicitly completion of the process-based
destroyed. request.

Server It can use any of the web- It can use the web-server that supports
Independent server. it.

Data Sharing Data sharing is possible. Data sharing is not possible.

It links directly to the It does not link the web server directly to
Link
server. the server.
It can read and set HTTP It can neither read nor set HTTP
HTTP server
servers. servers.

Construction and
Construction and destruction of the new
Cost destruction of new
processes are costly.
threads are not costly.

Av. Java QB 23
Speed It’s speed is slower. It’s speed is faster.

Platform It can be Platform


It can be not Platform dependent.
dependency dependent

Servlet with JDBC

💡 Servlets are the Java programs that run on the Java-enabled web
server or application server.

Step 1: Create Table in PostgreSQL

Create a Table studentdetails to store details of students.

Add columns

Step 2: Create a Dynamic web project in Eclipse

In Eclipse IDE, create a Dynamic web project

To connect with PostgreSQL DB, add “postgresql-123.jar” in the project


under “WEB-INF/lib” folder.

Step 3: Create required JSP’s to get the details from the student

Home.jsp

<tr>
<td>To insert your details into the Database:</td>
<td><input type="button" value="Insert data"
onclick="window.location.href='Insert.jsp'" /></td>
</tr>
<tr>
<td>To delete your details from the Database:</td>
<td><input type="button" value="Delete data"
onclick="window.location.href='Delete.jsp'" /></td>
</tr>

Insert.jsp

<tr><form action="./InsertDetails" method="post">


<td>ID:</td>
<td><input type="text" name="id" maxlength="6" size="7" /></td>
</tr>
<input type="submit" value="Insert Data" />
</form>
<input type="button" value="Return to Home"
onclick="window.location.href='Home.jsp'" />

Av. Java QB 24
Step 4: Create DBUtil.java

To establish a JDBC connection with PostgreSQL, we need to specify


the driver, URL, username, and password objects of the PostgreSQL. In
order to reuse these objects in all the servlets to make a connection
with the DB, we can provide these values in separate class like below.

public class DbUtil {

public static String url = "jdbc:postgresql://localhost/postgres";


public static String user = "root";
public static String password = "root";
public static String driver = "org.postgresql.Driver";

Step 5: Create respective servlet classes

Servlet classes and JSP pages can be mapped through web.xml.

import all the required packages

doPost() ⇒ insert details


establish the JDBC connection inside the try/catch block

Class.forName() ⇒ load the PostgreSQL driver


Prepare statement object with the insert query

close the statement and connection object

Then redirect the page to respective page.

Step 6: Run the Application

Run As -> Run on Server

The application will be deployed on the Tomcat server

Run the URL to get home page of the application

click on Insert data

After successful insertion, a success message will be displayed on the


screen.

Check if the data is inserted successfully in PostgreSQL DB.

fetch the values from the DB, click on Select Data on the Home page.

HTTP tunneling

Av. Java QB 25
HTTP tunneling is the process in which communications are encapsulated
by using HTTP protocol.

used for network locations which have restricted connectivity or are behind
firewalls or proxy servers.

sits between a group of client users and the wider outside Internet

to protect the internal client network from unauthorized access

outside traffic, most network protocols are restricted except a few.

If a user, for example, in a corporate environment has no permission to


open TCP connections the user cannot use certain services or connect to
the internet.

In HTTP tunneling, HTTP protocol acts as a wrapper for a channel that the
network protocol being tunneled uses to communicate.

HTTP tunnel software is used for this purpose and allows communication
with restricted network connectivity.

application ⇒ tunneling client


HTTP tunnel clients are used to access applications from behind restrictive
firewalls or proxy servers, to access blocked sites, or to share confidential
resource over HTTP securely.

Servlet chaining

💡 If a client request is processed by group of servlets, then that servlets


are known as servlet chaining or if the group of servlets process a
single client request then those servlets are known as servlet
chaining.

Forward model:

we forward a request to a group of servlets, finally we get the result of


destination servlet as a response but not the result of intermediate
servlets.

Av. Java QB 26
Include model:

If a single client request is passed to a servlet and that servlet makes


use of other group of servlets to process a request by including the
group of servlets into a single servlet.

Steps for DEVELOPING Servlet Chaining:

1. Obtain an object of ServletContext

ServletContext ctx1=getServletContext (); [GenericServlet method]


ServletContext ctx2=config.getServletContext (); [ServletConfig method]
ServletContext ctx3=req.getServletContext (); [HttpServletRequest method]

2. Obtain an object of RequestDispatcher.

RequestDispatcher rd=ctx.getRequestDispatcher ("./s2");

3. Use forward or include model to send the request and response


objects.

rd.forward (req, res) throws ServletException, IOException


rd.include (req, res) throws ServletException, IOException

Deployment description

💡 A web application's deployment descriptor maps the http request with


the servlets.

It resides in the application's WAR file under the WEB-INF/ directory

⇒ <web-app>. <servlet> element


root element

map a URL to servlet ⇒ <servlet-mapping> element

Av. Java QB 27
<servlet> ⇒ declares the servlet class and a logical name used to refer to
the servlet by other elements in the file.

<servlet-mapping> ⇒ specifies a URL pattern and the name of a declared


servlet

The standard does not support wildcards in the middle of a string, and does
not allow multiple wildcards in one pattern.

The URL path cannot start with a period (.)

Servlet with HTML

https://www.geeksforgeeks.org/servlet-form/

session management

💡 Servlet Session Management is a mechanism in Java used by Web


container to store session information.

Why is Session Maintained?

In case of continuous request and response from the same client to


server, server cannot identify which client requests are being sent since
HTTP is a stateless protocol.

Session Management / Tracking Methods

User Authorization:

login credentials of the user are passed via server and client to
maintain the servlet session.

URL rewriting:

User can append session identifier parameter with every request


and response to keep track of session.

Hidden Fields:

User has access to create unique field in HTML which is hidden,


when user starts navigating, user will be able to set the value
uniquely to customer and have track over the session.

Session Tracking API:

This type of session tracking is used for developers to minimize


overhead of session tracking.

Av. Java QB 28
Cookies:

Cookie is a key value pair of information sent by server to


browsers. It is the most used technology for session tracking.
Cookie is a smallest piece of information sent by the web server in
head tag and is stored as browser cookie.

HTTP and SSL:

Browsers that support Secure Socket Layer communication use


SSL support via HTTPS to generate unique session key as part of
encrypted conversation.

How to Create New Session Object and Enable?

1. Make a new session object.

2. Store information in session object.

3. Look up for information associated with Servlet.

11. Explain Jasper report generation and calling using servlet.

💡 JasperReports is an open source java reporting engine. JasperReports is


a Java class library, and it is meant for those Java developers who need
to add reporting capabilities to their applications

Jasper report generation

1. open the file menu, select new and then click jasper report

2. Select coffee and click next

3. select the folder in the workspace where you want to put the report and
name the new report

4. click next

5. choose sample DB - database JDBC connection

6. left hand list shows all the discovered fields, the right hand list shows those
that will be added to the report

7. after selecting the fields click next

8. click next

9. click finish

Av. Java QB 29
calling jasper report

Connect to JasperReports Server to test report changes you make


in Jaspersoft Studio. See Connecting to JasperReports Server.

Navigate to your report's JRXML, and click Run Report Unit. If prompted to
save the report unit, specify a location on your local computer and click OK.
If the report has input controls that require values, you'll be prompted to
specify them. The report appears in a browser window.

12. Short note on: Servlet context and config object.

ServletContext

An object of ServletContext is created by the web container at time of


deploying the project.

Advantage of ServletContext

easy to maintain

it is better to make it available for all the servlet

Usage of ServletContext Interface

The object of ServletContext provides an interface between the


container and servlet.

can be used to get configuration information

can be used to set, get or remove attribute from the web.xml file.

can be used to provide inter-application communication.

Commonly used methods of ServletContext interface

public String getInitParameter(String name)

public Enumeration getInitParameterNames()

public void setAttribute(String name,Object object):

public Object getAttribute(String name):

public Enumeration getInitParameterNames()

public void removeAttribute(String name)

How to get the object of ServletContext interface

getServletContext() method

getServletContext() method

Av. Java QB 30
config object

💡 The config object is an instantiation of javax.servlet.ServletConfig


and is a direct wrapper around the ServletConfig object for the
generated servlet.

This object allows the JSP programmer access to the Servlet or JSP engine
initialization parameters such as the paths or file locations etc.

The following config method is the only one you might ever use, and its
usage is trivial

config.getServletName();

This returns the servlet name, which is the string contained in the <servlet-
name> element defined in the WEB-INF\web.xml file.

13. Explain how servlet handles event?

https://www.cosmiclearn.com/servlet/eventhandling.php

14. Difference between: Servlet and JSP

Servlet JSP

Servlet is a java code. JSP is a HTML based code.

Writing code for servlet is harder than JSP as it


JSP is easy to code as it is java in HTML.
is HTML in java.
Servlet plays a controller role in the hasMVC JSP is the view in the MVC approach for
approach. showing output.
JSP is slower than Servlet because the first
step in the hasJSP lifecycle is the
Servlet is faster than JSP.
translation of JSP to java code and then
compile.

Servlet can accept all protocol requests. JSP only accepts HTTP requests.

In Servlet, we can override the service() In JSP, we cannot override its service()
method. method.
In Servlet by default session management is In JSP session management is
not enabled, user have to enable it explicitly. automatically enabled.
In Servlet we have to implement everything like In JSP business logic is separated from
business logic and presentation logic in just presentation logic by using
one servlet file. JavaBeansclient-side.

Av. Java QB 31
Modification in Servlet is a time-consuming JSP modification is fast, just need to click
compiling task because it includes reloading, the refresh button.
recompiling, JavaBeans and restarting the
server.
It does not have inbuilt implicit objects. In JSP there are inbuilt implicit objects.

While running the JavaScript at the client


There is no method for running JavaScript on
side in JSP, the client-side validation is
the client side in Servlet.
used.
Packages can be imported into the JSP
Packages are to be imported on the top of the
program(i.e., bottom , middleclient-side, or
program.
top )

15. Explain basic tags of JSP in detail.

16. Explain the MVC architecture in detail.

https://www.javatpoint.com/mvc-architecture-in-java

17. Brief note on java server tag libraries.

https://www.tutorialspoint.com/jsp/jsp_standard_tag_library.htm#:~:text=The
JavaServer Pages Standard Tag,internationalization tags%2C and SQL tags.

18. Write a short note on:

basic tags

<%-- Counter.jsp --%> <%-- Comment Tag --%>

<%@ page language="java" %> <%-- Directive Tag --%>


<%! int count = 0; %> <%-- Declaration Tag --%>
<% count++; %> <%-- Scriptlet Tag --%>
Welcome! You are visitor number
<%= count %> <%-- Expression Tag --%>

JSP Tag Brief Description Tag Syntax

Specifies translation time instructions


Directive <%@ directives %>
to the JSP engine.
Declaration Declares and defines <%! variable dceclaration &
Declaration
methods and variables. method definition %>
Allows the developer to write free-form
Scriptlet <% some Java code %>
Java code in a JSP page.
Used as a shortcut to print values in
Expression <%= an Expression %>
the output HTML of a JSP page.

Action Provides request-time instructions to <jsp:actionName />

Av. Java QB 32
the JSP engine.

Used for documentation and for


Comment <%– any Text –%>
commenting out parts of JSP code.

basic objects

The request Object

instance of a javax.servlet.http.HttpServletReqt
object.

Each time a client requests a page the JSP engine creates a new
object to represent that request.

The response Object

instance of a javax.servlet.http.HttpServletRese
object.

defines the interfaces that deal with creating new HTTP headers.

programmer can add new cookies or date stamps, HTTP status codes,
etc.

The out Object

S.No. Method & Description

1 out.print(dataType dt) Print a data type value

out.println(dataType dt) Print a data type value then terminate


2
the line with new line character.
3 out.flush() Flush the stream.

an instance of a javax.servlet.jsp.JspWriter
object and is used to send content in a response.

The session Object

an instance of javax.servlet.http.HttpSession
and behaves exactly the same way that session objects behave under
Java Servlets.

used to track client session between client requests

The application Object

direct wrapper around the ServletContext object for the generated


Servlet and in reality an instance of a javax.servlet.ServletContext
object.

Av. Java QB 33
The config Object

an instantiation of javax.servlet.ServletConfig and is a direct wrapper


around the ServletConfig object for the generated servlet.

This object allows the JSP programmer access to the Servlet or JSP
engine initialization parameters such as the paths or file locations etc.

The pageContext Object

an instance of a javax.servlet.jsp.PageContext object.

This object is intended as a means to access information about the


page while avoiding most of the implementation details.

The page Object

This object is an actual reference to the instance of the page. It can be


thought of as an object that represents the entire JSP page.

The exception Object

The exception object is a wrapper containing the exception thrown from


the previous page. It is typically used to generate an appropriate
response to the error condition.

action tags

💡 is used to remove or eliminate Scriptlet code from your JSP code as


JSP Scriptlets are obsolete. The action tag is also implemented to
streamline flow between pages and to employ a Java Bean.

JSP Action Tags Description

jsp:forward forwards the request and response to another resource.

jsp:include includes another resource.

jsp:useBean creates or locates bean object.

jsp:setProperty sets the value of property in bean object.

jsp:getProperty prints the value of property of the bean.

jsp:plugin embeds other components such as applet.

jsp:param sets the parameter value. It is used in forward and include mostly.

can be used to print the message if plugin is working. It is used in


jsp:fallback
jsp:plugin.

Av. Java QB 34
java server tag library

https://www.tutorialspoint.com/jsp/jsp_standard_tag_library.htm#:~:text=The
JavaServer Pages Standard Tag,internationalization tags%2C and SQL tags.

19. Explain the role of MVC in servlet and JSP.

https://www.javaguides.net/2019/08/java-mvc-web-application-using-jsp-and-
servlet.html

a simple alternative - https://www.javatpoint.com/mvc-architecture-in-java

20. Difference between hibernate and JDBC.

S.NO JDBC Hibernate

In JDBC, one needs to write


Hibernate maps the object model’s
code to map the object model’s
1. data to the schema of the database
data representation to the
itself with the help of annotations.
schema of the relational model.
JDBC enables developers to Hibernate uses HQL (Hibernate
create queries and update data Query Language) which is similar to
2. to a relational database using the SQL but understands object-oriented
Structured Query Language concepts like inheritance, association
(SQL). etc.
JDBC code needs to be written
Whereas Hibernate manages the
in a try catch block as it throws
3. exceptions itself by marking them as
checked
unchecked.
exception(SQLexception).
Whereas Hibernate is database
JDBC is database dependent i.e.
independent and same code can work
4. one needs to write different
for many databases with minor
codes for different database.
changes.

Associations like one-to-one, one-to-


Creating associations between many, many-to-one, and many-to-
5.
relations is quite hard in JDBC. many can be acquired easily with the
help of annotations.

21. Short note on: Architecture of hibernate.

Av. Java QB 35
Configuration:

It activates Hibernate framework.

reads both configuration file and mapping files.

checks syntax of config file

invalid config file ⇒ exception


SessionFactory:

an Interface used to create Session Object.

immutable and thread-safe in nature

Session:

It opens the Connection/Session with Database software through Hibernate


Framework.

light-weight object and it is not thread-safe

perform CRUD operations

Transaction:

used when we perform any operation and based upon that operation there
is some change in database.

give the instruction to the database to make the changes that happen
because of operation as a permanent by using commit() method.

Query:

A Query instance is obtained by calling Session.createQuery().

extra functionality

Criteria:

Av. Java QB 36
simplified API for retrieving entities by composing Criterion objects.

Flow of working

22. Explain steps to configure hibernate and create a sample program

https://www.javatpoint.com/steps-to-create-first-hibernate-application

💡 check this out on youtube

23. What is ORM and how is it used in hibernate?

💡 Object Relational Mapping (ORM) is a functionality which is used to


develop and maintain a relationship between an object and relational
database by mapping an object state to database column.

Av. Java QB 37
ORM is the solution for handling:

Mismatch & Description

Granularity Sometimes you will have an object model, which has more classes than
the number of corresponding tables in the database.
Inheritance RDBMSs do not define anything similar to Inheritance, which is a natural
paradigm in object-oriented programming languages.
Identity An RDBMS defines exactly one notion of 'sameness': the primary key. Java,
however, defines both object identity (a==b) and object equality (a.equals(b)).

Associations Object-oriented languages represent associations using object


references whereas an RDBMS represents an association as a foreign key column.

Navigation The ways you access objects in Java and in RDBMS are fundamentally
different.

Entities of ORM:

Sr.No. Solutions

An API to perform basic CRUD operations on objects of persistent


1
classes.

A language or API to specify queries that refer to classes and properties


2
of classes.
3 A configurable facility for specifying mapping metadata.

A technique to interact with transactional objects to perform dirty


4
checking, lazy association fetching, and other optimization functions.

Advantages of ORM

Sr.No. Advantages

1 Let’s business code access objects rather than DB tables.

2 Hides details of SQL queries from OO logic.

3 Based on JDBC 'under the hood.'

4 No need to deal with the database implementation.

5 Entities based on business concepts rather than database structure.

6 Transaction management and automatic key generation.

7 Fast development of application.

24. Explain HQL and how it works with database.

Av. Java QB 38
💡 Hibernate Query Language (HQL) is an object-oriented query language,
similar to SQL, but instead of operating on tables and columns, HQL
works with persistent objects and their properties. HQL queries are
translated by Hibernate into conventional SQL queries, which in turns
perform action on database.

Clauses in HQL

FROM Clause

AS clause

SELECT clause

WHERE

ORDER BY

GROUP BY

UPDATE

DELETE

INSERT

How HQL Works?

HQL is an XML file format to link java from the front end to the database in
the back end.

This is written in java language to reduce the impedance mismatch.

case sensitive except for the name of classes and entities.

Advantages of HQL

No obligation to learn the SQL

object-oriented and its performance is good when we link our front-end


application to the backend.

has caching memory ⇒ speedy


supports OOPs concepts.

25. Short note on:

Av. Java QB 39
💡 check this out on youtube

struts with hibernate

https://www.codejava.net/frameworks/struts/struts-2-spring-4-hibernate-4-
integration-tutorial-part-1-xml-configuration#:~:text=Struts is a web
application,and it can replace Struts.

struts with spring

https://struts.apache.org/getting-started/spring

struts with JDBC

https://www.tutorialandexample.com/struts-2-database-connection-example

26. Brief note on: Spring core module and sprint J2EE module

spring core module

core component

provides IoC container

implementations of container:

bean factory

acts as a container for beans

allows you to decouple the configuration and specification of


dependencies from program logic.

Av. Java QB 40
central IoC container that is responsible for instantiating application
objects

configures and assembles the dependencies between these


objects

application context

spring J2EE module

Java EE vs. Spring

Spring is the application development framework for Java EE

open-source Java platform

support robust J2EE applications

light weight

enables developers to develop enterprise-class applications using Plain


Old Java Object, POJO.

Benefits

use of plain old Java objects

modularity

well-developed web framework

organize middle-tier objects

code tends to be very easy to make test cases for various testings

Disadvantages

complex to build

challenging for beginners

XML knowledge is important

unclear guidelines

a lot of time and effort in initial configurations

27. Short note on:

read only modules from the following link.

https://www.geeksforgeeks.org/introduction-to-spring-framework/

spring core module

Av. Java QB 41
spring J2EE module

spring ORM

spring JDBC

https://www.geeksforgeeks.org/spring-jdbc-template/

spring AOP

spring web MVC module

28. Difference between Ant and Maven.

Ant Maven

Maven has a convention to place source


Ant doesn't have formal conventions, so
code, compiled code etc. So we don't need to
we need to provide information of the
provide information about the project structure
project structure in build.xml file.
in pom.xml file.
Ant is procedural, you need to provide
information about what to do and when to Maven is declarative, everything you define in
do through code. You need to provide the pom.xml file.
order.

There is no life cycle in Ant. There is life cycle in Maven.

It is a tool box. It is a framework.

It is mainly a build tool. It is mainly a project management tool.

The ant scripts are not reusable. The maven plugins are reusable.

It is less preferred than Maven. It is more preferred than Ant.

29. Explain maven repositories in detail.

💡 check this out on youtube

https://www.javatpoint.com/maven-repository

30. What is maven with example?

https://www.simplilearn.com/tutorials/maven-tutorial/what-is-maven

31. Explain maven pom.xml with example.

https://www.w3schools.blog/maven-pom-xml-file

Av. Java QB 42
32. What are WS components in detail.

https://www.javatpoint.com/web-service-components

33. Explain web services types in detail.

https://www.edureka.co/blog/java-web-services-tutorial/

34. What is JUnit testing with its types.

💡 I think the question is asking about annotations of JUnit testing.

https://www.simplilearn.com/tutorials/java-tutorial/what-is-junit

35. What is JAXB and its features?

Features of JAXB

1) Annotation support: JAXB 2.0 provides support to annotation so less


coding is required to develop JAXB application. The javax.xml.bind.annotation
package provides classes and interfaces for JAXB 2.0.

2) Support for all W3C XML Schema features: it supports all the W3C
schema unlike JAXB 1.0.

3) Additional Validation Capabilities: it provides additional validation support


by JAXP 1.3 validation API.

4) Small Runtime Library: it required small runtime library that JAXB 1.0.
5) Reduction of generated schema-derived classes: it reduces a lot of
generated schema-derived classes.

Av. Java QB 43
💡 Definition of JAXB

The Java™ Architecture for XML Binding (JAXB) provides an API and
tools that automate the mapping between XML documents and Java
objects.
The JAXB framework enables developers to perform the following
operations:

Unmarshal XML content into a Java representation

Access and update the Java representation

Marshal the Java representation of the XML content into XML content

36. Write a short note on:

JAXB

https://www.geeksforgeeks.org/java-architecture-for-xml-binding-jaxb-set-1/

object to XML

Steps:

1. Create POJO or bind the schema and generate the classes.

2. Create the JAXBContext object.

3. Create the Marshaller objects.

4. Create the content tree by using set methods.

5. Call the marshal method.

6. https://www.javatpoint.com/jaxb-tutorial

XML to object

steps

1. Create POJO or bind the schema and generate the classes.

2. Create the JAXBContext object.

3. Create the Unmarshaller objects.

4. Call the unmarshal method.

5. Use getter methods of POJO to access the data.

https://www.javatpoint.com/jaxb-tutorial

Av. Java QB 44
Maven repositories

💡 check this out on youtube - https://youtu.be/p0LPfK_oNCM

https://www.javatpoint.com/maven-repository

WS component

https://www.w3schools.blog/maven-pom-xml-file

JUNIT testing

https://www.simplilearn.com/tutorials/java-tutorial/what-is-junit

Av. Java QB 45

You might also like