← Back to Home

Java Interview Questions — What Senior Engineers Need to Know

Java interviews at the senior level go far beyond syntax. Interviewers expect you to reason about JVM internals, garbage collection trade-offs, the Java Memory Model, and how the collections framework actually works under the hood. Surface-level answers about “HashMap uses hashing” won’t cut it.

These 60 questions cover the concepts that consistently appear in senior Java interviews at top companies: concurrency primitives, class loading, generics and type erasure, functional interfaces, and modern Java features from records to virtual threads. Each question is designed to test whether you can explain why, not just what.

All 60 Questions

JVM vs JRE vs JDKEntry
What are the differences between JVM, JRE, and JDK?

The JVM, JRE, and JDK are nested components of the Java platform, each building on the previous. Understanding their boundaries is essential for knowing what to install in different contexts.

Read full answer →
Java Platform IndependenceEntry
Why is Java a platform-independent language?

Java's platform independence is summarized by the principle "Write Once, Run Anywhere" (WORA). The mechanism has two steps: compilation to an intermediate representation (bytecode), and execution of that bytecode by a platform-specific JVM.

Read full answer →
How JVM WorksMid
How does the JVM work?

The JVM processes Java programs through four major subsystems: the class loader, the bytecode verifier, the execution engine, and the runtime memory areas.

Read full answer →
Main Features of JavaEntry
What are the main features of Java?

Java is defined by a set of deliberate design choices that have kept it relevant for three decades. Understanding these features at depth — not just reciting the list — is what distinguishes strong candidates.

Read full answer →
public static void mainEntry
What is the significance of 'public static void main(String[] args)' in Java?

The `public static void main(String[] args)` signature is Java's program entry point — the method the JVM calls to start execution. Every keyword in the signature is load-bearing.

Read full answer →
String Constant PoolMid
What is the String Constant Pool in Java?

The String Constant Pool (also called String Intern Pool) is a special memory region inside the JVM's heap where string literals are stored and reused. When you write a string literal like `String s = "hello"`, the JVM checks the pool first. If "hello" already exists, it returns the same referenc…

Read full answer →
String ImmutabilityMid
Why are Strings immutable in Java?

String immutability in Java means that once a `String` object is created, its character sequence cannot be changed. Any operation that appears to modify a string — concatenation, `replace()`, `substring()` — actually creates and returns a new `String` object. The original remains unchanged.

Read full answer →
StringBuffer vs StringBuilderEntry
What is the difference between StringBuffer and StringBuilder?

Both `StringBuffer` and `StringBuilder` are mutable character sequences used when you need to build or modify strings without creating multiple intermediate `String` objects. They share the same API — `append()`, `insert()`, `delete()`, `reverse()`, `toString()` — and both inherit from `AbstractS…

Read full answer →
hashCode() and equals()Mid
What is the importance of hashCode() and equals() methods in Java?

The `equals()` method defines logical equality between objects — whether two instances should be considered the same value. The `hashCode()` method returns an integer used by hash-based data structures to bucket objects efficiently. They are defined on `Object` and meant to be overridden together.

Read full answer →
Checked vs Unchecked ExceptionsEntry
What is the difference between checked and unchecked exceptions in Java?

In Java, exceptions are divided into checked and unchecked. The distinction determines whether the compiler forces calling code to handle or declare the exception.

Read full answer →
Wrapper ClassesEntry
What are wrapper classes in Java?

Java has eight primitive types — `byte`, `short`, `int`, `long`, `float`, `double`, `char`, and `boolean` — that are not objects and cannot be used where `Object` references are required. Wrapper classes provide an object counterpart for each: `Byte`, `Short`, `Integer`, `Long`, `Float`, `Double`…

Read full answer →
Why Java is Not Pure OOPEntry
Why is Java not considered a pure object-oriented programming language?

A pure object-oriented language treats everything as an object and only allows object-based operations. Java falls short of this standard primarily because of primitive types and static members.

Read full answer →
Abstract Class vs InterfaceMid
What is the difference between an abstract class and an interface in Java?

Abstract classes and interfaces both enable abstraction, but they serve different design purposes.

Read full answer →
Marker InterfacesMid
What are marker interfaces in Java?

A marker interface is an interface that declares no methods or fields. Its sole purpose is to tag a class as possessing some property, which the JVM, runtime, or framework can then detect via `instanceof` checks. The interface conveys metadata rather than defining a behavioral contract.

Read full answer →
Java Collections FrameworkEntry
What are collections in Java?

The Java Collections Framework (JCF) is a unified architecture for representing and manipulating groups of objects. It consists of interfaces that define abstract data types, concrete implementations of those interfaces, and algorithms (utility methods in `Collections` and `Arrays`) that operate …

Read full answer →
ArrayList vs VectorEntry
What are the differences between ArrayList and Vector?

Both `ArrayList` and `Vector` are `List` implementations backed by a resizable array, and they share the same core operations. The primary difference is synchronization.

Read full answer →
finalize() MethodMid
What is the finalize() method in Java?

`finalize()` is a method defined on `java.lang.Object` that the garbage collector is permitted to call on an object before reclaiming its memory, giving the object a chance to release native resources or perform cleanup. It was part of Java from version 1.0.

Read full answer →
Comparable vs ComparatorMid
What is the difference between the Comparable and Comparator interfaces?

`Comparable` and `Comparator` are both interfaces used for ordering objects, but they serve different design purposes.

Read full answer →
Inner ClassesMid
What is an inner class in Java?

An inner class is a class defined within the body of another class or interface. Java has four distinct kinds, each with different scoping and access rules.

Read full answer →
final vs finally vs finalize()Entry
What is the difference between final, finally, and finalize() in Java?

These three keywords sound similar but serve completely different purposes.

Read full answer →
== vs equals()Entry
What is the difference between '==' and the equals() method in Java?

In Java, `==` and `equals()` test different things and the distinction is fundamental to writing correct code.

Read full answer →
Method Overloading vs OverridingEntry
What is method overloading and method overriding in Java?

Method overloading and method overriding are both forms of polymorphism but operate at different phases and on different axes.

Read full answer →
HashMap vs HashtableMid
What is the difference between HashMap and Hashtable?

HashMap and Hashtable both implement the Map interface and store key-value pairs using a hash table, but they differ in synchronization, null handling, and historical context.

Read full answer →
ArrayList vs LinkedListMid
What is the difference between ArrayList and LinkedList?

ArrayList and LinkedList are both implementations of the List interface in Java, but they are backed by fundamentally different data structures.

Read full answer →
Java Reflection APISenior
What is the Java Reflection API?

The Java Reflection API, in the `java.lang.reflect` package, enables a program to examine and modify its own structure and behavior at runtime. It allows code to inspect class metadata, invoke methods, access fields, and instantiate objects using symbolic names rather than compile-time references.

Read full answer →
JVM Memory AreasSenior
What are the different memory areas allocated by the JVM?

The JVM divides memory into several runtime data areas, each with a specific purpose and lifecycle.

Read full answer →
throw vs throwsEntry
What is the difference between throw and throws in Java?

`throw` and `throws` are both part of Java's exception mechanism but operate at different points and serve different purposes.

Read full answer →
Singleton Pattern in JavaMid
What is a Singleton class and how do you create one in Java?

The Singleton pattern ensures that a class has exactly one instance throughout the application's lifetime and provides a global point of access to it. It is one of the Gang of Four creational patterns.

Read full answer →
Java 8 Stream APIMid
What are the main features of the Java 8 Stream API?

The Stream API, introduced in Java 8 in `java.util.stream`, enables functional-style processing of sequences of elements through declarative, composable pipelines. A stream is not a data structure — it does not store data. It conveys elements from a source (collection, array, generator function, …

Read full answer →
Fail-fast vs Fail-safe IteratorsMid
What is the difference between fail-fast and fail-safe iterators?

The terms fail-fast and fail-safe describe how iterators behave when the underlying collection is modified during iteration.

Read full answer →
Process vs Thread in JavaMid
What is the difference between a process and a thread in Java?

A process and a thread are both units of execution, but they operate at different levels of the operating system and have fundamentally different resource isolation models.

Read full answer →
Creating Threads in JavaEntry
What are the different ways to create a thread in Java?

Java provides several mechanisms to create and run threads, each with different tradeoffs.

Read full answer →
Synchronization in JavaMid
What is synchronization in Java?

Synchronization in Java is the mechanism by which the JVM controls access to shared resources by multiple threads, preventing data races and ensuring memory visibility.

Read full answer →
Deadlock in JavaSenior
What is deadlock in Java and how can it be avoided?

A deadlock is a situation where two or more threads are permanently blocked, each waiting to acquire a lock held by another thread in the cycle. No thread can proceed, and the application hangs indefinitely without throwing an exception.

Read full answer →
volatile KeywordSenior
What is the volatile keyword in Java?

The volatile keyword in Java is a field modifier that guarantees visibility and ordering guarantees for a variable across multiple threads. Without volatile, each thread may cache a variable's value in its CPU register or L1/L2 cache, meaning writes by one thread are not necessarily visible to ot…

Read full answer →
transient KeywordMid
What is the transient keyword in Java?

The transient keyword in Java is a field modifier that instructs the serialization mechanism to skip a field when converting an object to a byte stream. When an object implementing Serializable is serialized, every non-transient field is written to the output. A transient field is omitted entirel…

Read full answer →
Serialization and DeserializationMid
What is serialization and deserialization in Java?

Serialization is the process of converting a Java object's state into a byte stream so it can be persisted to disk, stored in a database, or transmitted over a network. Deserialization is the inverse: reconstructing an object from that byte stream. Together, they enable objects to outlive the JVM…

Read full answer →
Functional InterfacesMid
What are functional interfaces in Java?

A functional interface in Java is an interface that declares exactly one abstract method. This single-abstract-method (SAM) constraint makes the interface usable as the target type for a lambda expression or method reference, enabling functional-style programming introduced in Java 8.

Read full answer →
Lambda ExpressionsMid
What are lambda expressions in Java?

Lambda expressions, introduced in Java 8, are anonymous function literals that implement a functional interface inline without the boilerplate of an anonymous inner class. The syntax is: (parameters) -> expression or (parameters) -> { statements; }. When the parameter type can be inferred from co…

Read full answer →
Collection vs CollectionsEntry
What is the difference between Collection and Collections in Java?

Collection (singular, no 's') is the root interface in the Java Collections Framework hierarchy. It is located in java.util and declares the fundamental contract all collection types must fulfill: add, remove, contains, size, iterator, and similar methods. Interfaces like List, Set, and Queue ext…

Read full answer →
Set vs ListEntry
What is the difference between Set and List in Java?

List and Set are both sub-interfaces of Collection but with fundamentally different contracts around ordering and uniqueness.

Read full answer →
HashSet vs TreeSetMid
What is the difference between HashSet and TreeSet?

HashSet and TreeSet are both implementations of the Set interface in Java, but they differ fundamentally in their underlying data structures, performance characteristics, and ordering guarantees.

Read full answer →
Diamond Problem in JavaSenior
What is the diamond problem in Java?

The diamond problem is a classic multiple inheritance ambiguity that arises when a class inherits from two parents that both provide a concrete implementation of the same method, and both parents share a common superclass or interface defining that method. The shape forms a diamond in the inherit…

Read full answer →
Dependency Injection in JavaMid
What is dependency injection in Java?

Dependency injection (DI) is a design pattern implementing the Inversion of Control (IoC) principle. Instead of a class creating its own dependencies with new, those dependencies are provided (injected) from outside — by a framework, factory, or test harness. The class declares what it needs; som…

Read full answer →
Shallow Copy vs Deep Copy in JavaMid
What is the difference between shallow copy and deep copy in Java?

A shallow copy creates a new object and copies the top-level field values from the original. For primitive fields, this means the value itself is copied. For reference-type fields, only the reference (memory address) is copied — both the original and the copy point to the same nested objects. Mod…

Read full answer →
Design Patterns in JavaMid
What are design patterns in Java?

Design patterns are proven, reusable solutions to commonly recurring software design problems. They are not code libraries or algorithms — they are templates describing how to structure classes and objects to solve a specific type of design challenge. The term was popularized by the Gang of Four …

Read full answer →
Factory Design PatternMid
What is the Factory design pattern?

The Factory pattern encapsulates object creation behind a method or class, so callers request objects by type or configuration without depending on concrete class names or constructors. This decouples the consuming code from the instantiation details, making the system easier to extend and test.

Read full answer →
Builder Design PatternMid
What is the Builder design pattern?

The Builder pattern separates the construction of a complex object from its representation, allowing the same construction process to produce different configurations. It is most valuable when an object requires many parameters, some of which are optional, because the alternative — telescoping co…

Read full answer →
Heap vs Stack MemoryMid
What is the difference between Heap and Stack memory in Java?

In Java, memory is divided into two primary regions: the stack and the heap.

Read full answer →
Garbage Collection in JavaMid
What is garbage collection in Java?

Garbage collection (GC) in Java is the automatic process of identifying objects on the heap that are no longer reachable from any GC root (active threads, static fields, local variables on stack) and reclaiming their memory. The developer is freed from manual memory management, eliminating use-af…

Read full answer →
Types of Garbage CollectorsSenior
What are the different types of garbage collectors in Java?

Java provides several garbage collector implementations, each representing a different set of tradeoffs between throughput, latency, and resource usage.

Read full answer →
wait() vs sleep()Mid
What is the difference between wait() and sleep() in Java?

wait() and sleep() both pause thread execution, but they serve entirely different purposes and behave very differently with respect to locks.

Read full answer →
notify() vs notifyAll()Senior
What is the difference between notify() and notifyAll() in Java?

Both notify() and notifyAll() are Object methods that wake threads suspended in wait() on the same object's monitor. The critical difference is how many threads they wake.

Read full answer →
Immutable Class in JavaMid
What is an immutable class and how do you create one?

An immutable class is a class whose instances cannot be modified after construction. Once created, an immutable object's state is fixed for its lifetime. java.lang.String, Integer, and the other wrapper types are the canonical examples.

Read full answer →
String vs StringBuilder vs StringBufferEntry
What is the difference between String, StringBuilder, and StringBuffer?

String, StringBuilder, and StringBuffer all represent character sequences in Java but differ critically in mutability and thread safety.

Read full answer →
Static vs Instance VariablesEntry
What is the difference between static and instance variables in Java?

Static variables (also called class variables) are declared with the static keyword and belong to the class itself rather than any particular object. There is exactly one copy of a static variable in memory, shared by all instances of the class. They are initialized when the class is first loaded…

Read full answer →
super KeywordEntry
What is the purpose of the super keyword in Java?

The super keyword in Java is a reference to the parent (superclass) of the current class. It has three primary uses: calling a parent class constructor, calling an overridden parent class method, and accessing a parent class field hidden by a subclass field of the same name.

Read full answer →
this KeywordEntry
What is the purpose of the this keyword in Java?

The this keyword in Java is an implicit reference to the current object — the instance on which the current method or constructor is executing. It has four main uses.

Read full answer →
Java GenericsMid
What are generics in Java?

Java generics, introduced in Java 5, allow classes, interfaces, and methods to be parameterized by type. Instead of writing a container that holds Object and requires manual casting, you declare List<String>, and the compiler enforces that only String values are added and returns String values wi…

Read full answer →
Type Erasure in GenericsSenior
What is type erasure in Java generics?

Type erasure is the mechanism by which the Java compiler removes all generic type parameters from the bytecode it produces. The resulting .class file contains no information about the specific type arguments used — only the erasure (the raw type or the bound) remains. This was a deliberate compat…

Read full answer →

How to Prepare

Focus on understanding concepts deeply enough to explain them in your own words. For each topic, practice articulating the trade-offs and real-world applications — interviewers care about practical judgment, not textbook definitions.

Related Topics

  • CS Fundamentals Interview Questions
  • Frameworks Interview Questions
  • Design Principles Interview Questions
  • Technical Interview Practice

Test Your Knowledge

Take a free AI-graded assessment across multiple domains. No signup required.

Start Free Assessment
GrindQuestionsAITechnical interview assessment
TermsPrivacyAbout