π§ Quiz β Week 5: Spring Boot
This quiz is designed to test your understanding of:
- Spring Boot fundamentals
- REST APIs
- Dependency Injection
- Backend architecture
π Try to answer without referring to notes.
π Section 1: Conceptual Questions
1. What problem does Spring Framework solve?
2. What is Inversion of Control (IoC)?
3. What is Dependency Injection?
4. Difference between Spring and Spring Boot?
5. What is a REST API?
6. What does @SpringBootApplication do?
7. What is the role of @RestController?
8. Why do we use @RequestMapping?
9. Difference between:
@GetMapping@PostMapping
10. What is the purpose of application.properties?
π» Section 2: Code Understanding
11. What is wrong in the following code?
```java id=β2wblvrβ @RestController public class UserController {
@GetMapping("/users")
public List<String> getUsers() {
UserService service = new UserService();
return service.getUsers();
} } ```
12. What will happen if Spring cannot find a bean to inject?
13. What is the output of this API?
```java id=βmb4npbβ @GetMapping(β/testβ) public String test() { return βSpring Boot Working!β; }
---
### 14. Identify the mistake:
```java id="sv3h83"
@Service
public class UserService {
}
```java id=β2a0md8β @RestController public class UserController {
private UserService userService;
public UserController() {
this.userService = new UserService();
} } ```
π Section 3: Practical Thinking
15. Design an API to:
- Get all products
- Add a product
What endpoints will you create?
16. Where should business logic be written?
17. Why should controllers be kept thin?
18. What happens if multiple responsibilities are placed in one class?
π§ͺ Section 4: API Testing
19. How will you test a POST API?
20. What status code should be returned for:
- Successful GET
- Resource created
- Invalid request
- Resource not found
21. What happens if you call:
GET /invalid-endpoint
π Section 5: Debugging & Scenario-Based
22. Your API is returning 500 Internal Server Error. What will you check?
23. Your API is not getting called. What could be the reasons?
24. You added a service class but Spring is not injecting it. Why?
25. You wrote a REST API but browser shows 404. What could be wrong?
π Self-Evaluation
After completing this quiz, you should be able to:
β Explain core Spring concepts β Understand REST APIs β Identify common mistakes β Think like a backend developer