0% found this document useful (0 votes)
8 views

SpringBoot_Backend_Interview_QA

Food Snap is a QR-enabled restaurant ordering system with a backend built on Spring Boot and MongoDB, utilizing React.js for the frontend. Key features include order tracking for admins and menu viewing for customers, with a focus on modular architecture through layered design. The document also covers various Spring Boot concepts such as dependency injection, transaction management, and data handling with JPA.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

SpringBoot_Backend_Interview_QA

Food Snap is a QR-enabled restaurant ordering system with a backend built on Spring Boot and MongoDB, utilizing React.js for the frontend. Key features include order tracking for admins and menu viewing for customers, with a focus on modular architecture through layered design. The document also covers various Spring Boot concepts such as dependency injection, transaction management, and data handling with JPA.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1. Explain your project 'Food Snap' and the backend architecture you used.

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

tracking and customer-side menu viewing and ordering.

2. What is the difference between @RestController and @Controller in Spring Boot?

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).

3. How does Spring Boot manage dependency injection internally?

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

@ConditionalOnProperty can be used for environment-specific bean creation.

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(),

findById(), findAll(), deleteById(). Example: employeeRepository.save(employee);

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

dependency management. It simplifies setup and makes development faster.

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

setters. Constructor injection is preferred for immutability and testability.

8. Difference between @Component, @Service, and @Repository.

Ans: @Component is a generic stereotype. @Service marks a service class. @Repository is used for data

access objects and adds exception translation.

9. How does @Transactional help in backend development?

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.

Example: spring.datasource.url, server.port, env.type.

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

EAGER fetch type, @Transactional, or DTO projection.

14. What is the difference between save() and saveAll() in JPA?

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

is used where strict relations and transactions are required.

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

/api/bookings with JSON payload to create a new booking.

19. What is the difference between Comparable and Comparator?

Ans: Comparable is used for natural ordering (implements compareTo). Comparator is used for custom

ordering (implements compare). Comparator is more flexible.

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

TreeNode (if threshold is crossed). Uses equals() to match keys.

You might also like