Spring, JPA & Java Web interview questions
45 Spring, JPA & Java Web interview questions with answers, from junior to mid level.
Foundations
- What is an annotation such as
@Overrideor@Servicein Java? - In Spring, what is a 'bean'?
- What is Apache Tomcat, and why do Spring Boot web apps often include it?
- A Spring Boot web app starts with default settings. On which port does the embedded server listen?
- What is
application.properties(orapplication.yml) in a Spring Boot project? - What are JPA (Jakarta Persistence) and Hibernate?
- What is start.spring.io (Spring Initializr)?
Core
- What is Spring Framework, in one sentence?
- What does Spring Boot add on top of Spring?
- What is Dependency Injection (DI)?
- Which injection style is generally recommended in Spring?
- What do
@Component,@Service,@Repositoryand@RestControllerhave in common? - What is the default scope of a Spring bean?
- What is the purpose of
@SpringBootApplication? - What does this endpoint do?
- Which annotation reads a JSON request body into a Java object?
- What is JDBC?
- What is a servlet and a servlet container (like Tomcat)?
- Explain Inversion of Control and Dependency Injection, and why Spring uses them.
Intermediate
- Where do you usually put settings such as the database URL in Spring Boot, and how do you switch between environments?
- What does Spring Boot auto-configuration do?
- What is the difference between
@Componentand@Bean? - What happens if two beans of the same type exist and you inject that type without more information?
- What does
@Transactionaldo? - What does a Spring Data JPA repository interface give you?
- In JPA, what do
@Entityand@Idmean? - What is the difference between LAZY and EAGER fetching in JPA?
- What is the role of
@ControllerAdvicewith@ExceptionHandler? - How do you validate request data in Spring Boot?
- Why use DTOs instead of exposing JPA entities directly in your API?
- Which test annotation starts the FULL Spring application context, and which loads only the web layer?
- What is Mockito used for in tests?
- How does a request flow through Spring MVC?
- What does Spring Security do by default when you just add the starter?
- What is Jackson and what happens in
@RestControllerwhen a method returns an object? - What is Spring Boot Actuator?
- What is the difference between
@RequestParamand@PathVariable? - Walk me through building a REST endpoint in Spring Boot, from request to database.
- Spring vs Spring Boot vs Spring MVC vs Spring Data: what is each?
Advanced
- Why might
@TransactionalNOT work in this code? - What is the N+1 problem in JPA and how do you fix it?
- What is the persistence context and what is "dirty checking"?
- What is Spring AOP (aspect-oriented programming) typically used for?
- Spring Boot 3 requires which Java version at minimum, and what package rename happened?
- What are the most common pitfalls with JPA/Hibernate and
@Transactional?