Learn J2EE MCQs

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

Which of the following is NOT a valid attribute scope in JSP?

1) Page

2) Request

3) Session

4) Application

Answer : Page

Which of the following methods is used to forward a request from one servlet to another?

1) request.getRequestDispatcher().forward()

2) response.sendRedirect()

3) request.forward()

4) session.forward()

Answer : request.getRequestDispatcher().forward()

Which of the following is NOT a part of the servlet configuration in the `web.xml` file?

1) Session timeout

2) Filter mapping

3) Error page mapping

4) Servlet mapping

Answer : Session timeout

Which of the following J2EE APIs is responsible for distributed transaction management?

1) JTA

2) JMS

3) JNDI

4) JDBC

Answer : JTA

Which of the following is the correct syntax to invalidate an `HttpSession` object?

1) session.invalidate()

2) session.delete()

3) session.terminate()

4) session.clear()

Answer : session.invalidate()

Which of the following is NOT true about `JSP`?

1) JSP is compiled into a servlet

2) JSP is interpreted directly by the browser

3) JSP pages can contain Java code

4) JSP supports custom tag libraries

Answer : JSP is interpreted directly by the browser

Which annotation is used to map an HTTP POST request to a method in a RESTful web service?

1) @POST

2) @PUT

3) @GET

4) @DELETE

Answer : @POST

Which J2EE component is used for managing naming and directory services?

1) JNDI

2) JMS

3) EJB

4) JSP

Answer : JNDI

What is the correct return type of the `doGet()` method in a servlet?

1) void

2) int

3) String

4) boolean

Answer : void

What does the `@PostConstruct` annotation indicate?

1) A method that is called after the bean is constructed

2) A method that is called before the bean is destroyed

3) A method that handles POST requests

4) A method that handles GET requests

Answer : A method that is called after the bean is constructed