Learn J2EE MCQs

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

What does the `doGet()` method in a servlet do?

1) Handles HTTP GET requests

2) Handles HTTP POST requests

3) Handles HTTP PUT requests

4) Handles HTTP DELETE requests

Answer : Handles HTTP GET requests

Which component in J2EE is used to create web-based applications?

1) Servlet

2) EJB

3) JDBC

4) JMS

Answer : Servlet

What is the role of `ServletConfig`?

1) Provides configuration for a specific servlet

2) Provides configuration for the entire web application

3) Stores session information

4) Manages database connections

Answer : Provides configuration for a specific servlet

Which method is called when a servlet is first loaded into memory?

1) init()

2) service()

3) doGet()

4) doPost()

Answer : init()

Which of the following technologies is used to build a user interface in J2EE?

1) JSF

2) JSP

3) JDBC

4) Servlet

Answer : JSF

Which method of `HttpSession` is used to retrieve an attribute?

1) getAttribute()

2) setAttribute()

3) removeAttribute()

4) invalidate()

Answer : getAttribute()

Which object provides information about the server environment?

1) ServletContext

2) HttpServletRequest

3) HttpSession

4) ServletConfig

Answer : ServletContext

Which of the following is a correct JNDI lookup string for an EJB?

1) java:comp/env/ejb/SessionBean

2) java:comp/env/jdbc/DataSource

3) java:comp/env/mail/Session

4) java:comp/env/jms/Queue

Answer : java:comp/env/ejb/SessionBean

Which of the following is true about `ServletContext`?

1) It is shared by all servlets in an application

2) It is unique to each servlet

3) It is the same as `HttpSession`

4) It stores session attributes

Answer : It is shared by all servlets in an application

What does the `@GET` annotation in JAX-RS represent?

1) It maps HTTP GET requests to a method

2) It maps HTTP POST requests to a method

3) It maps HTTP PUT requests to a method

4) It maps HTTP DELETE requests to a method

Answer : It maps HTTP GET requests to a method