Exception Handling Interview Questions for 5 Years Experience

Exception Handling Interview Questions for 5 Years Experience Work through these 12 questions out loud. Open any question for the full model answer, the trap to avoid, and the follow-up a panel usually asks.

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

    Full answer

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

    Full answer

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

    Full answer

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

    Full answer

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

    Full answer

  6. 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,...

    Full answer

  7. How do you handle exceptions globally in Spring?

    Create @RestControllerAdvice with @ExceptionHandler(MethodArgumentNotValidException.class) returning 400 + field map, NotFoundException → 404, generic Exception → 500 without...

    Full answer

  8. What is Optional and when should you use it?

    Use Optional as return type when absence is expected — findById returns Optional<User>. Chain with map/flatMap/orElseThrow. Do not use for fields, method parameters, or Jackson...

    Full answer

  9. When should you use CopyOnWriteArrayList?

    Use for subscriber lists in pub/sub where adds are rare and iteration is constant. Avoid for high-frequency add/remove — use ConcurrentLinkedQueue or synchronized collections....

    Full answer

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

    Full answer

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

    Full answer

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

    Full answer

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