Learn J2EE MCQs

Prepare J2EE MCQs (Multiple choice Questions) for exam and job interviews.

Which of the following components is responsible for rendering dynamic web pages?

1) Servlet

2) JSP

3) EJB

4) JNDI

Answer : JSP

What is the purpose of the `<filter>` tag in the `web.xml` file?

1) Defines a filter

2) Defines a servlet

3) Defines a listener

4) Defines a session

Answer : Defines a filter

What is the purpose of `Session Beans` in J2EE?

1) Manage client sessions

2) Handle HTTP requests

3) Render web pages

4) Manage messages

Answer : Manage client sessions

Which method is used to retrieve a session in a servlet?

1) request.getSession()

2) request.retrieveSession()

3) response.getSession()

4) session.getSession()

Answer : request.getSession()

What is the use of `JTA` in J2EE?

1) Transaction management

2) Session management

3) Message queuing

4) Database management

Answer : Transaction management

What is the purpose of `Message-Driven Beans` in J2EE?

1) Process asynchronous messages

2) Manage client requests

3) Handle HTTP sessions

4) Process web pages

Answer : Process asynchronous messages

Which method is used to invalidate a session in a servlet?

1) session.invalidate()

2) session.remove()

3) request.invalidate()

4) session.destroy()

Answer : session.invalidate()

Which of the following annotations is used to create RESTful web services in J2EE?

1) @Path

2) @WebServlet

3) @EJB

4) @WebListener

Answer : @Path

What does the `@RolesAllowed` annotation do in J2EE?

1) Specifies roles allowed to access the method

2) Defines roles for EJBs

3) Defines roles for Servlets

4) Specifies allowed roles for JSP

Answer : Specifies roles allowed to access the method

What is the main purpose of the `web.xml` file?

1) Defines web application configuration

2) Manages transactions

3) Configures EJB lifecycle

4) Handles HTTP requests

Answer : Defines web application configuration