Learn J2EE MCQs
Prepare J2EE MCQs (Multiple choice Questions) for exam and job interviews.
What is the main role of a `Message-Driven Bean`?
1) To process messages asynchronously
2) To handle HTTP requests
3) To manage transactions
4) To define entities
Answer : To process messages asynchronously
Which method is used to start a transaction in JTA?
1) begin()
2) start()
3) init()
4) create()
Answer : begin()
What is the correct way to specify a filter in `web.xml`?
1) <filter>
2) <filter-mapping>
3) <servlet>
4) <listener>
Answer : <filter>
Which of the following annotations is used to define a RESTful web service in JAX-RS?
1) @Path
2) @RestController
3) @Service
4) @WebService
Answer : @Path
What does `@Autowired` annotation do in Spring?
1) Injects dependencies automatically
2) Creates beans
3) Defines a transaction
4) Handles requests
Answer : Injects dependencies automatically
Which of the following is used to configure a connection pool in J2EE?
1) DataSource
2) ConnectionFactory
3) JDBC
4) JNDI
Answer : DataSource
What does the `@PathVariable` annotation do in Spring MVC?
1) Extracts variables from URI
2) Handles HTTP methods
3) Injects request parameters
4) Defines a resource path
Answer : Extracts variables from URI
What is the correct way to send an HTTP response from a servlet?
1) response.getWriter().write("message")
2) response.send("message")
3) response.write("message")
4) response.output("message")
Answer : response.getWriter().write("message")
What is the role of the `HttpServlet` class?
1) To handle HTTP requests
2) To manage sessions
3) To define servlets
4) To implement EJB
Answer : To handle HTTP requests
What is the correct way to configure a JMS connection factory in JNDI?
1) context.bind("connectionFactory", factory)
2) context.create("connectionFactory")
3) context.lookup("connectionFactory")
4) context.init("connectionFactory")
Answer : context.lookup("connectionFactory")