About this question set

These ten questions come from real Java interviews at companies ranging from large banks to small startups. They cover the topics interviewers most frequently probe: the JVM internals, object equality, immutability, the abstract class versus interface distinction, the Java Memory Model, the collections hierarchy, autoboxing, functional interfaces, garbage collection, and exception handling syntax. If you can answer all ten confidently and correctly, you are likely to pass the technical screen at most companies hiring for a Java backend role.

Each answer is technically correct but concise — one paragraph per question. In a real interview you should be prepared to go deeper on any of these. An interviewer who asks “Why is String immutable?” will often follow up with “And what is the string pool?” or “What would happen if String were mutable?” Treat each answer below as the opening of a conversation, not the end of one.

For each question, we have linked the relevant tutorial where you can read a much longer treatment of the topic. Interviewers love to ask follow-up questions, and reading the tutorial deeply is the best preparation for them. If you find you cannot answer a question without looking, mark it and come back to it the next day — the second exposure is what cements the answer in memory.

How to use this page

Try to answer each question out loud before clicking to reveal the answer. Verbalising your answer is a skill in itself — many candidates know the material but freeze when asked to speak it.

The ten questions

What is the JVM, JRE and JDK?

The JVM (Java Virtual Machine) runs Java bytecode on the host machine. The JRE (Java Runtime Environment) is the JVM plus core libraries needed to run Java programs. The JDK (Java Development Kit) is the JRE plus development tools such as the javac compiler, javadoc, and jdb debugger. To write Java you install the JDK; to run a compiled application the JRE is enough.

What is the difference between == and .equals()?

== compares references for objects and values for primitives. .equals() compares logical content. For String literals, the JVM may intern them so == sometimes works, but you should never rely on this. Always use .equals() for content comparison and override it in your own classes.

Why is String immutable in Java?

Immutability gives four benefits: thread safety without synchronisation, safe sharing (the JVM can pool literals in the string pool), safe use as keys in HashMaps, and security (a class loader or DB connection URL cannot be changed after construction). Each “modification” returns a new String.

What is the difference between an abstract class and an interface?

An abstract class can have fields, constructors, and method bodies, and a class can extend only one. An interface historically had only abstract methods, and a class can implement many. Since Java 8, interfaces can have default and static methods, and since Java 9, private methods. Use an abstract class when classes share state or constructors; use an interface to define a capability.

What is the Java Memory Model?

The JMM defines how threads interact through memory: visibility, ordering and atomicity. It guarantees that volatile reads see the latest write, that synchronized blocks establish a happens-before relationship, and that certain actions (thread start, join, final field writes) imply visibility. Understanding the JMM is essential to write correct concurrent code.

Explain the Collections hierarchy.

At the top is Collection<E>, extended by List (ordered, allows duplicates: ArrayList, LinkedList), Set (no duplicates: HashSet, TreeSet), Queue / Deque (ArrayDeque, PriorityQueue). Separately, Map<K,V> is not a Collection but is part of the framework (HashMap, TreeMap, LinkedHashMap).

What is autoboxing and unboxing?

Autoboxing converts a primitive to its wrapper class automatically (int → Integer); unboxing does the reverse. It works in assignments, method calls and generics. Beware of NullPointerException when unboxing a null wrapper and unintended object creation in tight loops.

What is a functional interface?

An interface with exactly one abstract method (e.g. Comparator, Runnable, Predicate). The @FunctionalInterface annotation is optional but makes the compiler check the rule. They are the target type for lambda expressions.

How does garbage collection work in Java?

The JVM divides the heap into young (Eden + 2 Survivor) and old generations. New objects go to Eden; surviving minor GCs move to Survivor and then to the old generation. Major GCs clean the old generation. Modern collectors include G1 (default in JDK 9+), ZGC and Shenandoah. You hint the GC via System.gc(), but it is not guaranteed to run.

What is the difference between throw and throws?

throw explicitly throws an exception object: throw new IllegalArgumentException(…). throws declares that a method may throw checked exceptions: void read() throws IOException. throw is a statement; throws is a clause in the method signature.

A two-week study plan

If you have a Java interview in two weeks and want to use this page as your primary study resource, here is a structured plan. It assumes you have already worked through the beginner and intermediate tutorials and have about two hours a day to study.

  1. Days 1–2. Re-read the Introduction and Syntax tutorials. Make sure you can write a Hello World from memory and explain what the public static void main signature means line by line.
  2. Days 3–4. Study the Classes & Objects, Inheritance, and Polymorphism tutorials in depth. Questions 4 and 6 below are about these topics.
  3. Days 5–6. Read the Exception Handling tutorial. Question 10 below covers throw versus throws; you should also be able to discuss checked versus unchecked exceptions and the try-with-resources pattern.
  4. Days 7–8. Work through the ArrayList and HashMap tutorials. Question 6 covers the collections hierarchy; you should be able to draw it on a whiteboard.
  5. Day 9. Read the Strings tutorial. Questions 2 and 3 below are about String equality and immutability.
  6. Day 10. Study the Lambda Expressions tutorial. Question 8 is on functional interfaces.
  7. Day 11. Skim the Multithreading tutorial. Question 5 covers the Java Memory Model; you should be able to explain volatile, synchronized, and the happens-before relationship.
  8. Day 12. Read about garbage collection. Question 9 covers the heap generations and the major collectors (G1, ZGC, Shenandoah).
  9. Days 13–14. Practise answering all ten questions out loud. Time yourself: aim for under ninety seconds per answer. Record yourself and listen back. The awkward pauses you hear are the parts to re-rehearse.

General interview tips

Knowing the answers is necessary but not sufficient. How you deliver them matters. Below are five tips that consistently separate strong candidates from average ones, regardless of the specific question being asked.

  • Think out loud. Interviewers want to see your reasoning. If you go silent for thirty seconds while thinking, they have no signal. Narrate your thought process: “I would start by checking whether the input is null, then I would iterate over the list, and for each element I would…” Even an imperfect narration is better than silence.
  • Ask clarifying questions. Many interview questions are deliberately vague. “Can the input contain negative numbers?”, “Is the list sorted?”, “Should I optimise for time or space?” are all reasonable questions that show engineering judgement.
  • Admit when you do not know. Saying “I’m not certain, but here’s how I would find out” is far better than bluffing. Interviewers can tell when you are making things up, and they will not penalise honesty.
  • Write clean code. If the interview involves writing code on a whiteboard or shared editor, name variables clearly, handle edge cases, and ask whether you should add tests. Boilerplate like public static void main(String[] args) can usually be skipped — ask the interviewer.
  • Have questions ready for the interviewer. “What is your build process?”, “How do you handle code review?”, “What is the most interesting bug you have shipped recently?” all show genuine interest and give you signal about whether you want to work there.

Beyond these ten questions

This page covers ten questions because ten is a useful number — enough to probe the major topic areas without overwhelming. Real Java interviews often include fifteen to twenty-five technical questions, plus one or two coding exercises and a system-design conversation. To prepare beyond these ten, we recommend:

  • Reading the reference page for a quick lookup of types, keywords, and operator precedence.
  • Building two or three of the projects so you have something concrete to talk about in a “tell me about a project you worked on” question.
  • Reading Effective Java by Joshua Bloch — the single best book on idiomatic Java ever written, and a frequent source of interview questions at senior levels.
  • Practising coding exercises on LeetCode or HackerRank, focusing on array, string, and tree problems — the most common data-structure interview questions.

If you have a specific Java interview topic you would like us to add to this page, please contact us — reader requests drive our editorial calendar.