Top 10 Java OOP Interview Questions Every Fresher Should Know

Top 10 Java OOP 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.

  1. What is dependency injection and why does Spring use it?

    DI supplies collaborators from outside the class — typically via constructor. Problem solved: tight coupling to concrete classes, hard unit tests, scattered object...

    Full answer

  2. @RestController vs @Controller?

    @Controller is for traditional MVC — return "user/list" view name. @RestController adds @ResponseBody so return types become JSON/XML body — standard for REST APIs. Use...

    Full answer

  3. What is the difference between Comparable and Comparator?

    Comparable built into the type — Employee implements compareTo by id. Comparator external — sort by name or salary without changing Employee. Use...

    Full answer

  4. Explain method overloading vs overriding.

    Overload print(int) and print(String) in one class — compiler picks at compile time. Override toString in subclass — JVM calls subclass version via virtual method table....

    Full answer

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

  6. What is the difference between JPA and Hibernate?

    JPA is the API contract; Hibernate is the engine under Spring Boot by default. You write @Entity per JPA spec; Hibernate handles SQL generation. Spring Data JpaRepository adds...

    Full answer

  7. Explain sealed classes and their purpose in Java 17+.

    sealed interface Shape permits Circle, Rectangle limits who implements Shape. Compiler verifies switch (Shape s) covers all cases — no default needed. Use for domain variants...

    Full answer

  8. What is the Java Platform Module System (JPMS) and who needs it?

    Use modules when building custom JDK images or publishing strict API boundaries. Typical microservice: no module-info — Spring Boot repackages classpath. Watch for illegal...

    Full answer

  9. Explain @ConfigurationProperties vs @Value.

    @ConfigurationProperties(prefix = "app.payment") record PaymentProps(int timeout, String apiUrl) {} — validated, testable, grouped. Use @Value only for single feature flags....

    Full answer

  10. When use @Query native SQL vs JPQL in Spring Data JPA?

    JPQL for standard entity fetches and portable logic. Native for PostgreSQL-specific jsonb queries, recursive CTEs, or performance-tuned index hints after EXPLAIN. Interface...

    Full answer

Java OOP Interview Questions and Answers · Top 50 Java OOP Interview Questions and Answers (2026 Edition) · Top 40 Java OOP Interview Questions | Must-Prepare before interview. · Java OOP Interview Questions Every Fresher Must Know

All interview question lists · Interview guides · Home · Support the platform