Java 2022
Java 2022
V (Elective-I)
Enterprise Java
Mumbai University Examination Paper Solution: Nov-22
Q1(a) What is an Enterprise Application? What is the enterprise edition of java? [5]
Ans.
o Transaction processing
,interoperability.
The J2EE platform consists of a set of services, APIs, and protocols that provide the
MUQuestionPapers.com
o Providing a complete set of services to those modular components.
programming.
Q1(b) Define java EE containers with the various java container types [5]
Ans.
Containers are the interface between a component and the low-level, platform-specific
EJB container:
Web container:
Manages the execution of web pages, servlets, and some EJB components for
Java EE applications. Web components and their container run on the Java EE
server.
MUQuestionPapers.com
Manages the execution of application client components. Application clients and
Applet container:
Manages the execution of applets. Consists of a web browser and a Java Plug-in
Security
Transaction
Persistence
Concurrency
Availability
Lifecycle Management
Ans.
MUQuestionPapers.com
The life cycle of a servlet application consists of four phases:
1. Initialization:
When a servlet container initializes a servlet, it creates an instance of the servlet and calls
its int() method. This phase is executed only once during the lifetime of a servlet.
2. Request Handling:
Once the servlet is initialized, it is ready to handle client requests. When a client sends a
request to the servlet, the servlet container creates a new thread to handle the request and
calls the service() method of the servlet. The service() method processes the request and
generates a response.
3. Response Generation:
After the service() method has finished processing the request, it generates a response and
4. Destroy:
When the servlet container decides to remove a servlet, it calls the destroy() method of
the servlet. This phase is executed only once during the lifetime of a servlet. During the
destroy() method, the servlet can release any resources it has allocated and perform any
cleanup operations.
Ans.
The javax.servlet package is a part of the Java Servlet API, which is a set of classes and
interfaces that define how a Java application can respond to requests from web clients.
The javax.servlet package contains classes and interfaces that are used to implement
servlets, which are Java classes that can dynamically generate web content.
MUQuestionPapers.com
The most important classes in the javax.servlet package are the ServletRequest and
ServletResponse classes, which define the objects that a servlet uses to communicate with
clients.
The ServletRequest class represents the request that a client sends to a servlet, while the
ServletResponse class represents the response that a servlet sends back to the client.
These classes provide methods for accessing information about the request, such as the
HTTP headers and parameters, and for generating the response, such as writing data to
Another important class in the javax.servlet package is the ServletContext class, which
The ServletContext provides a way for servlets to share information with each other,
The ServletContext also provides methods for accessing resources, such as files or other
The javax.servlet package also includes classes for handling HTTP sessions, cookies, and
filters.
The HttpSession class provides a way for a servlet to store data that is associated with a
specific client session, while the Cookie class provides a way for a servlet to store data in
a client's browser.
The Filter class provides a way for a servlet to intercept requests and responses before
Q1(e) What is JDBC statement object Explain its three types [5]
Ans.
MUQuestionPapers.com
JDBC (Java Database Connectivity) is a Java API that provides a standard interface for
Statement interface, which is used to execute SQL statements against a database. The
Statement object is used to send SQL statements to the database and receive the results.
1. Statement:
This is the simplest type of Statement object, which is used to execute a single
SQL statement that doesn't have any parameters. The Statement object is created
2. PreparedStatement:
that may have one or more parameters. The PreparedStatement object is created
3. CallableStatement:
This type of Statement object is used to execute stored procedures that are defined
in the database. A stored procedure is a set of SQL statements that are stored in
Q1(f) List and explain each of the four JDBC driver types [5]
Ans.
MUQuestionPapers.com
In a Type 1 driver, a JDBC bridge is used to access ODBC drivers installed on each client
machine. Using ODBC, requires configuring on your system a Data Source Name (DSN)
JDBC-Native API
In a Type 2 driver, JDBC API calls are converted into native C/C++ API calls, which are
unique to the database. These drivers are typically provided by the database vendors and
used in the same manner as the JDBC-ODBC Bridge. The vendor specific driver must be
installed
In a Type 3 driver, a three-tier approach is used to access databases. The JDBC clients
use standard network sockets to communicate with a middleware application server. The
socket information is then translated by the middleware application server into the call
In a Type 4 driver, a pure Java-based driver communicates directly with the vendor's
database through socket connection. This is the highest performance driver available for
Ans.
The Request Dispatcher interface dispatching the request to another resource it may be
html, servlet .
MUQuestionPapers.com
It is one of the way of servlet collaboration.
This method forwards the request and response objects to another resource for
processing. The resource can be a servlet, JSP page, or any other resource that can
The forward() method is typically used when the requested resource cannot
handle the request and needs to be forwarded to another resource for processing.
This method includes the response generated by another resource in the response
The resource can be a servlet, JSP page, or any other resource that can generate a
response. The include() method is typically used when the requested resource
needs to include the output generated by another resource in its own response.
Q2(b)Where are cookies used ? Describe any four important methods of cookie class [5]
Ans.
Cookies are used to store small amounts of data on the client side, typically in the form of
key-value pairs.
Cookies are sent from the server to the client in the HTTP response headers, and then
sent back to the server in subsequent requests in the HTTP request headers.
Cookies are commonly used for session management, user preferences, and tracking user
activity.
The Cookie class in Java provides several methods for working with cookies:
MUQuestionPapers.com
1. Cookie(String name, String value):
This constructor creates a new cookie with the specified name and value.
2. setMaxAge(int expiry):
This method sets the maximum age of the cookie in seconds. A value of 0 or less
indicates that the cookie should be deleted immediately. A negative value indicates that
3. setPath(String path):
This method sets the path for which the cookie is valid.
4. setSecure(boolean secure):
This method sets the secure flag for the cookie. If set to true, the cookie will only be sent
Ans.
A session is a way to maintain state information between HTTP requests for a single user
or client.
Sessions are typically used to store user-specific data, such as shopping cart items or
1. Session ID generation:
A unique session ID should be generated for each new session. This ID should be
MUQuestionPapers.com
2. Session ID storage:
The session ID should be stored in a cookie or in the URL. If stored in a cookie, the
cookie should be marked as secure and HttpOnly to prevent cross-site scripting (XSS)
attacks.
3. Session timeout:
Sessions should have a timeout period to prevent them from being active indefinitely.
The timeout period should be long enough to allow users to complete their tasks, but
Session data should be stored on the server side, not on the client side. This prevents
users from tampering with the session data and allows the server to control the lifetime of
the session.
5. Session termination:
Sessions should be terminated when the user logs out or when the session timeout period
is reached. This ensures that session data is not left active for longer than necessary.
Ans.
Non-blocking I/O is a technique that allows a program to perform I/O operations without
Non-blocking I/O is useful in situations where the program needs to perform I/O
In non-blocking I/O, the program initiates an I/O operation and then continues executing
MUQuestionPapers.com
When the I/O operation is complete, the program is notified and can then process the data
Non-blocking I/O works by using a special system call that allows the program to check
If an I/O operation can be performed without blocking, the program can initiate the
If an I/O operation would block, the program can choose to wait for the operation to
simultaneously. By using non-blocking I/O, a program can process data from multiple
This can improve the performance of network applications and allow them to handle
Ans.
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
MUQuestionPapers.com
private static final String FILE_DIRECTORY = "/path/to/your/files/"; // Replace with the actual
@Override
return;
if (!file.exists()) {
return;
response.setContentType("application/octet-stream");
int bytesRead;
MUQuestionPapers.com
response.getOutputStream().write(buffer, 0, bytesRead);
Q2(f) Which things needs to be carefully checked and understood while writing file
Ans.
When writing file uploading code in a servlet, there are several things that need to be
carefully checked and understood to ensure that the code is secure and reliable:
1. Request method:
The file upload request must use the POST method, as other methods like GET or HEAD
2. Encoding type:
The encoding type of the request must be set to "multipart/form-data", which allows binary
3. File size:
The maximum file size that can be uploaded should be limited to prevent denial of service
attacks and to ensure that the server has enough resources to handle the request.
4. File type:
The file type should be validated to ensure that only allowed file types are uploaded. This
can be done by checking the file extension or by checking the MIME type of the file.
5. File name:
MUQuestionPapers.com
The file name should be sanitized to prevent directory traversal attacks. The file name
6. File storage:
The uploaded file should be stored in a secure location on the server, and the file should be
7. Error handling:
The servlet should handle errors gracefully and provide informative error messages to the
user. This can include checking for file upload errors, file size errors, and file type errors.
8. Security:
The servlet should be protected against cross-site scripting (XSS) and cross-site request
Q3(a) What is the use of java server pages? Give difference between JSP and servlets [5]
Ans.
1) Extension to Servlet:
JSP technology is the extension to Servlet technology. We can use all the features
of the Servlet in JSP. In addition to, we can use implicit objects, predefined tags,
expression language and Custom tags in JSP that makes JSP development easy.
2) Easy to maintain:
The business logic with presentation logic is separated in JSP so we can easily
managed web application.In Servlet technology, we mix our business logic with
MUQuestionPapers.com
3) Fast Development:
No need to recompile and redeploy .If JSP page is modified, we don't need to
recompile and redeploy the project. The Servlet code needs to be updated and
In JSP, we can use many tags such as action tags, JSTL, custom tags, etc. that
reduces the code. Moreover, we can use EL, implicit objects, etc.
JSP SERVLET
JSP compiled into a java servlet before Servlet execute inside a web server
execution.
Ans.
MUQuestionPapers.com
The life cycle of a JSP page is as follows:
1. Translation:
When a JSP page is accessed for the first time, it is translated into a servlet by the JSP
container. The JSP container creates a servlet class that extends the HttpServlet class and
2. Compilation:
The servlet class is then compiled into bytecode by the Java compiler.
3. Initialization:
The JSP container creates an instance of the servlet class and calls its init() method. This
method is used to perform any initialization tasks that need to be done before the servlet
4. Request handling:
When a client sends a request to the JSP page, the JSP container calls the service()
method of the servlet class. This method handles the request and generates the response.
5. Destruction:
MUQuestionPapers.com
When the JSP container shuts down or the JSP page is removed, the container calls the
destroy() method of the servlet class. This method is used to perform any cleanup tasks
6. Recompile:
If the JSP page is modified, the JSP container recompiles it into a servlet and replaces the
old servlet with the new one. This allows the JSP page to be updated without restarting
the server.
Ans.
Directives in JSP are special instructions that are used to provide information to the JSP
container about how to translate a JSP file into a servlet. There are three types of
directives in JSP:
1. Page directive:
The page directive is used to provide information about the JSP page to the JSP
container. It is placed at the top of the JSP file and begins with the <%@ symbol. The
page directive can be used to specify attributes such as the content type, language, error
2. Include directive:
The include directive is used to include the contents of another file in the JSP page. It is
placed in the body of the JSP file and begins with the <%@ symbol. The include
directive can be used to include static files such as HTML or text files.
3. Taglib directive:
MUQuestionPapers.com
The taglib directive is used to define a custom tag library that can be used in the JSP
page. It is placed at the top of the JSP file and begins with the <%@ symbol. The taglib
directive specifies the URI of the tag library and the location of the tag library descriptor
file.
Overall, directives in JSP are used to provide important information to the JSP container
and to include external files or custom tag libraries in the JSP page.
Q3(d) Give an explanation of the jsp:useBean action tag's attributes and usage [5]
Ans.
The jsp:useBean action tag is used to create an instance of a JavaBean and store it as a
1. id:
This attribute is used to specify the name of the variable that will store the instance of the
JavaBean.
2. class:
This attribute is used to specify the fully qualified class name of the JavaBean.
3. scope:
This attribute is used to specify the scope of the variable that will store the instance of
the JavaBean. The possible values for this attribute are page, request, session, and
application.
4. type:
MUQuestionPapers.com
This attribute is used to specify the data type of the variable that will store the instance of
the JavaBean. This is an optional attribute and is only used when the type of the variable
The jsp:useBean tag is typically used in conjunction with the jsp:setProperty and
For example, the following code creates an instance of the Customer JavaBean and sets
its properties:
The customer variable is then stored in the session context and can be accessed by other
Ans.
The <jsp:plugin> action tag is used to embed applets or other types of plugins in a JSP
page.
The <jsp:plugin> tag has several attributes that can be used to specify the parameters and
properties of the plugin, including the codebase, code, type, width, height, and archive
attributes.
For example, the following code embeds an applet in a JSP page using the <jsp:plugin>
tag:
height="300">
MUQuestionPapers.com
<jsp:params>
</jsp:params>
</jsp:plugin>
This code embeds an applet with the class name "com.example.Applet" and a width and
The <jsp:params> tag is used to specify the parameters that will be passed to the applet.
The <jsp:plugin> tag is a powerful tool for embedding plugins in a JSP page, but it
It is important to ensure that plugins are up-to-date and that they are only used when
necessary.
Ans.
JSTL stands for JavaServer Pages Standard Tag Library, which is a collection of JSP tags
JSTL provides a set of tags that can be used to perform common tasks such as looping
JSTL is designed to simplify JSP development by providing a standard set of tags that
MUQuestionPapers.com
XPath is used to navigate through elements and attributes in an XML document and is
used by many XML-related technologies, including XSLT, XQuery, and XML Schema.
XPath expressions can be used to select nodes based on their name, value, or position in
the document.
XPath expressions are evaluated against an XML document and return a set of nodes that
XPath expressions can use a variety of operators and functions to select nodes.
Ans.
EJB stands for Enterprise JavaBeans, which is a server-side component architecture used
EJB provides a set of APIs for building business logic components that can be deployed
EJB include:
1. Scalability:
EJB provides a scalable architecture that can handle large volumes of transactions and
users.
2. Transaction management:
EJB provides built-in support for transaction management, which simplifies the
MUQuestionPapers.com
3. Security:
EJB provides a robust security model that can be used to secure applications against
unauthorized access.
4. Persistence:
EJB provides support for persistence, which allows data to be stored and retrieved from a
database.
5. Reusability:
6. Portability:
EJB components can be deployed on any application server that supports the EJB
Ans.
Session Beans are a type of Enterprise Java Beans (EJBs) that are used to manage the
There are three types of Session Beans: Stateful Session Beans, Stateless Session Beans,
Stateful Session Beans are used to maintain the conversational state of a client.
When a client interacts with a Stateful Session Bean, the bean maintains the state of the
MUQuestionPapers.com
This allows the client to continue the conversation with the server across multiple
requests.
Stateless Session Beans are used to perform a specific task or operation. When a client
interacts with a Stateless Session Bean, the bean performs the requested operation and
Singleton Session Beans are used to maintain a single instance of a bean across multiple
clients. When a client interacts with a Singleton Session Bean, the bean performs the
Ans
Remote and Local Interfaces are used in Enterprise Java Beans (EJBs) to define the
1. Remote Interface:
A Remote Interface is used to define the methods that can be accessed by clients
that are located on a different machine or JVM (Java Virtual Machine) from the
EJB.
The methods defined in the Remote Interface are accessed through RMI (Remote
Method Invocation).
Remote Interfaces are useful in scenarios where the client and server are located
2. Local Interface:
MUQuestionPapers.com
A Local Interface is used to define the methods that can be accessed by clients
The methods defined in the Local Interface are accessed through direct method
calls.
Local Interfaces are useful in scenarios where the client and server are located on
Ans
Message Driven Beans (MDBs) are a type of Enterprise Java Beans (EJBs) that are used
1. Asynchronous Processing:
the container invokes the onMessage() method of the MDB to process the message. This
allows the application to continue processing other requests while the message is being
processed.
2. Message Driven:
MDBs are designed to process messages from a messaging system. A messaging system
exchange messages. MDBs can be used with messaging systems such as Java Message
3. No Client Dependency:
MUQuestionPapers.com
MDBs do not have a client dependency. This means that MDBs can be invoked by any
client that sends messages to the messaging system. This allows the application to be
4. Stateless:
MDBs are stateless. This means that the container can reuse the same instance of the
MDB to process multiple messages. This reduces the overhead of creating and destroying
5. Configurable:
MDBs are configurable. The container allows you to configure the number of instances
of the MDB that can be created to process messages. This allows you to optimize the
Ans
centralized directory of services that clients can use to locate the services they need.
The naming service maps the names of services to their network addresses.
Clients can use the name of a service to look up its network address in the naming
service's directory.
Once the client has the network address, it can use it to connect to the service and use it.
The naming service acts as an intermediary between the client and the service, allowing
the client to access the service without having to know its physical location.
MUQuestionPapers.com
They make it easier for clients to locate and use services, even when the services are
They also make it easier to add or remove services from the system, because clients can
use the naming service to locate the services they need, rather than having to know their
physical location.
Ans
In Java EE, a DataSource Resource Definition is a way to define a connection pool for a
database.
By defining a DataSource Resource Definition, you can configure a connection pool that
In this file, you define the DataSource Resource Definition using XML syntax.
The definition includes the name of the DataSource, the type of database driver to use,
Once you have defined the DataSource Resource Definition, you can use it in your Java
You can do this by looking up the DataSource using the Java Naming and Directory
Interface (JNDI).
Once you have the DataSource, you can use it to get a connection to the database.
MUQuestionPapers.com
Using a DataSource Resource Definition has several benefits. First, it allows you to
configure a connection pool for your database, which can improve performance by
Second, it allows you to manage the connections to the database from a central location,
Finally, it provides a standard way to access the database from your Java EE application,
which can make your application more portable and easier to maintain.
Ans.
In SQL, a JOIN operation is used to combine rows from two or more tables based on a
The JOIN condition is used to specify the relationship between the tables. The ON
keyword is used to specify the condition that must be met for the JOIN to occur.
SELECT column_name(s)
FROM table1
JOIN table2
ON table1.column_name = table2.column_name;
MUQuestionPapers.com
Here, the JOIN keyword is used to combine rows from table1 and table2 based on a
related column, and the ON keyword is used to specify the condition that must be met for
In Java Persistence API (JPA), an Entity Listener is a callback method that is invoked
when a specific event occurs on an entity, such as when the entity is loaded, persisted, or
updated.
The CID (Callback Interface Definition) is a feature of JPA that allows you to define
your own callback methods in an interface, which can be implemented by your entity
classes.
To use Entity Listeners with CID, you need to define an interface that contains the
The interface should extend the javax.persistence.Callback interface, which defines the
You can then annotate your entity classes with the @EntityListeners annotation,
Ans.
Java.
It provides a set of interfaces and annotations that allow Java developers to map Java
MUQuestionPapers.com
JPA is part of the Java EE (Enterprise Edition) platform, which provides a set of APIs
JPA is used in conjunction with other Java EE technologies, such as Servlets, JavaServer
Pages (JSP), Enterprise JavaBeans (EJB), and Java Transaction API (JTA), to build
JPA provides a standard way to interact with relational databases, which makes it easier
JPA also provides a set of features for managing transactions, caching, and concurrency
control, which can help developers to write efficient and robust applications.
Ans.
system (RDBMS).
First, it allows developers to work with objects in their programming language, rather
This makes it easier to write and maintain code, as developers can use the object-oriented
MUQuestionPapers.com
.Third, ORM can help to improve performance by providing caching and lazy loading
mechanisms.
ORM frameworks can cache frequently accessed data in memory, reducing the number of
Additionally, ORM can use lazy loading to only load data from the database when it is
needed, reducing the amount of data that needs to be transferred from the database to the
application.
Q5(d) Write short note on functions in JPQL and downcasting in JPQL [5]
Ans.
Functions in JPQL (Java Persistence Query Language) are used to perform various
JPQL provides a set of built-in functions that can be used to perform common operations
such as string manipulation, mathematical calculations, date and time operations, and
more.
These functions can be used in JPQL queries to transform or manipulate data before it is
Downcasting in JPQL:
subclass.
MUQuestionPapers.com
This is useful when you want to retrieve only the objects of a particular subclass
from the database, but the database stores objects of both the superclass and the
subclass.
You can use the TYPE operator in a JPQL query to retrieve only the objects of a
particular subclass.
Ans.
programming language.
It provides a way to map Java objects to relational database tables, and vice versa.
improve performance.
1. Object-relational mapping:
Hibernate provides a way to map Java objects to relational database tables, and vice
versa. This allows developers to work with objects in their programming language, rather
2. Database independence:
MUQuestionPapers.com
Hibernate provides a database-independent way to work with the database. This means
that you can write your application code once, and it will work with any database that
Hibernate supports.
3. Caching:
Hibernate can cache frequently accessed data in memory, reducing the number of
4. Lazy loading:
Hibernate supports lazy loading, which means that it only loads data from the database
when it is needed. This can help to reduce the amount of data that needs to be transferred
5. Transactions:
way. This helps to ensure that the data in the database remains consistent and accurate.
Ans.
1. SessionFactory:
object that should be created once per application. The SessionFactory is used to create
MUQuestionPapers.com
Hibernate needs to know how to connect to the database. This includes details such as
the JDBC driver class name, the database URL, the username, and the password.
3. Mapping files:
Hibernate uses mapping files to map Java objects to database tables. These mapping files
define how each Java class is mapped to a database table, and how each property of the
Hibernate has many configuration properties that can be used to customize its behavior.
These properties can be used to configure things such as the cache provider, the
HQL is a powerful query language that is used to retrieve data from the database.
Hibernate configuration includes settings for HQL, such as the dialect used to generate
SQL statements.
MUQuestionPapers.com