Learn J2EE MCQs

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

Which of the following represents a JAX-RS resource?

1) A class annotated with @Path

2) A method annotated with @GET

3) A method annotated with @POST

4) All of the above

Answer : All of the above

Which of the following is used to access a database in J2EE?

1) JDBC

2) JSP

3) JavaFX

4) JavaScript

Answer : JDBC

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

1) To specify that a class is an entity

2) To indicate a transaction

3) To define a filter

4) To create a servlet

Answer : To specify that a class is an entity

Which of the following is a valid way to create a new EJB?

1) new MyBean()

2) @EJB MyBean myBean

3) create MyBean()

4) new MyBean()@EJB

Answer : @EJB MyBean myBean

What is the default scope of a Spring bean?

1) Singleton

2) Prototype

3) Request

4) Session

Answer : Singleton

Which of the following interfaces is used to handle HTTP requests in servlets?

1) HttpServletRequest

2) HttpRequest

3) RequestHandler

4) ServletRequest

Answer : HttpServletRequest

Which annotation is used to specify a transaction attribute in EJB?

1) @TransactionAttribute

2) @Transactional

3) @Transaction

4) @EJB

Answer : @TransactionAttribute

What is the purpose of `web.xml` in a J2EE application?

1) Deployment descriptor

2) Bean definition

3) Database connection

4) Session management

Answer : Deployment descriptor

Which of the following is a valid way to send a message to a JMS queue?

1) jmsTemplate.send()

2) jmsTemplate.publish()

3) jmsTemplate.request()

4) jmsTemplate.reply()

Answer : jmsTemplate.send()

What is the correct way to configure a data source in JNDI?

1) context.lookup("datasource")

2) context.bind("datasource", datasource)

3) context.create("datasource")

4) context.init("datasource")

Answer : context.lookup("datasource")