Learn J2EE MCQs

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

Which of the following HTTP methods is idempotent?

1) GET

2) POST

3) PUT

4) DELETE

Answer : GET

What does `JDBC` stand for?

1) Java Database Connectivity

2) Java Data Communication

3) Java Directory Communication

4) Java Directory Connectivity

Answer : Java Database Connectivity

Which of the following is used for sending and receiving messages asynchronously in J2EE?

1) JMS

2) JDBC

3) JNDI

4) JSP

Answer : JMS

What does the `@EJB` annotation in a servlet signify?

1) Injects an EJB reference

2) Defines a stateful session bean

3) Defines a stateless session bean

4) Defines a listener

Answer : Injects an EJB reference

Which is used to define the initial value of context parameters in a J2EE application?

1) web.xml

2) META-INF

3) pom.xml

4) application.xml

Answer : web.xml

Which method in a servlet is called only once during its lifecycle?

1) init()

2) service()

3) doGet()

4) doPost()

Answer : init()

What is the purpose of `EJB` in J2EE?

1) Encapsulates business logic

2) Handles HTTP requests

3) Manages database connections

4) Processes web pages

Answer : Encapsulates business logic

What does the `@ApplicationScoped` annotation do?

1) Makes a bean available for the entire application lifecycle

2) Limits a bean to a single HTTP request

3) Limits a bean to a single session

4) Defines a servlet scope

Answer : Makes a bean available for the entire application lifecycle

What is the primary purpose of the `ServletContext` object?

1) Provides context for the servlet within the web application

2) Tracks client session

3) Sends messages between components

4) Handles database connections

Answer : Provides context for the servlet within the web application

What does the `@Path` annotation define in a RESTful web service?

1) The URI path for a resource

2) The class path

3) The JNDI path

4) The file path

Answer : The URI path for a resource