Test your understanding of the Spring Framework fundamentals with this beginner-friendly quiz! Here are 40+ multiple-choice questions that cover the foundational concepts. Dive in and see how much you know!
Note that each question is followed by the correct answer and an explanation to help reinforce your knowledge.
1. What is minimum Java version requires to use Spring Framework 6?
Answer:
Explanation:
Spring Framework 6 requires Java 17 or later.
2. What is the core concept behind the Spring Framework?
Answer:
Explanation:
The core concept behind Spring is the Inversion of Control (IoC) which means that the control of objects is transferred from the developer to the Spring container.
3. What is Dependency Injection (DI) in Spring Framework?
Answer:
Explanation:
Dependency Injection is a technique to implement Inversion of Control. It allows the system to be more decoupled and modular.
4. Which of the following is NOT a module in the Spring Framework?
Answer:
Explanation:
There’s no module named “Spring JPA”. JPA stands for Java Persistence API which is used with Spring Data JPA, but it’s not a core module of Spring.
5. What is the primary function of the Spring IoC container?
Answer:
Explanation:
The primary function of the Spring IoC (Inversion of Control) container is to manage the lifecycle of beans, including their creation, wiring, and destruction.
6. Which annotation is used to mark a class as a Spring bean?
Answer:
Explanation:
The @Component annotation is a generic stereotype to denote a Spring-managed bean. Though @Repository, and @Service are also correct, they are specialized stereotypes with additional semantics.
7. What does the Spring @Autowired annotation do?
Answer:
Explanation:
The @Autowired annotation tells Spring to inject (or wire) a dependency into a bean automatically.
8. Which module in Spring is used for AOP (Aspect-Oriented Programming)?
Answer:
Explanation:
Answer: b) Spring AOP
9. In which layer is Spring MVC used?
Answer:
Explanation:
Spring MVC is used in the presentation layer to handle web requests and construct responses.
10. Which annotation is used to inject a dependency in Spring?
Answer:
Explanation:
All these annotations can be used to inject dependencies in Spring-based applications.
11. Which Spring annotation is used to handle exceptions at the controller level?
Answer:
Explanation:
@ExceptionHandler is used in Spring MVC to handle specific exceptions at the controller level.
12. Which annotation is used to make a Java class serve RESTful requests?
Answer:
Explanation:
@RestController is a specialized version of the controller that includes @Controller and @ResponseBody annotations, making it suited for building RESTful APIs.
13. What does @Qualifier annotation do?
Answer:
Explanation:
When multiple beans of the same type exist, @Qualifier is used to specify which bean should be autowired.
14. Which of these is a pointcut expression type in Spring AOP?
Answer:
Explanation:
In Spring AOP, “execution” is a pointcut designator (PCD) used to match method execution join points.
15. What is the default scope of a Spring bean?
Answer:
Explanation:
By default, beans in Spring are singletons, meaning only one instance of the bean is created for the entire application.
16. What does the @Required annotation do?
Answer:
Explanation:
The @Required annotation indicates that the affected bean property must be populated during bean configuration.
17. What does AOP stand for?
Answer:
Explanation:
AOP stands for Aspect-Oriented Programming. It provides a way to add cross-cutting concerns in a modular way.
18. Which of the following is NOT an advice type in Spring AOP?
Answer:
Explanation:
Spring AOP supports Before, After, and Around advice types, among others. “Across” isn’t one of them.
19. Which annotation denotes a transaction boundary in Spring?
Answer:
Explanation:
The @Transactional annotation in Spring is used to denote a transaction boundary.
20. Which module in Spring provides support for JDBC operations?
Answer:
Explanation:
Spring JDBC module provides a more convenient way to handle database operations compared to traditional JDBC.
21. How can you execute a method after bean initialization in Spring?
Answer:
Explanation:
Implementing the afterPropertiesSet() method from the InitializingBean interface allows executing custom logic after the bean has been initialized.
22. What is Spring Boot mainly used for?
Answer:
Explanation:
Spring Boot provides various tools and defaults to facilitate rapid application development.
23. How can you fetch a bean from the Spring application context?
Answer:
Explanation:
To retrieve a bean from the application context, use the getBean method on an instance of ApplicationContext.
24. What is the purpose of BeanFactory in Spring?
Answer:
Explanation:
BeanFactory is the root interface for accessing the Spring container, providing bean creation and management functionalities.
25. Which of the following is NOT a Spring bean scope?
Answer:
Explanation:
Spring supports various bean scopes like singleton, prototype, request, etc., but “global” is not one of them.
26. Which annotation is used to mark a class as a Spring Repository?
Answer:
Explanation:
@Repository is a stereotype annotation to mark a class as a Data Access Object (DAO).
27. Which module in Spring deals with cloud-based features?
Answer:
Explanation:
Spring Cloud provides a suite of tools for building cloud-native applications.
28. What does @Value annotation in Spring do?
Answer:
Explanation:
@Value is used to inject values from property files or default values into bean properties.
29. Which of the following is not a type of metadata provided by Spring?
Answer:
Explanation:
Spring supports annotation-based, Java-based, and XML-based metadata for bean configuration, but not YAML-based.
30. How can you execute a method before bean destruction in Spring?
Answer:
Explanation:
The @PreDestroy annotation indicates a method to be executed before a bean is removed from the container.
31. What does the JdbcTemplate class in Spring JDBC provide?
Answer:
Explanation:
JdbcTemplate simplifies the use of JDBC and helps to avoid common errors, offering a more streamlined way to handle database operations.
32. Which of the following is a way to introduce a bean’s metadata to the Spring container?
Answer:
Explanation:
Spring offers multiple ways to provide bean metadata including annotations, JavaConfig, and XML configurations.
33. Which annotation is used to mark a class as configuration class in Spring?
Answer:
Explanation:
The @Configuration annotation indicates that the class can be used by the Spring IoC container as a source of bean definitions.
34. Which of these is NOT a type of Dependency Injection in Spring?
Answer:
Explanation:
Spring supports Constructor, Setter, and Field injections. Annotations like @Autowired facilitate these injections but “Annotation Injection” itself isn’t a type.
35. Which Spring module provides features related to sending emails?
Answer:
Explanation:
The Spring Mail module abstracts away the complexities of sending emails, simplifying the task.
36. Which of the following is NOT a core module of the Spring framework?
Answer:
Explanation:
Spring Boot is not a core module of the Spring framework. It’s a project built on top of the Spring framework to simplify microservice development and deployment.
37. Which of the following is true about the @Controller annotation in Spring?
Answer:
Explanation:
The @Controller annotation indicates that a class is a Spring MVC controller that can handle HTTP requests.
38. How can you handle exceptions in Spring MVC?
Answer:
Explanation:
@ExceptionHandler is used for handling exceptions specific to a controller, while @ControllerAdvice can be used to handle exceptions across multiple controllers.
39. What does the @SpringBootApplication annotation do in Spring Boot?
Answer:
Explanation:
@SpringBootApplication is a convenience annotation often used in the main class, combining several other annotations to bootstrap a Spring Boot application.
40. Which annotation is used to define a pointcut expression in Spring AOP?
Answer:
Explanation:
The @Pointcut annotation is used to declare a pointcut expression in Spring AOP, defining where the aspect should be applied.
41. What is the main purpose of the @Aspect annotation in Spring AOP?
Answer:
Explanation:
The @Aspect annotation is used to declare a class as an aspect in Spring AOP.
42. What is a Pointcut in Spring AOP?
Answer:
Explanation:
A pointcut is an expression that captures where in the codebase an aspect should be applied.