SpringBoot_Backend_Interview_QA
SpringBoot_Backend_Interview_QA
Ans: Food Snap is a QR-enabled restaurant ordering system. Backend is built using Spring Boot with MVC
architecture (Controller, Service, Repository layers), and data is stored in MongoDB. React.js is used on the
frontend, communicating with Spring Boot through REST APIs. The system supports admin-side order
Ans: @RestController combines @Controller and @ResponseBody. It returns data (usually JSON) directly in
RESTful APIs. @Controller is used for server-side rendering where it returns view names (e.g., HTML pages
with Thymeleaf).
Ans: Spring Boot uses the ApplicationContext to scan for beans (@Component, @Service, @Repository),
registers them, and injects them using @Autowired. This enables loose coupling. @Bean and
4. Can you explain the layered architecture in your Hotel Booking System project (Controller, Service,
Repository)?
Ans: The Controller layer handles HTTP requests. The Service layer contains business logic. The Repository
layer interacts with the database using Spring Data JPA. This separation improves modularity and
maintainability.
5. How do you perform CRUD operations in Spring Data JPA? Give an example.
Ans: You extend JpaRepository in your repository interface. Spring provides built-in methods like save(),
6. What are the advantages of using Spring Boot over traditional Spring Framework?
Ans: Spring Boot reduces boilerplate code, provides embedded servers (Tomcat), auto-configuration, and
7. What does @Autowired do? What are its types (constructor, field, setter injection)?
Ans: @Autowired tells Spring to inject a dependency automatically. It can be used on fields, constructors, or
Ans: @Component is a generic stereotype. @Service marks a service class. @Repository is used for data
Ans: @Transactional manages transactions automatically. It ensures atomicityif any step fails, all changes
are rolled back. Its useful for operations involving multiple DB changes.
10. What is the role of application.properties in your Spring Boot project?
Ans: It stores configuration like database URL, port number, custom properties, and bean activation settings.
11. Explain the relationship between Employee and Department using @ManyToOne and
@OneToMany.
Ans: An Employee belongs to one Department (@ManyToOne), and a Department can have many
Employees (@OneToMany). These are mapped with JPA annotations to handle relational data.
12. How is data fetched from MySQL using Spring Data JPA?
Ans: By creating a repository interface extending JpaRepository. Spring Boot provides implementation at
runtime. You can also define custom queries using @Query or method names.
13. What are some common issues with lazy loading and how do you solve them?
Ans: Lazy loading can cause LazyInitializationException when accessed outside transaction. Solutions: use
Ans: save() persists a single entity. saveAll() persists a list of entities in batch mode.
15. In your Restaurant Management System, how do you handle multiple orders and their statuses?
Ans: Orders are stored with status fields (e.g., Pending, Preparing, Completed). Admin can update status
through REST API. Each order is associated with customer and table info.
16. How did you implement real-time notifications in your Food Snap project?
Ans: For real-time updates, polling or WebSocket can be used. For the prototype, the admin panel was
periodically refreshed to fetch latest orders using scheduled fetch calls in React.
17. Why did you choose MongoDB for some parts and MySQL for others?
Ans: MongoDB is schema-less and suitable for flexible or hierarchical data like dynamic menu items. MySQL
18. How did you test your APIs using Postman? Give an example.
Ans: Postman was used to test endpoints by sending HTTP requests. Example: Sending POST request to
Ans: Comparable is used for natural ordering (implements compareTo). Comparator is used for custom
20. Explain the internal working of HashMap. What happens in case of a collision?
Ans: HashMap uses hashCode to find bucket. In case of collisions, entries are stored in a LinkedList or