Core Java interview questions

// 40 QUESTIONS · UPDATED MAY 2026

Core Java interview questions for QA engineers and SDETs. Covers JVM internals, collections, concurrency primitives, streams, lambdas, exception handling, and OOP design — the Java fundamentals that appear in automation interviews.

Level

Showing 40 of 40 questions

  1. What is the difference between == and .equals() in Java?Junior

    == compares object references (memory addresses); .equals() compares object content. For String and all reference types, always use .equa…

  2. Explain the difference between ArrayList and LinkedList.Mid

    ArrayList is backed by a resizable array: O(1) random access by index, O(n) insert/delete in the middle. LinkedList is a doubly-linked li…

  3. How does garbage collection work in modern JVMs?Senior

    Modern JVM GC is generational: short-lived objects are collected cheaply in the Young generation (Eden + Survivor spaces); long-lived obj…

  4. What is the difference between String, StringBuilder, and StringBuffer?Junior

    String is immutable — every modification creates a new object. StringBuilder is mutable and fast but not thread-safe. StringBuffer is mut…

  5. Explain Java's primitive types and their wrapper classes.Junior

    Java has 8 primitives (byte, short, int, long, float, double, char, boolean) stored directly on the stack or inline in objects. Each has…

  6. What is autoboxing and unboxing? When does it become problematic?Junior

    Autoboxing is automatic conversion from a primitive to its wrapper (int → Integer); unboxing is the reverse. The compiler inserts these c…

  7. What is the difference between abstract class and interface in Java?Junior

    An abstract class can have state (fields), constructors, and concrete methods; a class can extend only one. An interface defines a contra…

  8. Explain Java's access modifiers — public, protected, package-private, and private.Junior

    private restricts access to the declaring class only. Package-private (no modifier) allows access within the same package. protected allo…

  9. What is the difference between throw and throws in Java?Junior

    `throw` is a statement that actually raises an exception at runtime. `throws` is a declaration in a method signature that warns callers t…

  10. What is the difference between checked and unchecked exceptions?Junior

    Checked exceptions extend Exception (not RuntimeException) and the compiler forces callers to handle or declare them. Unchecked exception…

  11. Explain the four pillars of OOP with Java examples.Junior

    Encapsulation hides internal state behind methods. Inheritance lets a subclass reuse and extend a parent class. Polymorphism lets a refer…

  12. What is the purpose of the `final` keyword in Java?Junior

    `final` means different things depending on where it's applied: a final variable cannot be reassigned; a final method cannot be overridde…

  13. Compare HashMap, LinkedHashMap, and TreeMap. When would you use each?Mid

    HashMap gives O(1) average get/put with no ordering guarantee. LinkedHashMap preserves insertion order at slight memory cost. TreeMap kee…

  14. What's the difference between HashMap and ConcurrentHashMap? How does ConcurrentHashMap achieve thread safety?Mid

    HashMap is not thread-safe — concurrent modifications can corrupt its internal structure or cause infinite loops during resize. Concurren…

  15. Explain the Stream API with a realistic data transformation example.Mid

    The Stream API provides a declarative pipeline for processing sequences of elements: source → zero-or-more intermediate operations (filte…

  16. What is the difference between intermediate and terminal stream operations?Mid

    Intermediate operations (filter, map, sorted, flatMap) are lazy — they return a new Stream and don't execute until a terminal operation i…

  17. What are functional interfaces? Provide 3 examples from the standard library.Mid

    A functional interface has exactly one abstract method and can be the target of a lambda or method reference. The @FunctionalInterface an…

  18. What is the diamond problem in Java and how does Java handle it?Mid

    The diamond problem arises when a class inherits from two sources that both provide the same method, creating ambiguity about which imple…

  19. What is the difference between Comparable and Comparator?Mid

    Comparable defines a class's natural ordering via compareTo() — the class itself implements it and can only have one. Comparator is an ex…

  20. How do try-with-resources statements work? Why are they preferred over try-finally?Mid

    try-with-resources automatically calls close() on any AutoCloseable declared in the parentheses when the block exits — whether normally o…

  21. Explain the role of the `volatile` keyword in concurrency.Mid

    `volatile` guarantees visibility: a write to a volatile variable is immediately flushed to main memory and all subsequent reads by any th…

  22. What is the difference between Runnable and Callable?Mid

    Runnable.run() returns void and cannot throw checked exceptions — it's fire-and-forget. Callable<V>.call() returns a value of type V and…

  23. How does ExecutorService work? Why use it over creating threads directly?Mid

    ExecutorService manages a pool of worker threads. You submit tasks (Runnable or Callable) and the pool dispatches them to available threa…

  24. What is the difference between String pool and heap memory for String objects?Mid

    String literals and strings produced by intern() are stored in the String pool (inside the heap in Java 7+), where identical strings shar…

  25. Explain Java's exception hierarchy starting from Throwable.Mid

    Throwable is the root. Error (and subclasses like OutOfMemoryError) represents unrecoverable JVM failures — never catch. Exception is for…

  26. What is a method reference and how does it relate to a lambda?Mid

    A method reference is shorthand for a lambda that does nothing but call an existing method. `String::toUpperCase` is equivalent to `s ->…

  27. Explain Optional<T> and when it's appropriate to use it.Mid

    Optional<T> is a container that may or may not hold a non-null value, making the possibility of absence explicit in the type system. It's…

  28. What is the difference between Map.of() and a HashMap with put() calls?Mid

    Map.of() (Java 9+) produces an unmodifiable map with no defined iteration order, null keys/values forbidden, and fixed at creation time.…

  29. How do you write a thread-safe Singleton in Java? Compare 2-3 approaches.Mid

    The cleanest modern approach is the initialization-on-demand holder (IODH) idiom or an enum singleton. Double-checked locking with volati…

  30. Walk through the JVM memory model — heap, stack, method area, and metaspace.Senior

    The JVM divides memory into several distinct runtime data areas. The heap stores all object instances and is garbage-collected. Each thre…

  31. Explain the Java Memory Model and the happens-before relationship.Senior

    The Java Memory Model (JMM) defines the rules for when one thread's writes are guaranteed to be visible to another thread. It does this t…

  32. What are virtual threads (Java 21) and how do they differ from platform threads?Senior

    Virtual threads (JEP 444, Java 21) are lightweight JVM-managed threads that are multiplexed onto a small pool of OS platform threads (car…

  33. How do CompletableFuture chains work? When are they better than ExecutorService.submit?Senior

    CompletableFuture (CF) is an implementation of Future and CompletionStage that supports non-blocking callback chains, explicit completion…

  34. Walk through how you'd diagnose a memory leak in a long-running Java service.Senior

    Diagnosing a Java memory leak follows a five-step process: observe the symptom (heap grows monotonically, OOM eventually), capture a heap…

  35. Explain the synchronized keyword vs ReentrantLock — when would you choose each?Senior

    synchronized is the built-in JVM monitor mechanism: simple, guaranteed to be released on exception, but limited to block-scoped locking.…

  36. How does the volatile keyword interact with the JMM? When is it sufficient and when isn't it?Senior

    A volatile field establishes a happens-before edge between its write and all subsequent reads: the write flushes to main memory and the r…

  37. What is escape analysis and stack allocation in the JVM?Senior

    Escape analysis is a JIT-compiler optimisation that determines whether an object created inside a method is accessible (escapes) outside…

  38. How would you safely shut down an ExecutorService with in-flight tasks?Senior

    A safe two-phase shutdown calls shutdown() to stop accepting new tasks, then awaits completion with awaitTermination(). If the timeout ex…

  39. How would you structure code review for Java in a QA team transitioning from manual to automation?Lead

    Structure reviews in three layers: a lightweight automated gate (compilation, checkstyle, test run) that every PR must pass without human…

  40. How do you decide between staying with Java for automation vs migrating to Kotlin or TypeScript?Lead

    The decision turns on four axes: team skill, ecosystem fit, AUT stack, and maintenance horizon. Java is the right default when the team i…