Learn J2EE MCQs

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

What does the `@Transactional` annotation indicate?

1) The method should be executed within a transaction

2) The class is a Spring component

3) The method is a REST endpoint

4) The class is a configuration class

Answer : The method should be executed within a transaction

What does the `@Autowired` annotation do?

1) Automatically wires a bean

2) Defines a REST endpoint

3) Creates a new bean

4) Indicates a service layer

Answer : Automatically wires a bean

Which method in a servlet is used to handle POST requests?

1) doPost()

2) doGet()

3) handlePost()

4) service()

Answer : doPost()

What is the purpose of `@Entity` in JPA?

1) Marks a class as a JPA entity

2) Defines a service

3) Handles transactions

4) Maps a request parameter

Answer : Marks a class as a JPA entity

Which of the following is used for configuration in Spring?

1) applicationContext.xml

2) web.xml

3) persistence.xml

4) context.xml

Answer : applicationContext.xml

What is the main purpose of `JNDI`?

1) Java Naming and Directory Interface

2) Java Naming and Data Integration

3) Java Network Directory Interface

4) Java Naming Data Interface

Answer : Java Naming and Directory Interface

Which of the following is a Java-based configuration in Spring?

1) @Configuration

2) @Bean

3) @ComponentScan

4) @EnableAutoConfiguration

Answer : @Configuration

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

1) Defines the URI for the resource

2) Maps requests to methods

3) Handles transactions

4) Injects dependencies

Answer : Defines the URI for the resource

Which of the following is a valid Java EE API for web services?

1) JAX-WS

2) JDBC

3) EJB

4) JPA

Answer : JAX-WS

What is the purpose of `@RequestMapping` in Spring MVC?

1) Maps web requests to specific handler methods

2) Defines a REST endpoint

3) Handles transactions

4) Injects dependencies

Answer : Maps web requests to specific handler methods