Top 10 Exception Handling Interview Questions Every Fresher Should Know
Top 10 Exception Handling Interview Questions Every Fresher Should Know Work through these 10 questions out loud. Open any question for the full model answer, the trap to avoid, and the follow-up a panel usually asks.
Multiple beans of the same type exist and Spring throws an error. How do you fix it?
Spring needs disambiguation when two `@Service` implement the same interface. ```java @Primary @Service public class StripePaymentGateway implements PaymentGateway {} @Service...
What happens if @Transactional fails midway? How do you verify rollback?
Default: runtime exception marks rollback-only; transaction commits nothing on exit. ```java @Transactional(rollbackFor = Exception.class) public void placeOrder(Order o) {...
What happens if an exception occurs inside a filter or interceptor?
Exceptions in `Filter` bypass `@ControllerAdvice` unless handled. Filters run before MVC. ```java @Override protected void doFilterInternal(HttpServletRequest req,...
Difference between @Component, @Service, @Repository?
All register as singleton beans via component scan. Choose by layer for readability: @Repository on DAOs (plus SQLException translation), @Service on business logic, @Component...
Explain try-with-resources and suppressed exceptions.
try (Connection c = ds.getConnection(); PreparedStatement ps = c.prepareStatement(sql)) { ... } — both closed even on SQLException. Check e.getSuppressed() in logs for close...
How does Bean Validation work in Spring Boot 3?
DTO fields: @NotBlank, @Email, @Size. Controller: createUser(@Valid @RequestBody UserDto dto). Global @RestControllerAdvice maps MethodArgumentNotValidException to 400 + field...
What is ProblemDetail (RFC 7807) in Spring 6 error handling?
@ExceptionHandler(NotFoundException.class) ProblemDetail handle(NotFoundException ex) { return ProblemDetail.forStatusAndDetail(NOT_FOUND, ex.getMessage()); } — consistent 404...
What are common mistakes freshers make in Spring Boot projects?
```java // ❌ Wrong @RestController public class OrderController { @PostMapping("/orders") public Order create(@RequestBody Order o) { return orderRepository.save(o); // DB in...
Explain the difference between == and .equals() in Java.
For primitives, == compares values. For objects, == asks if two references point to the same instance. equals() compares content when overridden — String overrides it for...
How do you handle exceptions globally in Spring?
Create @RestControllerAdvice with @ExceptionHandler(MethodArgumentNotValidException.class) returning 400 + field map, NotFoundException → 404, generic Exception → 500 without...
Exception Handling Interview Questions and Answers · Top 50 Exception Handling Interview Questions and Answers (2026 Edition) · Top 40 Exception Handling Interview Questions | Must-Prepare before interview. · Exception Handling Interview Questions Every Fresher Must Know
All interview question lists · Interview guides · Home · Support the platform