Java Programming
Java OOP, collections, multithreading
958 Questions 10 Topics Take Test
Advertisement
Showing 21–30 of 958 questions
When would you use request-scoped beans in a Spring web application?
A To store request-specific data that should not be shared across different HTTP requests
B To reduce memory consumption by reusing beans across requests
C To improve application performance significantly
D To simplify configuration by avoiding singleton bean management
Correct Answer:  A. To store request-specific data that should not be shared across different HTTP requests
EXPLANATION

Request-scoped beans are instantiated per HTTP request and destroyed after request completion, ideal for storing user-specific or request-specific information.

Take Test
What does the @EnableCaching annotation enable in a Spring application?
A Declarative caching support using @Cacheable, @CacheEvict, and similar annotations
B Automatic HTTP response caching by the server
C Database query result caching with Redis integration
D Browser-level caching of static resources
Correct Answer:  A. Declarative caching support using @Cacheable, @CacheEvict, and similar annotations
EXPLANATION

@EnableCaching activates Spring's caching infrastructure, allowing method-level caching through annotations like @Cacheable to store and retrieve results.

Take Test
In Spring framework, what is the purpose of FactoryBean interface?
A To create complex bean instances with custom initialization logic
B To define factory methods for creating beans
C To implement the Factory design pattern
D To manage bean lifecycle events
Correct Answer:  A. To create complex bean instances with custom initialization logic
EXPLANATION

FactoryBean allows creating beans with sophisticated initialization logic through getObject() method, useful for complex object creation.

Take Test
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
Consider a Spring application where method execution time tracking is required across multiple methods. Which approach is most appropriate?
A Using Spring AOP with custom aspect to track execution time
B Adding timing logic manually in each method
C Using @Timed annotation from Spring Actuator
D Implementing a custom servlet filter
Correct Answer:  A. Using Spring AOP with custom aspect to track execution time
EXPLANATION

Spring AOP with a custom aspect provides centralized, reusable cross-cutting concern implementation without code duplication in individual methods.

Take Test
Advertisement
What is the significance of the @ConfigurationProperties annotation in Spring Boot?
A It binds external configuration properties to Java objects with type-safe access
B It encrypts sensitive configuration values automatically
C It validates configuration file syntax during application startup
D It generates configuration files from Java classes
Correct Answer:  A. It binds external configuration properties to Java objects with type-safe access
EXPLANATION

@ConfigurationProperties enables binding of external properties (from application.properties/yml) to POJO classes, providing type safety and validation.

Take Test
An enterprise application requires different bean implementations based on runtime conditions. Which Spring feature is most suitable?
A @Conditional annotation with custom Condition implementations
B @Profile annotation for environment-specific beans
C Factory pattern with factory beans
D All of the above can be used depending on the scenario
Correct Answer:  D. All of the above can be used depending on the scenario
EXPLANATION

@Conditional provides fine-grained control, @Profile handles environment-specific beans, and factory beans offer explicit creation logic. Choice depends on use case requirements.

Take Test
What does the @Transactional annotation do in Spring?
A Manages database transactions, handling commit and rollback automatically
B Encrypts data being transmitted across the network
C Logs all database operations performed by the method
D Validates input parameters before method execution
Correct Answer:  A. Manages database transactions, handling commit and rollback automatically
EXPLANATION

@Transactional delegates transaction management to Spring, automatically committing on success and rolling back on exceptions, following ACID principles.

Take Test
In Spring AOP, what does the term 'Join Point' refer to?
A A specific point during program execution where an aspect can be applied
B The code written in an aspect to handle cross-cutting concerns
C A method that connects multiple beans together
D The configuration file that defines AOP rules
Correct Answer:  A. A specific point during program execution where an aspect can be applied
EXPLANATION

A Join Point is a candidate point in program execution (method call, exception throw) where advice can be applied. Pointcuts select specific Join Points.

Take Test
What is the function of the BeanFactory interface in Spring?
A To create and manage bean instances with lazy initialization capability
B To provide enterprise features like AOP and transaction management
C To store all bean metadata in an internal registry
D To enforce naming conventions for beans
Correct Answer:  A. To create and manage bean instances with lazy initialization capability
EXPLANATION

BeanFactory is the core interface for accessing beans, providing lazy initialization. ApplicationContext extends BeanFactory with additional enterprise features.

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