Java Programming
Java OOP, collections, multithreading
476 Questions 10 Topics Take Test
Advertisement
Showing 11–20 of 476 questions
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
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
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
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
Advertisement
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
In Spring Data JPA, what does the @Repository annotation signify?
A It marks a class as a data access object and enables exception translation
B It automatically generates SQL queries from method names
C It configures the database connection pool
D It enables caching for database queries
Correct Answer:  A. It marks a class as a data access object and enables exception translation
EXPLANATION

@Repository marks a class as a data access component and enables Spring to translate persistence-specific exceptions into Spring's DataAccessException hierarchy.

Take Test
What is the role of PropertySource annotation in Spring Framework?
A To define external property files and load their values into the environment
B To create new properties dynamically at runtime
C To encrypt sensitive properties automatically
D To validate property values against defined constraints
Correct Answer:  A. To define external property files and load their values into the environment
EXPLANATION

@PropertySource allows loading properties from external files (like .properties or .yml) into the Spring Environment for use throughout the application.

Take Test
Consider a scenario where you have two bean implementations of the same interface. How would you specify which one to inject using Spring annotations?
A Use @Primary on one bean and @Autowired on the injection point
B Use @Qualifier annotation with the bean name at the injection point
C Use @Autowired with @Primary or @Qualifier; both approaches work
D Use @Bean with explicit configuration in @Configuration class
Correct Answer:  C. Use @Autowired with @Primary or @Qualifier; both approaches work
EXPLANATION

Both @Primary (default choice) and @Qualifier (explicit selection by name) can resolve bean ambiguity. @Qualifier is more explicit and takes precedence over @Primary.

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