Learn J2EE MCQs

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

Which of the following is true about a Session Bean?

1) It can maintain state

2) It is stateless

3) It is a type of Message-Driven Bean

4) It cannot be pooled

Answer : It can maintain state

What is the purpose of the `@Path` annotation in JAX-RS?

1) Defines a resource path

2) Defines a service endpoint

3) Defines a database entity

4) Defines a filter

Answer : Defines a resource path

Which of the following is NOT a valid scope for a Spring bean?

1) Singleton

2) Prototype

3) Thread

4) Session

Answer : Thread

What is the correct method to retrieve an attribute from `HttpSession`?

1) session.getAttribute("name")

2) session.findAttribute("name")

3) session.retrieve("name")

4) session.get("name")

Answer : session.getAttribute("name")

What is the primary purpose of the `@Stateless` annotation?

1) To define a stateless session bean

2) To define a stateful session bean

3) To define a message-driven bean

4) To define an entity bean

Answer : To define a stateless session bean

Which of the following is a J2EE specification for web services?

1) JAX-RS

2) JAX-WS

3) JDBC

4) EJB

Answer : JAX-WS

What is the primary use of the `@PostConstruct` annotation?

1) To perform initialization after dependency injection

2) To handle HTTP POST requests

3) To manage transactions

4) To destroy beans

Answer : To perform initialization after dependency injection

Which of the following is NOT an HTTP method?

1) GET

2) POST

3) PUT

4) FETCH

Answer : FETCH

What is the main purpose of the `@PreDestroy` annotation?

1) To perform cleanup before bean destruction

2) To initialize beans

3) To handle HTTP GET requests

4) To manage sessions

Answer : To perform cleanup before bean destruction

Which of the following is used to define a REST endpoint in JAX-RS?

1) @Path

2) @Rest

3) @Service

4) @Endpoint

Answer : @Path