Learn J2EE MCQs
Prepare J2EE MCQs (Multiple choice Questions) for exam and job interviews.
Which of the following is a lifecycle method of a servlet?
1) service()
2) sendRedirect()
3) forward()
4) getParameter()
Answer : service()
What does `@WebServlet` annotation define?
1) A servlet class
2) A filter class
3) A listener class
4) A transaction class
Answer : A servlet class
What does the `RequestDispatcher` interface provide?
1) Handling messaging
2) Managing client sessions
3) Forwarding and including responses
4) Managing transactions
Answer : Forwarding and including responses
Which J2EE component handles client-side presentation?
1) JSP
2) Servlet
3) EJB
4) JMS
Answer : JSP
Which method is used to send a client redirect from a servlet?
1) sendRedirect()
2) forward()
3) getRequestDispatcher()
4) sendError()
Answer : sendRedirect()
What does `@Stateful` annotation define?
1) A stateful session bean
2) A servlet
3) A stateless session bean
4) A filter
Answer : A stateful session bean
Which method is used to obtain a `PrintWriter` object in a servlet?
1) getResponse()
2) getWriter()
3) getOutput()
4) sendResponse()
Answer : getWriter()
Which J2EE component is used to create dynamic web content?
1) EJB
2) Servlet
3) JSP
4) JMS
Answer : JSP
What does the `@WebListener` annotation define?
1) A Servlet
2) A Filter
3) A Web Listener
4) A JSP
Answer : A Web Listener
Which method is used to send a redirect response in a servlet?
1) response.sendRedirect()
2) request.forward()
3) response.redirect()
4) request.redirect()
Answer : response.sendRedirect()