Learn J2EE MCQs

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

What is the main purpose of `@Transactional` annotation in J2EE?

1) To define transaction boundaries

2) To handle HTTP requests

3) To manage session data

4) To configure servlets

Answer : To define transaction boundaries

Which of the following is NOT a type of message-driven bean?

1) Queue-based MDB

2) Topic-based MDB

3) HTTP-based MDB

4) JMS-based MDB

Answer : HTTP-based MDB

What is the correct way to retrieve a request parameter in a servlet?

1) request.getParameter("paramName")

2) request.getAttribute("paramName")

3) response.getParameter("paramName")

4) context.getParameter("paramName")

Answer : request.getParameter("paramName")

Which of the following is true about a message-driven bean?

1) It listens for messages from a queue

2) It is a type of session bean

3) It manages transactions

4) It handles HTTP requests

Answer : It listens for messages from a queue

What is the correct way to create a new `HttpSession`?

1) request.getSession(true)

2) request.getSession(false)

3) response.getSession()

4) context.createSession()

Answer : request.getSession(true)

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

1) To inject dependencies

2) To manage transactions

3) To define servlets

4) To handle requests

Answer : To inject dependencies

Which of the following is used to configure a JNDI resource?

1) web.xml

2) ejb-jar.xml

3) context.xml

4) all of the above

Answer : all of the above

What is the main benefit of using EJBs?

1) Simplifies enterprise application development

2) Improves performance

3) Enhances security

4) Reduces coding efforts

Answer : Simplifies enterprise application development

Which of the following is a valid way to define a JPA entity?

1) @Entity

2) @Table

3) @Column

4) @Bean

Answer : @Entity

What is the correct way to invalidate a session in a servlet?

1) session.invalidate()

2) session.remove()

3) session.close()

4) session.delete()

Answer : session.invalidate()