Advanced Java Technologies – Exam
Answer Sheet (Predicted Paper)
Based on Mumbai University B.Sc. IT – Semester 5 (R-2023) Pattern
Each question carries 5 marks. Write any three per section as per exam instructions.
Q1. Basics of Java EE and Servlets
a. Explain the architecture of Java EE platform.
The Java EE (Enterprise Edition) architecture provides a layered structure for developing
and deploying enterprise applications. It includes Client, Web, Business, and EIS (Enterprise
Information System) layers.
Layers:
1. Client Layer – End user interface.
2. Web Layer – Servlets, JSPs.
3. Business Layer – Enterprise Beans and business logic.
4. EIS Layer – Databases via JDBC or JPA.
Advantages: Scalability, modularity, and portability.
b. Compare Servlets and CGI.
Servlets are Java programs that run inside a server and handle web requests, while CGI
scripts are external programs executed per request.
Comparison:
- Servlets are multi-threaded, CGI is process-based.
- Servlets are faster and portable.
- Servlets run in JVM, CGI depends on OS.
- Servlets are reusable and maintainable.
c. Explain the life cycle of a Servlet with a neat diagram.
Phases of Servlet life cycle:
1. Loading and Instantiation
2. init()
3. service()
4. destroy()
Example:
public class MyServlet extends HttpServlet {
public void init(){}
public void service(){}
public void destroy(){}
}
Diagram: Client → Container → init() → service() → destroy().
d. Write a short note on JDBC Driver types.
There are four JDBC driver types:
1. Type I – JDBC-ODBC Bridge.
2. Type II – Native API.
3. Type III – Network Protocol.
4. Type IV – Thin Driver.
Type IV is pure Java and best for enterprise use.
e. Explain multi-tier architecture in enterprise applications.
Multi-tier architecture divides application logic into layers:
1. Client Tier
2. Web Tier
3. Business Tier
4. Data Tier
Benefits: Improved scalability, reusability, and easier maintenance.
Q2. Servlets, Cookies, and Sessions
a. Explain the role of RequestDispatcher in Servlets.
RequestDispatcher is used to forward requests or include content from another resource.
Methods:
- forward(request, response)
- include(request, response)
Example: RequestDispatcher rd = request.getRequestDispatcher('home.jsp');
rd.forward(request, response);
b. Define cookies and explain how to create and retrieve them.
Cookies are small data stored on the client-side to maintain user sessions.
Creating: Cookie c = new Cookie('user', 'Manali'); response.addCookie(c);
Retrieving: Cookie[] ck = request.getCookies();
c. What is Session Tracking? Explain any two methods.
Session tracking maintains user identity across requests.
Methods:
1. Cookies
2. URL Rewriting
3. Hidden Fields
4. HttpSession API
Example: HttpSession session = request.getSession();
d. Write a program to upload a file using Servlet.
Use Apache Commons FileUpload library:
@WebServlet('/upload')
public class UploadServlet extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse res) {
Part file = req.getPart('file'); file.write('D:/uploads/' + file.getSubmittedFileName());
}}
e. Explain the working of Non-blocking I/O in Java.
Non-blocking I/O allows multiple channels to be handled simultaneously using selectors.
Key Classes: Selector, Channel, Buffer.
Example: Selector monitors multiple channels and improves performance of servers
handling many clients.
Q3. JSP Concepts and JSTL
a. Describe the life cycle of a JSP page.
Steps:
1. Translation of JSP into Servlet.
2. Compilation into class file.
3. Initialization (jspInit()).
4. Request processing (_jspService()).
5. Destruction (jspDestroy()).
b. Explain JSP directives with examples.
Directives provide global information to the JSP engine.
Types:
1. page – <%@ page language='java' contentType='text/html' %>
2. include – <%@ include file='header.jsp' %>
3. taglib – <%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c' %>
c. Write a JSP program to calculate compound interest.
Formula: A = P*(1 + r/100)^n
<%
double p=Double.parseDouble(request.getParameter('p'));
double r=Double.parseDouble(request.getParameter('r'));
double n=Double.parseDouble(request.getParameter('n'));
double a=p*Math.pow((1+r/100),n);
out.println('Amount='+a);
%>
d. What are implicit objects in JSP? Explain any three.
Implicit objects are built-in objects available in JSP:
request, response, session, application, out, config, page, pageContext.
Example: session.getAttribute('user');
e. What is JSTL? How does it remove the need for scriptlets?
JSTL (JavaServer Pages Standard Tag Library) provides ready-made tags for common tasks
like iteration, conditionals, and formatting.
Example: <c:forEach>, <c:if>. It replaces scriptlets with XML-style tags improving
readability.
Q4. Enterprise Java Beans (EJB) and JNDI
a. What is EJB? Explain its architecture.
EJB (Enterprise Java Bean) is a server-side component for building distributed,
transactional applications.
Architecture: EJB Container, EJB Server, and EJB Components (Session, Entity, Message-
driven Beans).
b. Explain different types of Session Beans.
Types:
1. Stateless – No client-specific state.
2. Stateful – Maintains client state.
3. Singleton – One instance shared among clients.
c. Illustrate the life cycle of a Message Driven Bean.
Phases:
1. Instantiation
2. Message-driven context set
3. onMessage() invocation
4. Destruction
Diagram: JMS Queue → MDB → Business Logic
d. What is an Interceptor? Explain @AroundInvoke.
Interceptors provide cross-cutting services like logging.
@AroundInvoke marks a method to intercept business logic calls.
Example:
@AroundInvoke public Object log(InvocationContext ctx) { System.out.println('Before');
return ctx.proceed(); }
e. Explain JNDI and its lookup process.
JNDI (Java Naming and Directory Interface) is used to access directory and naming services.
Example:
Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup('jdbc/MyDB');
Q5. Persistence, JPA, and Hibernate
a. Explain Object-Relational Mapping (ORM) and its advantages.
ORM maps Java objects to database tables.
Advantages: Reduces boilerplate SQL, improves maintainability, and supports transaction
management.
b. Describe the architecture of Hibernate with a neat diagram.
Hibernate architecture includes Configuration, SessionFactory, Session, Transaction, and
Query objects.
Diagram:
Application → SessionFactory → Session → Database
c. Explain the structure and purpose of hibernate.cfg.xml.
hibernate.cfg.xml configures database connection and mapping resources.
Example:
<hibernate-configuration><session-factory><property
name='hibernate.dialect'>org.hibernate.dialect.MySQLDialect</property></session-
factory></hibernate-configuration>
d. What is persistence.xml? Explain its key components.
It defines configuration for JPA persistence units.
Main elements:
- <persistence-unit>
- provider
- class
- properties (database URL, driver, username, password).
e. Explain how JPA implements persistence in Java.
JPA provides a standard for ORM using annotations like @Entity, @Id, @GeneratedValue.
It manages entity lifecycle and provides EntityManager for CRUD operations.