Learn J2EE MCQs

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

Which of the following is true about the `doPost()` method in servlets?

1) It handles HTTP POST requests

2) It handles HTTP GET requests

3) It handles HTTP PUT requests

4) It handles HTTP DELETE requests

Answer : It handles HTTP POST requests

Which component of J2EE is used to create a connection pool?

1) JNDI

2) JDBC

3) JMS

4) JCA

Answer : JDBC

What is the default HTTP status code returned by a servlet when a request is successfully processed?

1) 200 OK

2) 404 Not Found

3) 500 Internal Server Error

4) 302 Found

Answer : 200 OK

Which J2EE feature allows asynchronous communication between different components?

1) JMS

2) JDBC

3) JSP

4) EJB

Answer : JMS

What is the purpose of the `@WebServlet` annotation?

1) Defines a servlet class

2) Defines a filter class

3) Defines a listener class

4) Defines a session bean

Answer : Defines a servlet class

Which of the following is a persistent entity in J2EE?

1) JPA Entity

2) Servlet

3) JSP

4) EJB

Answer : JPA Entity

What does the `@RequestScoped` annotation do?

1) Limits the bean scope to a single HTTP request

2) Limits the bean scope to the session

3) Limits the bean scope to the application

4) Limits the bean scope to a servlet

Answer : Limits the bean scope to a single HTTP request

Which method is used to set a request attribute in a servlet?

1) request.setAttribute()

2) response.setAttribute()

3) session.setAttribute()

4) context.setAttribute()

Answer : request.setAttribute()

Which is the correct sequence of the servlet life cycle?

1) init() -> service() -> destroy()

2) service() -> init() -> destroy()

3) destroy() -> init() -> service()

4) init() -> destroy() -> service()

Answer : init() -> service() -> destroy()

Which of the following components in J2EE is responsible for session tracking?

1) HttpSession

2) JSP

3) Servlet

4) JPA

Answer : HttpSession