Learn J2EE MCQs

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

What is the primary purpose of `@Component` in Spring?

1) Indicates a Spring-managed component

2) Defines a RESTful endpoint

3) Handles HTTP requests

4) Defines a configuration class

Answer : Indicates a Spring-managed component

What is the role of the `DispatcherServlet` in Spring MVC?

1) Handles HTTP requests and dispatches to controllers

2) Defines a REST service

3) Manages transactions

4) Handles asynchronous processing

Answer : Handles HTTP requests and dispatches to controllers

What does `JNDI` stand for?

1) Java Naming and Directory Interface

2) Java Naming Directory Interface

3) Java Network and Directory Interface

4) Java Network and Directory Integration

Answer : Java Naming and Directory Interface

Which of the following is used to create a transaction in JTA?

1) UserTransaction.begin()

2) Transaction.create()

3) Transaction.start()

4) Transaction.begin()

Answer : UserTransaction.begin()

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

1) To provide specific bean to autowire

2) To mark a bean as a service

3) To manage transactions

4) To define a repository

Answer : To provide specific bean to autowire

Which of the following is NOT a valid lifecycle method for EJBs?

1) init()

2) destroy()

3) create()

4) remove()

Answer : init()

What is the correct way to retrieve a session attribute in a servlet?

1) session.getAttribute("key")

2) session.get("key")

3) session.find("key")

4) session.retrieve("key")

Answer : session.getAttribute("key")

Which of the following is used for message-driven beans?

1) JMS

2) EJB

3) JPA

4) JNDI

Answer : JMS

What is the primary function of `@ResponseBody` in Spring?

1) Indicates that the return value should be written directly to the HTTP response body

2) Handles transactions

3) Injects dependencies

4) Defines a REST endpoint

Answer : Indicates that the return value should be written directly to the HTTP response body

Which of the following annotations is used for dependency injection in Spring?

1) @Inject

2) @Autowired

3) @Service

4) @Repository

Answer : @Autowired