Learn J2EE MCQs
Prepare J2EE MCQs (Multiple choice Questions) for exam and job interviews.
What is the main purpose of `ServletContext`?
1) To provide information about the web application
2) To manage session data
3) To handle HTTP requests
4) To process database transactions
Answer : To provide information about the web application
Which annotation is used to inject a dependency in a servlet?
1) @Inject
2) @EJB
3) @WebServlet
4) @Resource
Answer : @Inject
What is the main purpose of `JPA` in J2EE?
1) Object-relational mapping
2) Handling HTTP requests
3) Managing transactions
4) Building user interfaces
Answer : Object-relational mapping
Which is the correct way to define a servlet in `web.xml`?
1) <servlet>
2) <context-param>
3) <filter>
4) <listener>
Answer : <servlet>
Which of the following is NOT an HTTP method?
1) CONNECT
2) TRACE
3) HEAD
4) SEND
Answer : SEND
Which annotation is used to define a RESTful resource class?
1) @Path
2) @WebServlet
3) @EJB
4) @RequestScoped
Answer : @Path
What does the `@DELETE` annotation in JAX-RS signify?
1) It maps HTTP DELETE requests to a method
2) It maps HTTP POST requests to a method
3) It maps HTTP GET requests to a method
4) It maps HTTP PUT requests to a method
Answer : It maps HTTP DELETE requests to a method
Which of the following is used for dependency injection in J2EE?
1) CDI
2) JSP
3) Servlet
4) JTA
Answer : CDI
What is the primary role of `ServletConfig`?
1) To provide configuration information to a servlet
2) To provide configuration information to a filter
3) To store session data
4) To manage the application context
Answer : To provide configuration information to a servlet
Which of the following methods is used to retrieve a session in a servlet?
1) request.getSession()
2) request.getAttribute()
3) response.getSession()
4) context.getSession()
Answer : request.getSession()