Learn J2EE MCQs
Prepare J2EE MCQs (Multiple choice Questions) for exam and job interviews.
What is a primary feature of EJB?
1) Distributed computing
2) Client-server architecture
3) Message passing
4) Database connectivity
Answer : Distributed computing
What is the default scope of a Spring bean?
1) Singleton
2) Prototype
3) Session
4) Request
Answer : Singleton
Which of the following is used for asynchronous processing in Spring?
1) @Async
2) @Scheduled
3) @EnableAsync
4) @EnableScheduling
Answer : @Async
What does the `@ComponentScan` annotation do?
1) Scans for components in the specified package
2) Defines a REST service
3) Handles transactions
4) Injects dependencies
Answer : Scans for components in the specified package
What is the purpose of `PersistenceContext` in JPA?
1) Manages entity lifecycle
2) Defines a REST service
3) Handles transactions
4) Creates an EJB
Answer : Manages entity lifecycle
Which method is used to send an HTTP response in a servlet?
1) response.getWriter()
2) response.sendRedirect()
3) response.send()
4) response.write()
Answer : response.getWriter()
What is the role of a `Filter` in Java web applications?
1) To intercept requests and responses
2) To manage sessions
3) To handle HTTP methods
4) To define a service
Answer : To intercept requests and responses
Which annotation is used to specify a RESTful endpoint method?
1) @GetMapping
2) @PostMapping
3) @RequestMapping
4) @PutMapping
Answer : @GetMapping
What does the `@Value` annotation do?
1) Injects property values
2) Defines a bean
3) Handles HTTP requests
4) Manages transactions
Answer : Injects property values
Which method is called to initialize a servlet?
1) init()
2) start()
3) load()
4) begin()
Answer : init()