Learn J2EE MCQs
Prepare J2EE MCQs (Multiple choice Questions) for exam and job interviews.
What is the correct method to close a `Connection` in JDBC?
1) connection.close()
2) connection.stop()
3) connection.end()
4) connection.release()
Answer : connection.close()
Which of the following represents a RESTful endpoint in Spring?
1) @GetMapping("/endpoint")
2) @RequestMapping("/endpoint")
3) @RestController("/endpoint")
4) @Controller("/endpoint")
Answer : @GetMapping("/endpoint")
What is the main purpose of `@PathVariable` in Spring MVC?
1) To extract variables from URI templates
2) To map requests to methods
3) To handle HTTP GET requests
4) To define a service endpoint
Answer : To extract variables from URI templates
Which method is used to send an HTTP redirect in a servlet?
1) response.sendRedirect("url")
2) response.redirect("url")
3) response.forward("url")
4) response.go("url")
Answer : response.sendRedirect("url")
What is the role of the `@Bean` annotation in Spring?
1) Indicates a method produces a bean
2) Defines a controller
3) Handles transactions
4) Creates an EJB
Answer : Indicates a method produces a bean
What is the primary purpose of the `@Transactional` annotation in Spring?
1) Defines transaction boundaries
2) Indicates a service layer
3) Handles HTTP requests
4) Manages session
Answer : Defines transaction boundaries
Which of the following is a Java specification for RESTful web services?
1) JAX-RS
2) JAX-WS
3) EJB
4) JDBC
Answer : JAX-RS
What is the correct way to configure a bean in Spring?
1) @Configuration
2) @ComponentScan
3) @Bean
4) @Autowired
Answer : @Configuration
Which interface is used to create a connection in JMS?
1) ConnectionFactory
2) Session
3) Message
4) Destination
Answer : ConnectionFactory
What is the purpose of `@EnableTransactionManagement` in Spring?
1) Enables declarative transaction management
2) Defines a REST endpoint
3) Configures a service layer
4) Handles HTTP requests
Answer : Enables declarative transaction management