💻 Spring Boot Interview Questions and
Answers (for RippleHire)
🔹 1. What is Spring Boot?
Answer:
Spring Boot is a framework that simplifies Java-based application development by providing
pre-configured setups for Spring. It reduces boilerplate configuration through
auto-configuration and embedded servers like Tomcat or Jetty.
🔹 2. What are the main features of Spring Boot?
Answer:
● Auto Configuration
● Starter Dependencies
● Embedded Server Support
● Actuator (for monitoring)
● Easy integration with databases and security
🔹 3. What is the difference between Spring and Spring Boot?
Answer:
Feature Spring Spring Boot
Configuratio Manual XML/Java Auto-configured
n
Server Setup Needs external Embedded Tomcat/Jetty
server
Deployment WAR file Runnable JAR
Focus Framework Simplified microservices
🔹 4. What are Spring Boot Starters?
Answer:
Starters are dependency bundles that simplify adding required libraries.
Example:
● spring-boot-starter-web → for REST APIs
● spring-boot-starter-data-jpa → for database operations
🔹 5. What is @SpringBootApplication annotation?
Answer:
It is a combination of:
● @Configuration – marks class as configuration source
● @EnableAutoConfiguration – enables auto-configuration
● @ComponentScan – scans for components in the package
🔹 6. How do you create a REST API in Spring Boot?
Answer:
@RestController
@RequestMapping("/api")
public class UserController {
@GetMapping("/users")
public List<User> getUsers() {
return userRepository.findAll();
}
}
🔹 7. What is the use of @Autowired?
Answer:
@Autowired is used for dependency injection, automatically providing a required bean
into another bean.
Example:
@Autowired
private UserRepository userRepository;
🔹 8. What is the purpose of application.properties / application.yml file?
Answer:
It is used to define application configuration — such as database connection, server port,
etc.
Example:
spring.datasource.url=jdbc:mysql://localhost:3306/ripplehire
spring.datasource.username=root
spring.datasource.password=admin
🔹 9. What is Spring Data JPA?
Answer:
Spring Data JPA simplifies database access by providing a repository layer with pre-defined
methods like save(), findAll(), findById() etc.
🔹 10. What is @Entity and @Table annotation?
Answer:
● @Entity marks a Java class as a database entity.
● @Table specifies the table name in the database.
Example:
@Entity
@Table(name = "employees")
public class Employee {
@Id
private int id;
private String name;
}
🔹 11. What is @Repository?
Answer:
@Repository marks a class as a Data Access Object (DAO) and handles
database-related exceptions.
🔹 12. How do you handle exceptions in Spring Boot?
Answer:
Using @ControllerAdvice and @ExceptionHandler.
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
public ResponseEntity<String> handleError(Exception ex) {
return new ResponseEntity<>("Error: " + ex.getMessage(),
HttpStatus.INTERNAL_SERVER_ERROR);
}
}
🔹 13. How do you connect Spring Boot with MySQL?
Answer:
Add dependency in pom.xml:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
Then add DB config in application.properties.
🔹 14. What is @RestController vs @Controller?
Answer:
● @Controller → returns view (HTML/JSP).
● @RestController → returns JSON/XML directly (REST API).
🔹 15. How to test REST APIs in Spring Boot?
Answer:
Using Postman or Swagger UI (by adding springdoc-openapi-ui dependency).
🔹 16. What is Spring Boot Actuator?
Answer:
Actuator provides production-ready endpoints for monitoring app health, metrics, and logs.
Example: http://localhost:8080/actuator/health
🔹 17. What is the difference between @Component, @Service, and
@Repository?
Answer:
Annotation Purpose
@Componen Generic bean
t
@Service Business logic
layer
@Repository Data Access layer
🔹 18. What is the lifecycle of a Spring Bean?
Answer:
Instantiation → Properties Set → Initialization → Ready to Use → Destruction.
🔹 19. How do you secure a REST API in Spring Boot?
Answer:
Using Spring Security, JWT tokens, or OAuth 2.0.
🔹 20. RippleHire-level Scenario Question:
Q: You have a user registration API — how would you validate duplicate emails before
saving?
A:
● Use existsByEmail(String email) method in JPA Repository.
● Return error response if email already exists.
Example:
if(userRepository.existsByEmail(user.getEmail())) {
throw new RuntimeException("Email already registered");
}
🗄️ SQL Interview Questions and
Answers (for RippleHire)
🔹 1. What is SQL?
Answer:
SQL (Structured Query Language) is used to manage and manipulate relational databases.
🔹 2. What is the difference between DDL, DML, DCL?
Answer:
Type Example Purpose
DDL CREATE, ALTER, DROP Structure definition
DML INSERT, UPDATE, DELETE Data manipulation
DCL GRANT, REVOKE Access control
🔹 3. What is a Primary Key and Foreign Key?
Answer:
● Primary Key: Uniquely identifies each record.
● Foreign Key: Refers to the primary key of another table.
🔹 4. Write a query to get all employees with salary greater than 50,000.
SELECT * FROM employees WHERE salary > 50000;
🔹 5. What is the difference between WHERE and HAVING?
Answer:
● WHERE filters rows before grouping.
● HAVING filters groups after aggregation.
🔹 6. Write a query to count employees by department.
SELECT department, COUNT(*) AS total FROM employees GROUP BY department;
🔹 7. What is normalization?
Answer:
Process of organizing data to reduce redundancy and improve data integrity.
🔹 8. What are JOINS?
Answer:
Joins combine rows from two or more tables.
Types:
● INNER JOIN
● LEFT JOIN
● RIGHT JOIN
● FULL JOIN
Example:
SELECT e.name, d.dept_name
FROM employee e
JOIN department d ON e.dept_id = d.id;
🔹 9. What is the difference between DELETE and TRUNCATE?
Answer:
Command Effect Rollbac
k
DELETE Removes rows one by Yes
one
TRUNCATE Removes all rows No
instantly
🔹 10. How do you fetch the 2nd highest salary?
SELECT MAX(salary) FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
🔹 11. How do you find duplicate records in a table?
SELECT name, COUNT(*)
FROM employees
GROUP BY name
HAVING COUNT(*) > 1;
🔹 12. What is a Subquery?
Answer:
A query nested inside another query.
Example:
SELECT name FROM employee
WHERE dept_id = (SELECT id FROM department WHERE name='HR');
🔹 13. What is indexing in SQL?
Answer:
An index improves data retrieval speed on large tables.
🔹 14. What is a view?
Answer:
A virtual table based on the result of a SQL query.
CREATE VIEW high_salary AS
SELECT * FROM employees WHERE salary > 60000;
🔹 15. RippleHire Scenario:
Q: You need to store job applications. How would you design the schema?
A:
● Table 1: Candidate (candidate_id, name, email)
● Table 2: Job (job_id, title, dept)
● Table 3: Application (app_id, candidate_id, job_id, status)
With foreign keys between Candidate → Application and Job → Application.