← QA

Java Core Interview Questions and Answers

Java for QA automation and developers: the JVM, types and strings, OOP, interfaces and records, collections and generics, exceptions, lambdas and streams, Optional, concurrency and the memory model, virtual threads, GC and memory, JUnit 5, TestNG, Mockito and AssertJ, Maven and Gradle, and parallel test frameworks.

225 questions for Java Core interviews with answers and explanations - Junior, Middle and Senior levels. Sample questions, online quizzes and coding tasks.

Questions by level

Sample questions

A few questions from each level with the correct answer and an explanation.

Java Core · Junior

  1. What does the JVM do?
    Show the answer

    Correct answer: Runs compiled bytecode on a specific platform

    javac compiles .java files into .class bytecode. The JVM loads and runs that bytecode, interpreting it and compiling hot parts with the JIT.

  2. What's the difference between the JDK and the JRE?
    Show the answer

    Correct answer: The JDK adds development tools like javac to what is needed to run Java

    The JRE was just what you needed to run programs. The JDK includes it plus the compiler, debugger and other tools. Modern Java ships the JDK only.

  3. Which of these is a primitive type in Java?
    Show the answer

    Correct answer: int

    Java has eight primitives: byte, short, int, long, float, double, char, boolean. Integer is a wrapper class, String is a class.

  4. What is the default value of an int field in a class?
    Show the answer

    Correct answer: 0

    Fields get defaults: 0 for numbers, false for boolean, null for references. Local variables have no default and must be assigned before use.

All 75 questions with answers →

Java Core · Middle

  1. How does HashMap find a value by key?
    Show the answer

    Correct answer: It uses hashCode to pick a bucket, then equals to find the key in it

    A good hashCode spreads keys across buckets. Long chains (since Java 8) turn into trees, but bad hash codes still slow things down.

  2. You put an object into a HashSet, then change a field used in its hashCode. What happens?
    Show the answer

    Correct answer: The set may no longer find it, though it is still inside

    The object stays in the old bucket. Keys of hash collections should be immutable, at least in the fields used by equals and hashCode.

  3. What is the 'load factor' of a HashMap?
    Show the answer

    Correct answer: How full it may get before it resizes, 0.75 by default

    When size exceeds capacity x load factor, the map doubles and rehashes. Setting the initial capacity avoids repeated resizing.

  4. What does PECS mean for generic wildcards?
    Show the answer

    Correct answer: Producer extends, consumer super

    Read from a List<? extends Number>, write into a List<? super Integer>. Collections.copy uses exactly this.

All 75 questions with answers →

Java Core · Senior

  1. What does 'happens-before' mean in the Java Memory Model?
    Show the answer

    Correct answer: If A happens-before B, B is guaranteed to see A's effects

    Unlock-then-lock, volatile write-then-read, thread start and join create such edges. Without one, reads may see stale values.

  2. Why are properly built immutable objects safe to share between threads?
    Show the answer

    Correct answer: Final fields are guaranteed visible after construction, and nothing changes

    The final-field semantics guarantee safe publication if this doesn't escape the constructor.

  3. Which thread runs CompletableFuture.supplyAsync(task) without an executor?
    Show the answer

    Correct answer: A thread from the shared ForkJoinPool.commonPool

    Blocking I/O in the common pool starves parallel streams and other async code. Pass a dedicated executor for I/O.

  4. An exception is thrown inside thenApply. What does the caller see on join()?
    Show the answer

    Correct answer: A CompletionException wrapping the original cause

    Handle with exceptionally or handle, and unwrap getCause() in tests to assert on the real exception.

All 75 questions with answers →

Coding tasks

Write your solution right in the browser, and tests check it instantly. JavaScript interview classics (debounce, deepClone, Promise.all, an LRU cache), TypeScript tasks on generics, narrowing and utility types checked by the real compiler, Node.js backend logic (middleware, rate limiters, job queues), SQL queries in real PostgreSQL, and React components and hooks like a todo list, tabs, useDebounce and useInterval.

Open tasks →