Learn J2EE MCQs

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

Which of the following can be used to share data between servlets?

1) ServletContext

2) HttpSession

3) ServletConfig

4) Both a and b

Answer : Both a and b

What does `@PathParam` annotation in JAX-RS do?

1) Injects URI template parameters

2) Injects request headers

3) Injects request parameters

4) Injects session attributes

Answer : Injects URI template parameters

Which of the following is a valid way to define a filter in `web.xml`?

1) <filter>

2) <listener>

3) <servlet>

4) <context-param>

Answer : <filter>

What is the main advantage of using `JPA`?

1) Simplifies database operations

2) Improves security

3) Increases performance

4) Reduces server load

Answer : Simplifies database operations

Which of the following is used for logging in J2EE applications?

1) Log4j

2) JDBC

3) JNDI

4) JMS

Answer : Log4j

What is the purpose of `@WebServlet` annotation?

1) To declare a servlet

2) To define a filter

3) To configure a context

4) To handle sessions

Answer : To declare a servlet

Which of the following methods can be overridden to handle HTTP POST requests in a servlet?

1) doPost()

2) doGet()

3) service()

4) init()

Answer : doPost()

What does `@SessionScoped` annotation indicate?

1) The bean is tied to a session

2) The bean is tied to a request

3) The bean is tied to an application

4) The bean is tied to a transaction

Answer : The bean is tied to a session

What is the default behavior of `HttpSession`?

1) Session data is shared across all users

2) Session data is unique to each user

3) Session data is stored in the database

4) Session data is stateless

Answer : Session data is unique to each user

Which of the following is a valid RESTful API method for creating a new resource?

1) POST

2) GET

3) PUT

4) DELETE

Answer : POST