Java Programming
Java OOP, collections, multithreading
958 Questions 10 Topics Take Test
Advertisement
Showing 11–20 of 958 questions
What happens when @Lazy annotation is applied to a singleton bean in Spring?
A The bean is created only when first accessed
B The bean is created at application startup
C The bean is never created
D The bean is created in a separate thread
Correct Answer:  A. The bean is created only when first accessed
EXPLANATION

@Lazy defers bean instantiation until it's first requested, overriding the default eager initialization behavior of singleton beans.

Take Test
In Spring Framework, which interface represents a factory pattern implementation for creating objects?
A ObjectFactory
B FactoryBean
C BeanFactory
D All of the above
Correct Answer:  D. All of the above
EXPLANATION

BeanFactory is the basic container, ObjectFactory is for lazy bean retrieval, and FactoryBean allows custom bean creation logic. All represent factory patterns in Spring.

Take Test
What is the role of Spring's PropertyPlaceholderConfigurer in application configuration?
A It encrypts sensitive properties
B It replaces ${} placeholders with values from properties files
C It validates XML configuration files
D It manages database transactions
Correct Answer:  B. It replaces ${} placeholders with values from properties files
EXPLANATION

PropertyPlaceholderConfigurer (or @PropertySource in modern Spring) enables externalization of configuration by replacing ${property.name} placeholders with actual values from properties files.

Take Test
Consider a scenario where a Spring application needs to initialize a database connection pool at startup. Which method should be used?
A Use @PostConstruct annotation on a method
B Use InitializingBean interface
C Use initMethod parameter in @Bean
D All of the above are valid approaches
Correct Answer:  D. All of the above are valid approaches
EXPLANATION

Spring provides multiple mechanisms for initialization: @PostConstruct, InitializingBean interface, and initMethod in @Bean definition. All are equally valid.

Take Test
What is the difference between @Bean and @Component annotations in Spring?
A @Bean is class-level while @Component is method-level
B @Bean is method-level while @Component is class-level
C They are functionally identical with no difference
D @Bean cannot be used in @Configuration classes
Correct Answer:  B. @Bean is method-level while @Component is class-level
EXPLANATION

@Component is applied to classes making them beans automatically. @Bean is applied to methods in @Configuration classes, giving explicit control over bean creation.

Take Test
Advertisement
In Spring Framework, what does the @Autowired annotation do when autowiring candidates are ambiguous?
A It automatically selects the first bean found
B It throws NoUniqueBeanDefinitionException
C It uses the @Primary annotation to resolve conflicts
D Both B and C are correct
Correct Answer:  D. Both B and C are correct
EXPLANATION

When multiple beans match the injection point, Spring throws an exception unless @Primary is used to indicate the preferred bean or @Qualifier specifies which bean to inject.

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
What is the difference between constructor injection and setter injection in Spring?
A Constructor injection provides immutability and mandatory dependencies; setter injection allows optional dependencies
B Constructor injection is deprecated in Spring 5.0+
C Setter injection is more secure and recommended for sensitive data
D There is no practical difference; both have identical performance
Correct Answer:  A. Constructor injection provides immutability and mandatory dependencies; setter injection allows optional dependencies
EXPLANATION

Constructor injection enforces required dependencies and creates immutable objects; setter injection allows optional dependencies and partial initialization.

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