MCQ

J2EE MCQ with Answers

This collection of Java Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “J2EE”.
 

1. What exception is thrown when Servlet initialization fails?

A ServletException

B RemoteException

C IOException

D SocketException

A
If the Servlet initialization fails, we will get the following error message:

 javax.servlet.ServletException: Could not initialize class org.apache.jasper.runtime.ClassImpl
 

2. The classes in the _________ directory must be available for the “Classloader” of the application?

A /root/lib/classes/

B /root/classes/

C /WEB-INF/lib/classes/

D /WEB-INF/classes/

D
The “/WEB-INF/classes/” directory for the servlet and utility classes. The classes in this directory must be available for the “Classloader” of the application.

 

 

3. Which of the following statements are correct about the status of the Http response?

A HTTP status codes in the 500 to 599 range indicate that the error is related to the client

B HTTP status codes in the 400 to 499 range indicate that the error is related to the server

C HTTP status codes in the 300 to 399 range are informational messages.

D HTTP status codes in the 200 to 299 range means that the client’s request was successful.

D

 

 

4. Why are beans used in the J2EE architecture instead of writing all the code in the JSPs?

A Allows the separation of roles between web developers and application developers

B Allows integration with Content Management tools

A
Bean is frequently used in HTML forms to capture the value of selected query parameters (such as username) and pass it on to other processing pages or server-side programs, depending on its scope.

 

 

5. What is correct about JSP Scriptlets ?

A A loop can start in one Scriptlet and end in another

B Instructions in a Scriptlet must follow Java syntax

C Semicolon is required at the end of each statement in a Scriptlet

D All the answers are true

D

 

 

6. Which method is called first each time a servlet is called?

A Start()

B Run()

C init()

D Servive()

C

 

 

7. What is the scope of response object?

A session

B page

C request

D response

B
Objects with this scope are only accessible on the page where they were created. The object is only valid while the response is being processed.

 

 

8. In JSP, how can you tell which HTTP method (GET or POST) is being used by the client request?

A Using request.getMethod()

B Using request.setMethod()

C Impossible to know

A
The request object provides methods for getting information about the HTTP header, including form data, cookies, HTTP methods, and more.
 

9. What is the difference between using “forward” and “sendRedirect()”?

A forward runs on the client side while sendRedirect() runs on the server side.

B forward runs on the server side while sendRedirect() runs on the client side.

C Both methods work in the same way.

B

 

 

10. How can a servlet call a JSP error page?

A This feature is not supported

B When the servlet throws the exception, it will be automatically caught by the calling JSP page

C The servlet should forward the request to the URL of the specific error page. The exception is thrown as an attribute named “javax.servlet.jsp.jspException”

D The servlet should redirect the response to the error page

C

 

 

11. Any client request to access resources in the WEB-INF/ directory must be returned with a ________?

A BAD_REQUEST

B SC_NOT_FOUND

C SC_INTERNAL_SERVER_ERROR

D ESC_BAD_REQUEST

B
The classLoader of the web application must first load classes from the WEB-INF/classes directory, then library JAR files from the WEB-INF/lib directory. Moreover, any client request to access resources in the WEB-INF/ directory must be returned with an SC_NOT_FOUND (404) response.

 

 

12. Which of the following is not an implicit object in JSP?

A system

B page

C response

D request

A
There are 9 implicit objects in jsp which are: request, response, config, session, application, out, page, exception and pageContext.

 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *