Spring Quiz - MCQ - Multiple Choice Questions

This post contains a few useful Spring Framework (MCQ) multiple-choice questions (quiz) to self-test your knowledge of the Spring Boot framework.


The answers to each question have been given at end of this post.

1. What is the main purpose of the Spring Framework? 

  1. To provide a comprehensive programming and configuration model for Java-based enterprise applications 
  2. To provide a comprehensive programming and configuration model for JavaScript-based web applications 
  3. To provide a comprehensive programming and configuration model for PHP-based web applications
  4. To provide a comprehensive programming and configuration model for Python-based web applications 

Answer:

1. To provide a comprehensive programming and configuration model for Java-based enterprise applications

2. What is the default scope of the Spring Bean?

  1. singleton
  2. prototype
  3. request
  4. session

Answer:

1. singleton

3. Different ways to configure Spring-based applications?

  1. XML based configuration
  2. Java-based configuration
  3. Annotation based configuration
  4. All of the above

Answer:

4. All of the above

4. What is the purpose of the Spring IoC container? 

  1. To manage the lifecycle of beans and their dependencies 
  2. To handle the configuration of the application 
  3. To provide a caching mechanism for the application 
  4. To provide a security mechanism for the application

Answer:

1. To manage the lifecycle of beans and their dependencies

5. What is the purpose of the Spring MVC module? 

  1. To provide a web framework for building web applications 
  2. To provide a data access framework for accessing databases 
  3. To provide a caching framework for caching data 
  4. To provide a security framework for securing web applications

Answer:

1. To provide a web framework for building web applications

6. What are Spring stereotype annotations?

  1. @Service
  2. @Controller
  3. @Repository
  4. @Component
  5. All of the above

Answer:

5. All of the above

7. What are two ways to achieve dependency Injection in Spring?

  1. Using Getter and Setter methods
  2. Using Setter and Constructor 
  3. Using Getter and Constructor
  4. Using Setter and Factory methods

Answer:

2. Using Setter and Constructor

8. What is the scope to create a new instance every time the bean is requested from the spring container?

  1. singleton
  2. prototype
  3. request
  4. session

Answer:

2. prototype

9. What is the purpose of the Spring MVC module? 

  1. To provide a web framework for building web applications 
  2. To provide a data access framework for accessing databases 
  3. To provide a caching framework for caching data 
  4. To provide a security framework for securing web applications 

Answer:

1. To provide a web framework for building web applications

10. Which is the front controller in Spring MVC?

  1. DispatcherServlet
  2. FrontDispatcherServlet
  3. FrontControllerService
  4. None of the above

Answer:

1. DispatcherServlet

11. Spring MVC Framework is designed based on which Design Pattern?

  1. Model-View-Controller (MVC)
  2. Layered pattern
  3. Client-server pattern
  4. None of the above

Answer:

1. Model-View-Controller (MVC)

12. In spring MVC, DispatcherServlet consults ____________ to map the logical view name with the actual view implementation

  1. ViewResolver
  2. Handler Mapper
  3. Controller
  4. Model

Answer:

1. ViewResolver

13. In Spring MVC web applications, all the HTTP requests first come to which component?

  1. DispatcherServlet
  2. Controller
  3. HandlerMapper
  4. None of the above

Answer:

1. DispatcherServlet

14. What is the purpose of the Spring JDBC module? 

  1. To provide a data access framework for accessing databases 
  2. To provide a web framework for building web applications 
  3. To provide aspect-oriented programming functionality 
  4. To provide caching functionality

Answer:

1. To provide a data access framework for accessing databases

15. Which Spring Framework module is used to implement cross-cutting concerns in Spring based-applications?

  1. ORM
  2. AOP
  3. JDBC
  4. TXM

Answer:

2. AOP

16. JdbcTemplate implements the below design pattern?

  1. Strategy design pattern
  2. Template Design pattern
  3. Singleton design pattern
  4. Decorator design pattern

Answer:

2. Template Design pattern

17. Different ways to inject Spring beans in Spring-based applications?

  1. Constructor based
  2. Setter based
  3. Field-based
  4. All of the above

Answer:

4. All of the above

18. Are singleton beans thread-safe?

  1. Yes
  2. No

Answer:

2. No

19. Which Spring annotation is used to create RESTful web services using Spring MVC?

  1. @RestController
  2. @Controller
  3. @Component
  4. @Rest

Answer:

1. @RestController

20. @RestController annotation is a combination of the below two annotations

  1. @Component and @ResponseBody annotations
  2. @Controller and @ResponseBody annotations
  3. @Service and @ResponseBody annotations
  4. None of the above

Answer:

2. @Controller and @ResponseBody annotations

21. Which Spring annotation is used to handle HTTP POST requests?

  1. @GetMapping
  2. @PutMapping
  3. @CreateMapping
  4. @PostMapping

Answer:

4. @PostMapping

22. Which Spring annotation is used to handle HTTP GET requests?

  1. @GetMapping
  2. @PutMapping
  3. @CreateMapping
  4. @PostMapping

Answer:

1. @GetMapping

23. Which Spring annotation is used to handle HTTP DELETE requests?

  1. @GetMapping
  2. @PutMapping
  3. @DeleteMapping
  4. @PostMapping

Answer:

@DeleteMapping

24. Which Spring annotation is used to handle HTTP PUT requests?

  1. @GetMapping
  2. @PutMapping
  3. @DeleteMapping
  4. @PostMapping

Answer:

2. @PutMapping

25. Which annotation do we use to mark the class as a Service class/component?

  1. @Component
  2. @Service
  3. @Controller
  4. @Repository

Answer:

2. @Service

26. What is the primary use of the Spring Security module? 

  1. To provide authentication and authorization for web applications 
  2. To provide data access and management 
  3. To provide Model-View-Controller architecture 
  4. To provide aspect-oriented programming functionality 

Answer:

1. To provide authentication and authorization for web applications

27. Which Spring annotation is used to inject the Spring bean?

  1. @Bean
  2. @Autowired
  3. @Service
  4. @Inject

Answer:

2. @Autowired

28. Which Spring annotation is used to extract the URI template variable value?

  1. @PathVariable
  2. @ParamRequest
  3. @ModelAttribute
  4. @RequestMapping

Answer:

1. @PathVariable

29. Which interface represents the Spring IOC container?

  1. ApplicationContent
  2. ApplicationContentFactory
  3. SessionFactory
  4. DispatchServlet

Answer:

1. ApplicationContext

Free Spring Boot Tutorial | Full In-depth Course | Learn Spring Boot in 10 Hours


Watch this course on YouTube at Spring Boot Tutorial | Fee 10 Hours Full Course

Comments