Java Programming
Java OOP, collections, multithreading
270 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 270 questions
Which of the following best describes the purpose of Spring's Stereotype annotations (@Service, @Repository)?
A They improve code execution performance
B They mark classes for component scanning and provide semantic meaning
C They enforce specific design patterns
D They are purely optional and provide no functional benefit
Correct Answer:  B. They mark classes for component scanning and provide semantic meaning
EXPLANATION

Stereotype annotations (@Service, @Repository, @Controller) enable classpath component scanning and convey the architectural role of the class.

Take Test
What does the @Scope annotation with value 'prototype' mean in Spring Framework?
A A new bean instance is created for each request
B The bean is shared across the entire application
C The bean is created once and reused
D The bean is never instantiated
Correct Answer:  A. A new bean instance is created for each request
EXPLANATION

Prototype scope creates a new bean instance each time it's requested, unlike singleton which creates only one instance for the entire application.

Take Test
Which of the following is NOT a valid Spring Bean scope in Spring Framework 2024?
A Singleton
B Prototype
C Session
D Eternal
Correct Answer:  D. Eternal
EXPLANATION

Spring supports singleton, prototype, request, session, application, and websocket scopes. 'Eternal' is not a valid scope in Spring Framework.

Take Test
What is the primary purpose of the ApplicationContext in Spring Framework?
A To manage HTTP requests and responses
B To create and manage Spring Beans and their lifecycle
C To handle database connections exclusively
D To configure security policies
Correct Answer:  B. To create and manage Spring Beans and their lifecycle
EXPLANATION

ApplicationContext is the core container that instantiates, configures, and manages beans. It also resolves dependencies and manages bean lifecycle.

Take Test
Which annotation is used to mark a class as a Spring Bean in the latest Spring Framework 6.0?
A @Component
B @Bean
C @Service
D All of the above
Correct Answer:  D. All of the above
EXPLANATION

@Component, @Service, @Repository, and @Controller are all stereotype annotations that mark classes as Spring Beans. @Bean is used for method-level bean definition.

Take Test
Advertisement
What is the default behavior of Spring when multiple beans of the same type are available for autowiring?
A Throws NoUniqueBeanDefinitionException
B Autowires the bean marked with @Primary
C Autowires the first bean registered in the container
D Skips autowiring and requires manual configuration
Correct Answer:  A. Throws NoUniqueBeanDefinitionException
EXPLANATION

Spring raises NoUniqueBeanDefinitionException when ambiguity exists. Use @Primary or @Qualifier to resolve the ambiguity.

Take Test
What is the primary advantage of using Spring Dependency Injection over manual object creation?
A Reduces code coupling, improves testability, and simplifies bean management
B Increases application performance by caching objects in memory
C Eliminates the need for writing Java code
D Automatically implements all design patterns used in the application
Correct Answer:  A. Reduces code coupling, improves testability, and simplifies bean management
EXPLANATION

DI reduces tight coupling between classes, making code more maintainable, testable, and flexible for changes or mock implementations during testing.

Take Test
What is the difference between @Component and @Service annotations in Spring?
A @Component is generic, while @Service is semantically used for business logic classes
B @Service provides additional database transaction management capabilities
C @Component requires manual bean registration, while @Service auto-registers
D There is no functional difference; they are completely interchangeable
Correct Answer:  A. @Component is generic, while @Service is semantically used for business logic classes
EXPLANATION

@Component is a generic stereotype, while @Service is a specialized annotation indicating the class contains business logic, improving code readability.

Take Test
Which of the following correctly describes the lifecycle of a singleton-scoped Spring bean?
A Created once per HTTP request and destroyed after the request completes
B Created once when the ApplicationContext is initialized and persists throughout the application lifetime
C Created every time it is referenced and destroyed immediately after use
D Created in a separate thread context and shared across multiple threads
Correct Answer:  B. Created once when the ApplicationContext is initialized and persists throughout the application lifetime
EXPLANATION

Singleton beans are instantiated once per Spring container and reused for the application's lifetime, making them memory-efficient for stateless objects.

Take Test
In Spring Framework, what is the primary purpose of the @Autowired annotation?
A To automatically inject dependent beans into a class
B To define a new bean in the Spring container
C To configure database connections
D To enable component scanning
Correct Answer:  A. To automatically inject dependent beans into a class
EXPLANATION

@Autowired is used for dependency injection, allowing Spring to automatically resolve and inject bean dependencies without explicit configuration.

Take Test
IGET
iget AI
Online · Ask anything about exams
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