
Your first Java developer interview can feel intimidating. Interviewers ask about concepts you may have learned months ago, and the pressure makes everything harder to recall.
This guide covers ten questions that appear frequently in entry-level Java interviews. For each question, you get the answer plus context on why interviewers ask it and what they’re really looking for.
1. What is the difference between JDK, JRE, and JVM?
This question tests whether you understand Java’s architecture beyond just writing code.
JVM (Java Virtual Machine) executes Java bytecode. It’s the layer that makes Java platform-independent. Your compiled code runs on the JVM, and the JVM handles translation to whatever operating system you’re using.
JRE (Java Runtime Environment) includes the JVM plus the core libraries needed to run Java programs. If you only need to run Java applications (not develop them), the JRE is sufficient.
JDK (Java Development Kit) includes the JRE plus development tools like the compiler (javac), debugger, and documentation generator. You need the JDK to write and compile Java code.
A simple way to remember: JDK contains JRE, which contains JVM. Developers need the JDK. End users only need the JRE.
2. What is object-oriented programming, and what are its main principles?
Interviewers ask this to confirm you understand Java’s fundamental paradigm, not just its syntax.
Object-oriented programming (OOP) organizes code around objects that contain both data and behavior. Java is built entirely on this model.
The four main principles:
Encapsulation bundles data and the methods that operate on that data within a single unit (a class). It also restricts direct access to some components, typically using private fields with public getter/setter methods.
Inheritance lets a class inherit properties and methods from another class. A Dog class might extend an Animal class, gaining all of Animal’s characteristics while adding its own.
Polymorphism allows objects of different classes to be treated as objects of a common parent class. A method that accepts an Animal parameter can work with Dog, Cat, or any other Animal subclass.
Abstraction hides complex implementation details and exposes only what’s necessary. You can drive a car without understanding the combustion engine. Similarly, you can use a Java class without knowing its internal workings.
3. What is the difference between == and .equals() in Java?
This trips up many beginners, and interviewers know it.
== compares references. It checks whether two variables point to the exact same object in memory.
.equals() compares values. It checks whether two objects are meaningfully equivalent, even if they’re stored in different memory locations.
String a = new String("hello");
String b = new String("hello");
System.out.println(a == b); // false (different objects)
System.out.println(a.equals(b)); // true (same content)
For primitive types (int, double, boolean), use == because there are no objects involved. For objects, almost always use .equals() when comparing values.
One exception: comparing to null. Use == null because calling .equals() on null throws an exception.
4. What is the difference between an abstract class and an interface?
This question checks your understanding of Java’s type system and design patterns.
An abstract class can have both abstract methods (without implementation) and concrete methods (with implementation). A class can extend only one abstract class. Abstract classes can have constructors, instance variables, and any access modifier.
An interface traditionally defined only method signatures without implementation. Since Java 8, interfaces can include default and static methods. A class can implement multiple interfaces. All interface methods are implicitly public.
When to use each:
Use an abstract class when classes share common code and state. A Vehicle abstract class might include shared fields like speed and methods like accelerate().
Use an interface when unrelated classes need to guarantee certain behaviors. Both a Bird class and an Airplane class might implement a Flyable interface, even though they share no common ancestor.
// Abstract class
abstract class Animal {
String name;
abstract void makeSound();
void sleep() {
System.out.println(name + " is sleeping");
}
}
// Interface
interface Swimmable {
void swim();
}
5. What is the difference between ArrayList and LinkedList?
This tests your knowledge of data structures and when to use each.
ArrayList stores elements in a dynamic array. Accessing elements by index is fast (O(1)). Adding or removing elements in the middle is slow because elements must shift.
LinkedList stores elements as nodes with pointers to the next and previous nodes. Accessing elements by index is slow (O(n)) because you traverse from the start. Adding or removing elements is fast if you already have a reference to the position.
In practice, ArrayList is the better default choice for most situations. Its cache-friendly memory layout makes it faster for iteration, and random access is common. LinkedList makes sense when you frequently add or remove elements from the beginning or middle of the list and rarely access elements by index.
6. What is exception handling in Java?
Exceptions represent errors or unexpected conditions during program execution. Java’s exception handling lets you manage these situations gracefully instead of crashing.
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Cannot divide by zero");
} finally {
System.out.println("This always runs");
}
try contains code that might throw an exception. catch handles specific exception types. finally runs regardless of whether an exception occurred, often used for cleanup like closing files.
Java has two categories of exceptions:
Checked exceptions must be either caught or declared in the method signature. The compiler enforces this. Examples: IOException, SQLException.
Unchecked exceptions (RuntimeException and its subclasses) don’t require explicit handling. Examples: NullPointerException, ArrayIndexOutOfBoundsException.
Interviewers often follow up by asking about creating custom exceptions or best practices for exception handling.
7. What is the difference between String, StringBuilder, and StringBuffer?
String is immutable. Once created, it cannot be changed. Operations like concatenation create new String objects.
String s = "Hello";
s = s + " World"; // Creates a new String object
StringBuilder is mutable. You can modify its contents without creating new objects. It’s faster for building strings through multiple operations but is not thread-safe.
StringBuilder sb = new StringBuilder("Hello");
sb.append(" World"); // Modifies the same object
StringBuffer is like StringBuilder but thread-safe. The synchronization adds overhead, so use StringBuilder unless multiple threads access the same instance.
For simple string operations, use String. For building strings in loops or with many concatenations, use StringBuilder.
8. What is the static keyword in Java?
The static keyword means something belongs to the class itself rather than to instances of the class.
Static variables are shared across all instances. If you have a counter that tracks how many objects have been created, that’s a good use for static.
Static methods can be called without creating an object. Math.sqrt() is static because you don’t need a Math instance to calculate a square root.
public class Counter {
static int count = 0;
public Counter() {
count++;
}
public static int getCount() {
return count;
}
}
// Usage
Counter c1 = new Counter();
Counter c2 = new Counter();
System.out.println(Counter.getCount()); // Prints 2
Static methods cannot access instance variables directly because they exist at the class level, not the object level.
9. What is method overloading vs method overriding?
Overloading means multiple methods in the same class share a name but have different parameters. The compiler determines which version to call based on the arguments.
public int add(int a, int b) {
return a + b;
}
public double add(double a, double b) {
return a + b;
}
Overriding means a subclass provides its own implementation of a method defined in its parent class. The method signature must match exactly.
class Animal {
void makeSound() {
System.out.println("Some sound");
}
}
class Dog extends Animal {
@Override
void makeSound() {
System.out.println("Bark");
}
}
Overloading happens at compile time (compile-time polymorphism). Overriding happens at runtime (runtime polymorphism).
10. What is garbage collection in Java?
Garbage collection automatically frees memory by removing objects that are no longer reachable. You don’t manually allocate or deallocate memory like in C or C++.
An object becomes eligible for garbage collection when no references point to it. The JVM’s garbage collector runs periodically to identify and remove these objects.
Object obj = new Object();
obj = null; // The original Object is now eligible for garbage collection
You can suggest garbage collection by calling System.gc(), but the JVM decides when to actually run it. You cannot force immediate garbage collection.
Common follow-up questions include explaining different garbage collector types (G1, ZGC, Parallel) or discussing memory leaks in Java.
Tips for the Interview
Knowing the answers is only part of success. Keep these points in mind:
Explain your reasoning. Interviewers want to see how you think, not just whether you memorized definitions. Talk through your thought process.
Admit when you don’t know. Guessing badly is worse than saying “I’m not sure, but I’d look that up.” You can also reason out loud: “I haven’t used that specifically, but based on what I know about similar concepts…”
Ask clarifying questions. If a question is ambiguous, ask for clarification. This shows you think carefully rather than jumping to assumptions.
Practice coding by hand. Some interviews involve whiteboard coding. Practice writing code on paper or in a plain text editor without auto-complete.
Related: What is Java? A Beginner’s Guide | How to Install Java
Sources
- Oracle. “The Java Tutorials.” docs.oracle.com
- Bloch, Joshua. “Effective Java.” 3rd Edition. Addison-Wesley, 2018.
- Baeldung. “Java Interview Questions.” baeldung.com


