Learn J2EE MCQs
Prepare J2EE MCQs (Multiple choice Questions) for exam and job interviews.
Which of the following is a valid method in `HttpServletResponse`?
1) sendError()
2) getRequestDispatcher()
3) invalidate()
4) getSession()
Answer : sendError()
Which tag is used to define a servlet in `web.xml`?
1) <web>
2) <servlet>
3) <listener>
4) <filter>
Answer : <servlet>
What is the purpose of `ContextListener` in J2EE?
1) Manages the session
2) Manages servlet lifecycle
3) Handles web application startup and shutdown
4) Manages transactions
Answer : Handles web application startup and shutdown
Which method is used to write a response in a servlet?
1) getWriter()
2) getResponse()
3) setContent()
4) sendResponse()
Answer : getWriter()
What does the `@EJB` annotation do in J2EE?
1) Registers a servlet
2) Declares a session bean
3) Registers a filter
4) Defines a JSP
Answer : Declares a session bean
Which J2EE technology is used for transaction management?
1) JNDI
2) JTA
3) JSP
4) Servlet
Answer : JTA
Which method is used to handle all HTTP requests in a servlet?
1) doGet()
2) service()
3) doPost()
4) init()
Answer : service()
What does the `doGet()` method handle?
1) Processes POST requests
2) Processes GET requests
3) Processes both GET and POST requests
4) Initializes the servlet
Answer : Processes GET requests
Which of the following is a lifecycle method of a servlet?
1) getSession()
2) service()
3) sendRedirect()
4) sendError()
Answer : service()
What is the purpose of the `RequestDispatcher` in J2EE?
1) Manages database connections
2) Forwards a request to another resource
3) Manages user sessions
4) Handles messaging
Answer : Forwards a request to another resource