Home Subjects Java Programming Spring Framework Basics

Java Programming
Spring Framework Basics

Java OOP, collections, multithreading

15 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 11–15 of 15
Topics in Java Programming
Which XML element is used to define a bean in Spring XML configuration?
A
B
C
D
Correct Answer:  B.
EXPLANATION

The <bean> element is the standard XML element used in applicationContext.xml to define Spring beans.

Test
What does @Autowired annotation do in Spring?
A Automatically injects dependencies by type
B Creates a new bean instance
C Marks a class as deprecated
D Enables auto-scanning of packages
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.

Test
Which of the following is NOT a valid Spring bean scope in Spring 5.x+?
A singleton
B prototype
C request
D eternal
Correct Answer:  D. eternal
EXPLANATION

Valid scopes are singleton, prototype, request, session, application, and websocket. 'eternal' is not a valid scope.

Test
What is the primary purpose of Dependency Injection (DI) in Spring Framework?
A To increase code complexity
B To reduce coupling between classes and improve testability
C To replace all design patterns
D To automatically generate SQL queries
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.

Test
Which annotation is used to mark a class as a Spring Bean in the latest Spring Framework?
A @Bean
B @Component
C @Service
D @Controller
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.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips