Java Interview Questions
1,715 questions from 600 real interviews · April 2026
Every question ranked by how often it actually gets asked. Sourced from 600 public Java interviews on YouTube using voice transcription and frequency analysis. The ones at the top are the ones you will almost certainly face.
Source: 600 public interviews on YouTube
Most Asked
Tell me about yourself
Structure your answer: start with your current role and tech stack, mention 1-2 key accomplishments relevant to the position, then explain why you are interested in this role. Keep it under 2 minutes. Focus on Java-specific experience like frameworks you have used, systems you have built, and problems you have solved.
What is OOP
OOP encapsulates data and behavior using inheritance, polymorphism, encapsulation, and abstraction to build maintainable, reusable code.
class Animal {
void sound() {
}
}
class Dog extends Animal {
@Override void sound() {
System.out.println("Bark");
}
}
Dog dog = new Dog();
dog.sound();What is the difference between Checked and UNCHECked exceptions
Checked exceptions must be caught or declared (IOException), while unchecked exceptions extend RuntimeException and represent programming errors that don't require declaration.
try {
int x = Integer.parseInt("abc");
}
catch (NumberFormatException e) {
}
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
}What methods in the Object class do you know
Key Object methods: equals(), hashCode(), toString(), clone(), wait(), notify(), notifyAll(), getClass(), finalize().
Object obj = new Object();
obj.hashCode();
obj.equals(new Object());
obj.getClass();
obj.toString();
obj.clone();Tell me about the hierarchy of exceptions
Throwable → Exception/Error; Exception → CheckedException/RuntimeException; RuntimeException → NullPointerException, IllegalArgumentException, etc.
try {
throw new RuntimeException("unchecked");
}
catch (Exception e) {
}
try {
throw new IOException("checked");
}
catch (IOException e) {
}What is Solid
SOLID: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion principles for maintainable design.
Tell me about the hierarchy of collections in Java
Collection → List (ArrayList, LinkedList), Set (HashSet, TreeSet), Queue; Map hierarchy separate (HashMap, TreeMap, ConcurrentHashMap).
Collection<Integer> col = Arrays.asList(1, 2, 3);
List<Integer> list = new ArrayList<>();
Set<Integer> set = new HashSet<>();
Map<String, Integer> map = new HashMap<>();What is the difference between the interface and the abstract class
Interfaces define contracts with abstract methods, supporting multiple inheritance; abstract classes provide partial implementation and state with single inheritance.
interface Drawable {
void draw();
}
abstract class Shape {
abstract void draw();
}
class Circle extends Shape implements Drawable {
@Override public void draw() {
}
}What is the difference between Linkedlist and Arraylist
ArrayList uses dynamic array (fast random access, slow insertion/deletion), LinkedList uses doubly-linked nodes (slow access, fast insertion/deletion at ends).
ArrayList<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
LinkedList<Integer> ll = new LinkedList<>();
ll.addFirst(1);
ll.addLast(2);Tell me about Hashcode and Equals Contract
hashCode() and equals() must be consistent: equal objects have same hashCode; used together in hashing structures like HashMap to determine bucket placement and collision resolution.
class Person {
@Override public int hashCode() {
return id;
}
@Override public boolean equals(Object o) {
return this.id == ((Person)o).id;
}
int id;
}What is the difference between a primitive and a reference type of data
Primitives (int, boolean) store values directly on stack; reference types (objects) store memory address on stack, actual data on heap.
int primitive = 5;
Integer reference = new Integer(5);
int[] arr = {
1, 2, 3
}
;
String str = "hello";
primitive = 10;
reference = null;How Hashmap is organized
HashMap uses array of buckets; hash function determines bucket index, collisions resolved via linked lists or red-black trees (Java 8+) when threshold exceeded.
HashMap<String, Integer> map = new HashMap<>();
map.put("a", 1);
map.put("b", 2);
Node node = map.getNode("a");
int index = hash("a") % capacity;What is you experience is in programming
Tailor your answer to the role. Mention years of experience, primary languages (emphasize Java), types of projects (web apps, microservices, APIs), and frameworks you have worked with (Spring, Hibernate). Give a concrete example of a system you built or a hard problem you solved. Avoid generic statements.
What do you know about Object class
Object is superclass of all Java classes; provides equals(), hashCode(), toString(), clone(), wait(), notify() methods; all classes inherit from Object.
class Demo extends Object {
public String toString() {
return "Demo";
}
public boolean equals(Object o) {
return super.equals(o);
}
public int hashCode() {
return super.hashCode();
}
}What are the principles of OOP
Encapsulation (data hiding), Abstraction (hide complexity), Inheritance (code reuse), Polymorphism (runtime behavior determination).
class Animal {
void sound() {
}
}
class Dog extends Animal {
void sound() {
System.out.println("Bark");
}
}
interface Pet {
void play();
}
class Cat implements Pet {
public void play() {
System.out.println("Play");
}
}Java Core
288 questionsWhat is the difference between Checked and UNCHECked exceptions
Checked exceptions must be caught or declared (IOException), while unchecked exceptions extend RuntimeException and represent programming errors that don't require declaration.
try {
int x = Integer.parseInt("abc");
}
catch (NumberFormatException e) {
}
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
}What methods in the Object class do you know
Key Object methods: equals(), hashCode(), toString(), clone(), wait(), notify(), notifyAll(), getClass(), finalize().
Object obj = new Object();
obj.hashCode();
obj.equals(new Object());
obj.getClass();
obj.toString();
obj.clone();Tell me about the hierarchy of exceptions
Throwable → Exception/Error; Exception → CheckedException/RuntimeException; RuntimeException → NullPointerException, IllegalArgumentException, etc.
try {
throw new RuntimeException("unchecked");
}
catch (Exception e) {
}
try {
throw new IOException("checked");
}
catch (IOException e) {
}Spring
153 questionsWhat Spring Scopes do you know
Singleton (one instance application-wide), Prototype (new per injection), Request (per HTTP request), Session (per user session), Application (application scope).
What is Bean
A Bean in Spring is a managed object created and maintained by the Spring IoC container with lifecycle methods and dependency injection capabilities.
What is the life cycle of Spring Beans
Spring Bean lifecycle: instantiation → property injection → BeanNameAware/BeanFactoryAware callbacks → BeanPostProcessor.postProcessBeforeInitialization → @PostConstruct/InitializingBean.afterPropertiesSet → BeanPostProcessor.postProcessAfterInitialization → ready for use → @PreDestroy/DisposableBean.destroy on shutdown.
Java Collections
114 questionsTell me about the hierarchy of collections in Java
Collection → List (ArrayList, LinkedList), Set (HashSet, TreeSet), Queue; Map hierarchy separate (HashMap, TreeMap, ConcurrentHashMap).
Collection<Integer> col = Arrays.asList(1, 2, 3);
List<Integer> list = new ArrayList<>();
Set<Integer> set = new HashSet<>();
Map<String, Integer> map = new HashMap<>();What is the difference between Linkedlist and Arraylist
ArrayList uses dynamic array (fast random access, slow insertion/deletion), LinkedList uses doubly-linked nodes (slow access, fast insertion/deletion at ends).
ArrayList<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
LinkedList<Integer> ll = new LinkedList<>();
ll.addFirst(1);
ll.addLast(2);How Hashmap is organized
HashMap uses array of buckets; hash function determines bucket index, collisions resolved via linked lists or red-black trees (Java 8+) when threshold exceeded.
HashMap<String, Integer> map = new HashMap<>();
map.put("a", 1);
map.put("b", 2);
Node node = map.getNode("a");
int index = hash("a") % capacity;Servlets
90 questionsWhat is a "deployment descriptor"
Deployment descriptor (web.xml) is an XML file that configures servlets, filters, listeners, security constraints, and other settings for a web application.
How container controls the life cycle of the Serlet, when and what methods are called
Container instantiates servlet (constructor), calls init(), then repeatedly calls service() for requests, and finally calls destroy() on shutdown.
Why do you need application servers if there are server containers
Application servers provide additional services beyond container functionality: connection pooling, transaction management, JMS messaging, clustering, security, and resource management.
Multithreading
76 questionsTell me about Deadlock
Deadlock occurs when threads circularly wait for locks held by others; prevent via lock ordering, timeouts, tryLock(), or ReentrantReadWriteLock patterns.
Object lock1 = new Object();
Object lock2 = new Object();
new Thread(() -> {
synchronized(lock1) {
synchronized(lock2) {
}
}
}
).start();
new Thread(() -> {
synchronized(lock2) {
synchronized(lock1) {
}
}
}
).start();What is executorservice
ExecutorService is a thread pool that manages a pool of threads for executing submitted tasks asynchronously. It abstracts away thread creation and lifecycle management, providing methods like submit(), execute(), and shutdown().
ExecutorService executor = Executors.newFixedThreadPool(2);
executor.submit(() -> System.out.println("Task 1"));
executor.submit(() -> System.out.println("Task 2"));
executor.shutdown();What is the idea of multi -seating
Multi-threading allows multiple threads to execute concurrently within a single process, enabling parallelism and responsive applications, though it requires careful synchronization to avoid race conditions.
synchronized void incrementCount() {
count++;
}
synchronized void decrementCount() {
count--;
}
volatile int sharedVar = 0;General
75 questionsTell me about yourself
Structure your answer: start with your current role and tech stack, mention 1-2 key accomplishments relevant to the position, then explain why you are interested in this role. Keep it under 2 minutes. Focus on Java-specific experience like frameworks you have used, systems you have built, and problems you have solved.
What is Solid
SOLID: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion principles for maintainable design.
What is you experience is in programming
Tailor your answer to the role. Mention years of experience, primary languages (emphasize Java), types of projects (web apps, microservices, APIs), and frameworks you have worked with (Spring, Hibernate). Give a concrete example of a system you built or a hard problem you solved. Avoid generic statements.
Databases
57 questionsWhat is ACID
ACID ensures reliable transactions: Atomicity (all-or-nothing), Consistency (valid state), Isolation (no interference), Durability (persistence after commit).
What is the normalization of databases
Database normalization organizes data into tables to reduce redundancy and dependency by applying rules like 1NF, 2NF, 3NF, ensuring data integrity and efficient queries.
What is the difference between SQL and NOSQL
SQL is relational (structured tables, ACID properties, complex joins), while NoSQL is non-relational (document/key-value stores, eventual consistency, horizontal scaling).
Patterns
48 questionsWhat design patterns do you know
Common patterns: Singleton, Factory, Strategy, Observer, Adapter, Decorator, Proxy, Builder, Template Method, and State.
class Singleton {
private static Singleton instance = new Singleton();
private Singleton() {
}
public static Singleton getInstance() {
return instance;
}
}
class Prototype implements Cloneable {
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}How Singleton differs from Prototype
Singleton creates one instance (lazy or eager initialization, thread-safe), Prototype creates copies of existing objects; Singleton manages instance count, Prototype manages object cloning.
class Singleton {
private static Singleton instance;
public static synchronized Singleton getInstance() {
if(instance == null) instance = new Singleton();
return instance;
}
}
Prototype p1 = new Prototype();
Prototype p2 = (Prototype) p1.clone();Why is singleon called antipattern
Singleton violates SOLID principles: tight coupling, hard to test (difficult to mock), breaks single responsibility, and creates global mutable state. It complicates dependency injection and multi-threaded scenarios.
class Singleton {
private static Singleton instance;
private Singleton() {
}
public static Singleton getInstance() {
if(instance == null) instance = new Singleton();
return instance;
}
}SQL
46 questionsFamiliar with SQL
Yes, proficient with SQL for queries, joins, subqueries, transactions, indexes, and optimization.
Are you familiar with SQL
Yes, proficient with SQL for DML/DDL operations, optimization, and query design.
What types of Join do you know
INNER JOIN returns matching rows from both tables; LEFT/RIGHT JOIN includes unmatched rows from one side; FULL OUTER JOIN includes all unmatched rows; CROSS JOIN produces Cartesian product.
Java 8
42 questionsWhat is Stream in Java?
Stream provides lazy, functional pipeline for processing collections; chains operations (map, filter, reduce) without modifying source, enabling parallel processing.
List<Integer> nums = Arrays.asList(1, 2, 3, 4, 5);
nums.stream().filter(n -> n > 2).map(n -> n * 2).forEach(System.out::println);What is a functional interface
Functional interface has exactly one abstract method, allowing lambda expression implementation; annotated with @FunctionalInterface (e.g., Comparator, Function).
@FunctionalInterface interface Calculator {
int calculate(int a, int b);
}
Calculator add = (a, b) -> a + b;
System.out.println(add.calculate(5, 3));What is Lambda
Lambda is a concise anonymous function syntax (parameter -> expression) in Java 8+ that enables functional programming, often used with functional interfaces and streams.
List<String> fruits = Arrays.asList("apple", "banana", "orange");
fruits.forEach(f -> System.out.println(f));
Function<Integer, Integer> square = x -> x * x;JDBC
35 questionsHow to close the connection connection
Call connection.close() to release JDBC connection back to pool; use try-with-resources for automatic closure.
How to cause a stored procedure
Use CallableStatement: CallableStatement cs = connection.prepareCall("{call procName(?, ?)}"); set parameters with setString(); execute with executeQuery(); retrieve results with getters.
How is the database request and processing the results are carried out
JDBC uses DriverManager to establish connections, executes SQL via Statement/PreparedStatement objects, and processes results through ResultSet which provides methods like next(), getInt(), getString() to iterate and extract data.
XML
28 questionsWhat is XSLT
XSLT transforms XML documents using template-based rules into other XML, HTML, or text formats.
What is JAXP
JAXP is Java API for XML Processing: provides parsing (SAX/DOM), transformation (XSLT), and validation (XSD) through factory pattern abstraction.
What are the ways of recording XML
DOM (in-memory tree), SAX (stream-based), StAX (event-based), and binding frameworks like JAXB for direct object serialization.
Java interview questions for freshers
If you are a fresher or have less than 2 years of experience, focus on Java Core and OOP fundamentals. Interviewers expect you to know the basics well, not to have deep framework knowledge. These are the questions you will face most often:
What is OOP
OOP encapsulates data and behavior using inheritance, polymorphism, encapsulation, and abstraction to build maintainable, reusable code.
What are the principles of OOP
Encapsulation (data hiding), Abstraction (hide complexity), Inheritance (code reuse), Polymorphism (runtime behavior determination).
What is the difference between the interface and the abstract class
Interfaces define contracts with abstract methods, supporting multiple inheritance; abstract classes provide partial implementation and state with single inheritance.
What is the difference between Checked and UNCHECked exceptions
Checked exceptions must be caught or declared (IOException), while unchecked exceptions extend RuntimeException and represent programming errors that don't require declaration.
What primitive data types are in Java
Java primitives are: byte, short, int, long, float, double, boolean, and char,stored on the stack with fixed memory sizes.
What is the difference between a primitive and a reference type of data
Primitives (int, boolean) store values directly on stack; reference types (objects) store memory address on stack, actual data on heap.
Tell me about the hierarchy of collections in Java
Collection → List (ArrayList, LinkedList), Set (HashSet, TreeSet), Queue; Map hierarchy separate (HashMap, TreeMap, ConcurrentHashMap).
What is the difference between Linkedlist and Arraylist
ArrayList uses dynamic array (fast random access, slow insertion/deletion), LinkedList uses doubly-linked nodes (slow access, fast insertion/deletion at ends).
Tell me about Hashcode and Equals Contract
hashCode() and equals() must be consistent: equal objects have same hashCode; used together in hashing structures like HashMap to determine bucket placement and collision resolution.
What is a functional interface
Functional interface has exactly one abstract method, allowing lambda expression implementation; annotated with @FunctionalInterface (e.g., Comparator, Function).
Browse the Java Core and OOP sections above for the full list.
Java interview questions for experienced developers
With 3+ years of experience, interviewers expect you to go beyond basics. Expect questions about concurrency, framework internals, database optimization, and design patterns. These come up regularly in mid-level and senior Java interviews:
Tell me about Deadlock
Deadlock occurs when threads circularly wait for locks held by others; prevent via lock ordering, timeouts, tryLock(), or ReentrantReadWriteLock patterns.
What is executorservice
ExecutorService is a thread pool that manages a pool of threads for executing submitted tasks asynchronously. It abstracts away thread creation and lifecycle management, providing methods like submit(), execute(), and shutdown().
How Hashmap is organized
HashMap uses array of buckets; hash function determines bucket index, collisions resolved via linked lists or red-black trees (Java 8+) when threshold exceeded.
What Spring Scopes do you know
Singleton (one instance application-wide), Prototype (new per injection), Request (per HTTP request), Session (per user session), Application (application scope).
What is Bean
A Bean in Spring is a managed object created and maintained by the Spring IoC container with lifecycle methods and dependency injection capabilities.
What is the normalization of databases
Database normalization organizes data into tables to reduce redundancy and dependency by applying rules like 1NF, 2NF, 3NF, ensuring data integrity and efficient queries.
What areas of memory in JVM do you know
JVM memory areas: Stack (local variables, method calls), Heap (objects, garbage collected), Method Area (class structures, constants), Program Counter, and Native Method Stack.
Tell me about Race Condition
Race condition occurs when multiple threads access shared mutable data concurrently and at least one modifies it, causing unpredictable behavior due to non-atomic operations.
What is the difference between SQL and NOSQL
SQL is relational (structured tables, ACID properties, complex joins), while NoSQL is non-relational (document/key-value stores, eventual consistency, horizontal scaling).
What is Stream in Java?
Stream provides lazy, functional pipeline for processing collections; chains operations (map, filter, reduce) without modifying source, enabling parallel processing.
Browse the Spring, Multithreading, and Databases sections above for the full list.
How to prepare
1. Know the top 40 cold. The high and moderate frequency questions are the ones you will face. OOP, exceptions, collections, Java 8 features.
2. Go deep on Java Core and Collections. Over 400 questions combined. HashMap internals, ArrayList vs LinkedList, garbage collection, hashCode and equals.
3. Practice coding. Use the NeetCode 150 or Blind 75.
4. Mock interviews. Practice with an AI mock interview. Most candidates fail on communication, not knowledge.
Where this data comes from
These 1,715 Java interview questions were extracted from 600 real, publicly available Java developer interviews on YouTube. Voice transcription and text categorization identified every unique question, then counted how often each one appeared.
The result is a frequency-ranked list showing what interviewers actually ask. The high frequency questions (15) appear in the majority of interviews. If you are short on time, start there.
Frequently Asked Questions
What are the most common Java interview questions?add
Based on 600 real interviews: What is OOP, explain checked vs unchecked exceptions, describe the collections hierarchy, explain hashCode and equals, how is HashMap organized, what is SOLID, and what is Stream in Java 8. These appear in the majority of Java interviews regardless of level.
How many Java interview questions should I prepare?add
Focus on the high and moderate frequency questions first (about 40). Once those are solid, work through your weak topics. Understanding the top 100-150 gives you strong coverage. You do not need to memorize all 1,715.
What Java topics are asked most in interviews?add
Java Core (OOP, exceptions, data types, generics), Spring Framework (beans, scopes, DI), Collections (HashMap, ArrayList, LinkedList internals), and Multithreading (deadlock, synchronization, ExecutorService). Senior roles add JVM internals and system design.
Are Java interview questions different for freshers vs experienced?add
Yes. Freshers get more OOP fundamentals and Java Core basics. Experienced candidates (3+ years) get Spring, Multithreading, database, and architecture questions. The high frequency questions apply to all levels.
How should I prepare for a Java coding interview?add
Start with high frequency questions on this page. Then practice coding problems using NeetCode 150 or Blind 75 in Java. Finally, do mock interviews to practice explaining answers under pressure.
Knowing the answers is half the battle
The other half is explaining them clearly under pressure.
Try a free mock interviewarrow_forward