Spring Boot MCQ

Spring Boot, a sub-project of the Spring framework, has gained tremendous popularity among Java developers. Its primary strength lies in simplifying the creation and deployment of Spring applications by removing much of the boilerplate configuration. If you're new to Spring Boot, this set of Multiple Choice Questions (MCQs) offers a gentle introduction and a way to test your foundational knowledge.

1. What is the primary purpose of Spring Boot?

a) Mobile application development
b) Microservice creation
c) Simplified Spring application setup
d) Frontend UI development

Answer:

c) Simplified Spring application setup

Explanation:

While Spring Boot can be used in various contexts like microservice development, its chief aim is to streamline the configuration and deployment of Spring applications.

2. Which embedded server does Spring Boot provide by default for web applications?

a) Jetty
b) JBoss
c) Apache Tomcat
d) GlassFish

Answer:

c) Apache Tomcat

Explanation:

Spring Boot offers an embedded Apache Tomcat server out of the box, allowing web applications to be easily run without external server setups.

3. What role do "starters" play in Spring Boot?

a) They serve as entry points for applications.
b) They provide a set of default dependencies for specific tasks.
c) They define application properties.
d) They handle database migrations.

Answer:

b) They provide a set of default dependencies for specific tasks.

Explanation:

Starters in Spring Boot are templates that furnish a set of default dependencies, easing dependency management for common tasks.

4. Which file format cannot be used to configure properties in Spring Boot?

a) .XML
b) .properties
c) .json
d) .yml

Answer:

c) .json

Explanation:

Spring Boot primarily supports .properties and .yml (YAML) for externalized configuration. Traditional XML can be used in certain contexts but not for the main application properties.

5. Which annotation activates Spring Boot's auto-configuration?

a) @Activate
b) @SpringBootApplication
c) @AutoConfigure
d) @Configure

Answer:

b) @SpringBootApplication

Explanation:

The @SpringBootApplication annotation encompasses several annotations, including @EnableAutoConfiguration, which activates Spring Boot’s auto-configuration feature.

6. How does Spring Boot decide whether to autoconfigure a specific feature?

a) Based on classes available in the classpath
b) Depending on the JVM version
c) Based on the spring.xml configuration file
d) By analyzing the database schema

Answer:

a) Based on classes available in the classpath

Explanation:

Spring Boot autoconfiguration is driven by the presence or absence of specific classes in the classpath, among other conditions.

7. What does Actuator in Spring Boot provide?

a) API documentation
b) Security features
c) Production-ready features like health checks and metrics
d) Data binding

Answer:

c) Production-ready features like health checks and metrics

Explanation:

The Spring Boot Actuator provides a range of production-ready features such as monitoring, metrics, and even custom endpoints, making it easier to monitor and manage applications.

8. To externalize Spring Boot's configuration, where can properties be specified?

a) application.properties
b) springboot.properties
c) config.properties
d) external.properties

Answer:

a) application.properties

Explanation:

Spring Boot looks for external configurations in an application.properties file by default.

9. What is the purpose of spring-boot-starter-parent?

a) It provides useful Maven defaults.
b) It contains core libraries for Spring Boot.
c) It adds logging dependencies.
d) It generates a basic project structure.

Answer:

a) It provides useful Maven defaults.

Explanation:

spring-boot-starter-parent provides default configurations, dependency management, and other useful settings for Maven-based Spring Boot projects.

10. How can you specify a specific port number for your Spring Boot application?

a) By modifying the server.xml file
b) By adding server.port= in the application.properties file
c) By using the @Port annotation
d) By configuring the embedded server manually

Answer:

b) By adding server.port= in the application.properties file

Explanation:

The port number for a Spring Boot application can easily be specified using the server.port property in the application.properties file.

11. What is the primary advantage of using Spring Boot?

a) Enhanced Performance
b) Modular Development
c) Rapid Development
d) Rich User Interface

Answer:

c) Rapid Development

Explanation:

While Spring Boot has various benefits, its primary advantage is the acceleration of application development processes with minimal configuration.

12. How does Spring Boot simplify database configurations?

a) By eliminating the need for a database
b) By using conventions for data source URLs and drivers
c) By using JPA as the only option
d) By automating table creation

Answer:

b) By using conventions for data source URLs and drivers

Explanation:

Spring Boot uses convention over configuration, which means it provides sensible defaults (e.g., default data source URLs and drivers) but allows them to be overridden if needed.

13. If you want to override Spring Boot's default configurations, which file should you modify?

a) spring.xml
b) boot-config.properties
c) application.yml or application.properties
d) boot.properties

Answer:

c) application.yml or application.properties

Explanation:

Spring Boot allows users to override its default configurations using the application.properties or application.yml file.

14. Which of these is a benefit of using Spring Boot?

a) Eliminates the need for code
b) Reduces boilerplate code
c) Guarantees bug-free applications
d) Only supports web applications

Answer:

b) Reduces boilerplate code

Explanation:

Spring Boot simplifies application development by reducing boilerplate code, automating configurations, and providing sensible defaults. However, it doesn't eliminate the need for code or guarantee bug-free applications.

15. What is the primary purpose of @SpringBootApplication annotation?

a) Only to activate component scanning
b) Just to enable Spring Boot's autoconfiguration
c) To launch the embedded Tomcat server
d) A combination of component scanning, autoconfiguration, and Spring Boot's configuration

Answer:

d) A combination of component scanning, autoconfiguration, and Spring Boot's configuration

Explanation:

@SpringBootApplication is a convenience annotation that includes @Configuration, @EnableAutoConfiguration, and @ComponentScan.

16. Which annotation is specifically used to indicate that a class provides Bean definitions?

a) @Bean
b) @Entity
c) @Configuration
d) @Component

Answer:

c) @Configuration

Explanation:

The @Configuration annotation indicates that a class declares one or more @Bean methods which will be processed by the Spring container.

17. What is the primary function of @Conditional annotation in Spring Boot?

a) To run SQL conditional statements
b) To specify that a component should only be configured under specific circumstances
c) To execute conditions during runtime
d) To validate bean properties

Answer:

b) To specify that a component should only be configured under specific circumstances

Explanation:

@Conditional is used to indicate a condition that, when met, enables the configuration or component.

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

a) @RestController
b) @Controller
c) @Component
d) @Rest

Answer:

a) @RestController

Explanation:

When you annotate a class with @RestController, it indicates that the class is a Spring MVC REST controller responsible for handling incoming HTTP requests and generating the appropriate HTTP responses.

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

a) @GetMapping
b) @PutMapping
c) @CreateMapping
d) @PostMapping

Answer:

d) @PostMapping

Explanation:

The @PostMapping annotation is used to map an HTTP POST request to a specific handler method in a Spring MVC controller. It is a shortcut for specifying the @RequestMapping annotation with the RequestMethod.POST method.

20. Which starter dependency is used to develop web applications or Restful web services?

a) spring-boot-starter-data-jpa
b) spring-boot-starter-web
c) spring-boot-starter-rest
d) spring-boot-starter-web-dependency

Answer:

b) spring-boot-starter-web

Explanation:

The spring-boot-starter-web dependency provides the necessary components to develop Web Applications and RESTful API in a Spring Boot project, including the embedded Tomcat server, Spring Web MVC, and other required dependencies.



Comments