Java interview questions and answers

A Java technical interview almost always covers the same topics: how the JVM works, the difference between == and equals(), collections, exceptions and object-oriented programming. Junior roles focus on the fundamentals; mid-level and senior roles also test your judgment to choose between alternatives and explain why.

These are questions Syntax, the recruiter in SyntaxQuest’s mock interview, may ask you for backend and Android roles, each with a short, verified answer. After them come three code snippets of the kind interviewers use to check whether you really understand the language.

Updated · SyntaxQuest

Java technical questions

Short answers, the way you would say them out loud. If you can explain them in your own words and give an example, you’re on the right track.

  1. What’s the difference between the JDK, the JRE and the JVM?

    The JVM runs bytecode. The JRE is the JVM plus the libraries needed to run programs. The JDK is all of that plus development tools such as the compiler (javac) and the debugger. Since Java 11, Oracle only ships the JDK.

  2. What’s the difference between == and equals()?

    With objects, == compares references (whether they’re the same object) and equals() compares content, as long as the class overrides it, like String and Integer do. With primitives (int, double…), == compares values. Always use equals() to compare strings.

  3. What’s the difference between overloading and overriding?

    Overloading: several methods with the same name and different parameters; the compiler decides which one to call. Overriding: a subclass redefines an inherited method with the same signature (@Override) and, at runtime, the version of the object’s actual class is called. It’s the basis of polymorphism.

  4. What’s the difference between ArrayList and LinkedList?

    ArrayList stores elements in an array: index access is O(1), but inserting or removing in the middle is O(n). LinkedList uses linked nodes: inserting or removing is O(1) once you’re at the position (with an iterator), but reaching an index is O(n). In practice, ArrayList wins almost every time.

  5. What’s the difference between an interface and an abstract class?

    An interface defines a contract: abstract methods and, since Java 8, default and static methods, but no state (only constants). A class can implement several interfaces. An abstract class can have fields, constructors and methods with logic, but a class can extend only one.

  6. What are generics for?

    They let you parameterize types, like List<String>, so the compiler catches type errors and you don’t need casts. Type information is erased at compile time (type erasure): at runtime, List<String> and List<Integer> are the same class.

  7. What does the garbage collector do?

    It automatically frees the memory of objects that are no longer reachable from any live reference. It doesn’t guarantee when it runs (System.gc() is only a hint), so don’t rely on finalize(), which is deprecated anyway: use try-with-resources to close resources.

  8. What’s the difference between checked and unchecked exceptions?

    Checked exceptions, like IOException, must be caught with try/catch or declared with throws, or the code won’t compile. Unchecked exceptions extend RuntimeException (like NullPointerException), usually signal programming errors and don’t have to be declared.

  9. Why is String immutable?

    For security and efficiency: a validated value (a path, a URL) can’t change afterwards, it can be shared between threads without synchronization, and literals are reused from the string pool. Every “modification” creates a new String, so use StringBuilder to concatenate in a loop.

  10. What is a stream (java.util.stream)?

    A pipeline of declarative operations over data from a collection or another source: filter, map, reduce, collect… Intermediate operations are lazy and only run when a terminal operation is reached. A stream doesn’t modify its source and can only be traversed once.

Code questions: what does it print?

Many interviews show you a short snippet and ask you to predict the result and explain why. Try to answer before opening the solution.

  1. Comparing Strings with ==

    What does this code print?

    String a = "hello";
    String b = new String("hello");
    System.out.println(a == b);
    System.out.println(a.equals(b));
    Show answer

    Output

    false
    true

    == compares references: new String creates a different object, so a == b is false. equals() compares content and returns true. Always use equals() to compare strings.

  2. Removing inside a for-each

    What happens when this code runs?

    List<Integer> nums = new ArrayList<>(List.of(1, 2, 3));
    for (Integer n : nums) {
        if (n == 1) nums.remove(n);
    }
    System.out.println(nums);
    Show answer

    Output

    Exception in thread "main" java.util.ConcurrentModificationException

    Modifying the list while a for-each iterates over it throws ConcurrentModificationException on the next step, so the println never runs. Use nums.removeIf(n -> n == 1) or an Iterator with remove().

  3. The Integer cache

    What does this code print?

    Integer x = 127, y = 127;
    Integer p = 128, q = 128;
    System.out.println(x == y);
    System.out.println(p == q);
    Show answer

    Output

    true
    false

    By default, Java reuses Integer objects from -128 to 127: x and y are the same object. With 128, different objects are created and == compares references. Compare Integer values with equals().

Syntax, the 3D SyntaxQuest mascot

Practice with a mock interview

Knowing the answer isn’t enough: you have to explain it calmly in front of someone. In SyntaxQuest, Syntax plays the recruiter on a video call, asks you Java questions for the role and your level (junior, mid-level or senior), grades the content of your answers and gives you feedback on your eye contact, pace and filler words. At the end, Syntax tells you whether you’d be hired.

Included in Pro. Nothing is recorded: the camera is analyzed on your iPhone.

Java interview FAQ

What do they ask in a junior Java technical interview?

Mostly fundamentals: object-oriented programming (inheritance, interfaces, polymorphism), the difference between == and equals(), collections like List, Set and Map, exceptions and Strings. There’s usually a short coding exercise or a “what does this print?” question too.

And in a mid-level or senior Java interview?

Beyond the fundamentals, expect concurrency (threads, ExecutorService, synchronization), how HashMap works internally, JVM memory and frameworks like Spring. The definition matters less than explaining when you’d use each option and why.

Which Java version should I know?

A recent LTS release, such as Java 17, 21 or 25, and what they added to the language: var, records, text blocks, switch expressions, pattern matching and virtual threads (Java 21). Many companies still run Java 8 or 11, so it also helps to know what changed since then.

How do I prepare for a Java interview?

Review the fundamentals, solve short exercises and, above all, answer out loud: explaining an idea clearly is harder than recognizing it. In SyntaxQuest you can review with the free Java course and do video-call mock interviews with Syntax, included in Pro.

Does the mock interview record my camera?

No. Nothing is recorded: the camera is analyzed on your iPhone to give you feedback on eye contact, and Apple’s speech recognition transcribes your voice. Syntax only gets the text of your answer.