Bird
Raised Fist0
Spring Bootframework~10 mins

What is Spring Boot in Spring Boot - Interactive Quiz & Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a basic Spring Boot application class.

Spring Boot
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.[1](Application.class, args);
    }
}
Drag options to blanks, or click blank then click option'
Astart
Brun
Claunch
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' or 'launch' instead of 'run' causes errors.
Forgetting to call a method to start the app.
2fill in blank
medium

Complete the annotation to mark the main class as a Spring Boot application.

Spring Boot
import org.springframework.boot.autoconfigure.SpringBootApplication;

@[1]
public class MyApp {}
Drag options to blanks, or click blank then click option'
ASpringBootApp
BComponentScan
CEnableAutoConfiguration
DSpringBootApplication
Attempts:
3 left
💡 Hint
Common Mistakes
Using only @EnableAutoConfiguration misses component scanning.
Using wrong annotation names causes the app not to start.
3fill in blank
hard

Fix the error in the code to correctly inject a service in Spring Boot.

Spring Boot
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.[1];

@Service
public class MyService {
    // service methods
}
Drag options to blanks, or click blank then click option'
AComponent
BInject
CAutowired
DResource
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Inject requires extra setup and is not default in Spring Boot.
Using @Component on a field is incorrect.
4fill in blank
hard

Fill both blanks to create a REST controller with a GET endpoint in Spring Boot.

Spring Boot
import org.springframework.web.bind.annotation.[1];
import org.springframework.web.bind.annotation.[2];

@[1]("/hello")
public class HelloController {
    @[2]("/")
    public String greet() {
        return "Hello, Spring Boot!";
    }
}
Drag options to blanks, or click blank then click option'
ARestController
BGetMapping
CController
DPostMapping
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Controller instead of @RestController requires extra setup.
Using @PostMapping instead of @GetMapping changes the HTTP method.
5fill in blank
hard

Fill all three blanks to define a Spring Boot application with a service and controller.

Spring Boot
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

@SpringBootApplication
public class [1] {
    public static void main(String[] args) {
        SpringApplication.[2]([3].class, args);
    }
}

@Service
class GreetingService {
    public String greet() {
        return "Hello from service!";
    }
}

@RestController
class GreetingController {
    private final GreetingService service;

    @Autowired
    public GreetingController(GreetingService service) {
        this.service = service;
    }

    @GetMapping("/greet")
    public String greet() {
        return service.greet();
    }
}
Drag options to blanks, or click blank then click option'
AApplication
Brun
CMyApp
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using different class names in main and run causes errors.
Using 'start' instead of 'run' causes runtime errors.

Practice

(1/5)
1. What is the main purpose of Spring Boot in Java development?
easy
A. To simplify and speed up Java application setup and development
B. To replace the Java programming language
C. To create mobile applications only
D. To manage database connections exclusively

Solution

  1. Step 1: Understand Spring Boot's role

    Spring Boot is designed to make Java app development faster and easier by reducing setup complexity.
  2. Step 2: Compare options

    The other options describe roles that Spring Boot does not fulfill; it does not replace Java, is not limited to mobile apps, nor only manages databases.
  3. Final Answer:

    To simplify and speed up Java application setup and development -> Option A
  4. Quick Check:

    Spring Boot purpose = Simplify Java apps [OK]
Hint: Spring Boot = fast, simple Java app setup [OK]
Common Mistakes:
  • Thinking Spring Boot replaces Java language
  • Believing Spring Boot is only for mobile apps
  • Assuming it only manages databases
2. Which annotation is used to mark the main class in a Spring Boot application?
easy
A. @Controller
B. @Service
C. @Entity
D. @SpringBootApplication

Solution

  1. Step 1: Identify main class annotation

    The main class in Spring Boot is marked with @SpringBootApplication to enable auto-configuration and component scanning.
  2. Step 2: Review other annotations

    @Controller is for web controllers, @Entity for database entities, and @Service for service layer components, not for main app class.
  3. Final Answer:

    @SpringBootApplication -> Option D
  4. Quick Check:

    Main class annotation = @SpringBootApplication [OK]
Hint: Main class uses @SpringBootApplication annotation [OK]
Common Mistakes:
  • Confusing @Controller with main class annotation
  • Using @Entity or @Service incorrectly for main class
  • Missing the auto-configuration role of @SpringBootApplication
3. Consider this Spring Boot main class code snippet:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MyApp {
    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }
}

What happens when you run this application?
medium
A. Nothing happens because main method is missing
B. The application throws a compilation error
C. The application starts with default configuration and embedded server
D. The application runs but without any web server

Solution

  1. Step 1: Analyze the main method

    The main method calls SpringApplication.run() with the main class, which starts the Spring Boot app.
  2. Step 2: Understand Spring Boot defaults

    Spring Boot auto-configures and starts an embedded web server by default unless configured otherwise.
  3. Final Answer:

    The application starts with default configuration and embedded server -> Option C
  4. Quick Check:

    SpringApplication.run starts app with defaults [OK]
Hint: SpringApplication.run starts app with embedded server [OK]
Common Mistakes:
  • Thinking main method is missing
  • Assuming no server starts by default
  • Expecting compilation errors from correct code
4. Identify the error in this Spring Boot main class:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class);
    }
}
medium
A. Missing second argument 'args' in SpringApplication.run call
B. Incorrect annotation used instead of @SpringBootApplication
C. Main method should return void, not be static
D. Class name should be 'Application' not 'App'

Solution

  1. Step 1: Check SpringApplication.run parameters

    The method requires two arguments: the class and the args array from main method.
  2. Step 2: Identify missing argument

    The code calls SpringApplication.run(App.class) missing the second argument args, preventing command-line arguments from being passed to the application.
  3. Final Answer:

    Missing second argument 'args' in SpringApplication.run call -> Option A
  4. Quick Check:

    SpringApplication.run needs class and args [OK]
Hint: SpringApplication.run needs both class and args [OK]
Common Mistakes:
  • Omitting args parameter in run method
  • Confusing annotation names
  • Changing main method signature incorrectly
5. You want to create a Spring Boot app that starts quickly with minimal setup. Which combination best achieves this?
hard
A. Manually configure all beans and avoid @SpringBootApplication
B. Use @SpringBootApplication on main class and call SpringApplication.run with args
C. Use only @Controller annotation without main class
D. Write a main method without SpringApplication.run

Solution

  1. Step 1: Identify minimal setup approach

    Using @SpringBootApplication and SpringApplication.run() provides auto-configuration and quick startup.
  2. Step 2: Evaluate other options

    Manual bean config is slow and complex; @Controller alone does not start app; main method without run won't launch Spring Boot.
  3. Final Answer:

    Use @SpringBootApplication on main class and call SpringApplication.run with args -> Option B
  4. Quick Check:

    Minimal setup = @SpringBootApplication + run() [OK]
Hint: Use @SpringBootApplication and run() for fast startup [OK]
Common Mistakes:
  • Skipping @SpringBootApplication annotation
  • Avoiding SpringApplication.run call
  • Confusing controller annotation with app start
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard