Govt. Exams
Entrance Exams
Advertisement
Topics in Java Programming
Which XML element is used to define a bean in Spring XML configuration?
Correct Answer:
B.
EXPLANATION
The <bean> element is the standard XML element used in applicationContext.xml to define Spring beans.
What does @Autowired annotation do in Spring?
Correct Answer:
A. Automatically injects dependencies by type
EXPLANATION
@Autowired performs type-based dependency injection. Spring looks for a bean of the required type and injects it automatically.
Which of the following is NOT a valid Spring bean scope in Spring 5.x+?
Correct Answer:
D. eternal
EXPLANATION
Valid scopes are singleton, prototype, request, session, application, and websocket. 'eternal' is not a valid scope.
What is the primary purpose of Dependency Injection (DI) in Spring Framework?
Correct Answer:
B. To reduce coupling between classes and improve testability
EXPLANATION
DI reduces coupling by injecting dependencies rather than creating them internally, making code more testable and maintainable.
Which annotation is used to mark a class as a Spring Bean in the latest Spring Framework?
Correct Answer:
B. @Component
EXPLANATION
@Component is a generic stereotype annotation for any Spring-managed component. @Bean is used on methods, while @Service and @Controller are specialized versions of @Component.