Top 50 Java Interview Questions for Freshers 2026
22 min read
interview-questions
Advertisement Placement
Top 50 Java Interview Questions for Freshers 2026
Last Updated: March 2026 | Level: Freshers & 0-2 Years Experience | Read Time: ~20 min
Master these 50 Java interview questions before your next technical round. Curated from real interview experiences at top MNCs, startups, and product companies. Java is the primary language tested at Infosys, TCS, and Wipro — pair this guide with our Infosys Placement Papers 2026 and TCS Placement Papers 2026 for end-to-end preparation.
Table of Contents
- Core Java (Q1–Q15)
- OOP Concepts (Q16–Q25)
- Collections Framework (Q26–Q35)
- Multithreading (Q36–Q43)
- Java 8+ Features (Q44–Q50)
Core Java
Q1. What is the difference between JDK, JRE, and JVM? Easy
Memory tip: JDK ⊃ JRE ⊃ JVM
Q2. What is the difference between == and .equals() in Java? Easy
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)
Q3. What is autoboxing and unboxing in Java? Easy
int num = 42;
Integer boxed = num; // autoboxing
int unboxed = boxed; // unboxing
List<Integer> list = new ArrayList<>();
list.add(10); // autoboxing int → Integer
Q4. What is the final keyword in Java? Easy
final int MAX = 100; // constant variable
// MAX = 200; // compile error
final class Immutable {} // cannot be subclassed
// class Sub extends Immutable {} // compile error
Q5. Explain the difference between String, StringBuilder, and StringBuffer. Medium
// String (immutable)
String s = "Hello";
s = s + " World"; // new object created
// StringBuilder (mutable, not thread-safe)
StringBuilder sb = new StringBuilder("Hello");
sb.append(" World"); // modifies same object
// StringBuffer (mutable, thread-safe)
StringBuffer sbuf = new StringBuffer("Hello");
sbuf.append(" World");
Q6. What is the String Pool in Java? Medium
String a = "hello"; // stored in pool
String b = "hello"; // returns existing pool reference
String c = new String("hello"); // forces new heap object
System.out.println(a == b); // true (same pool reference)
System.out.println(a == c); // false (different object)
System.out.println(a == c.intern()); // true (intern() adds to pool)
Q7. What are access modifiers in Java? Easy
| Modifier | Class | Package | Subclass | World |
|---|---|---|---|---|
| private | ✅ | ❌ | ❌ | ❌ |
| default | ✅ | ✅ | ❌ | ❌ |
| protected | ✅ | ✅ | ✅ | ❌ |
| public | ✅ | ✅ | ✅ | ✅ |
Q8. What is a static method and when would you use it? Easy
class MathUtils {
static int square(int n) {
return n * n;
}
}
// Call without creating object
int result = MathUtils.square(5); // 25
Q9. What is exception handling in Java? Explain try-catch-finally. Medium
try {
int result = 10 / 0; // throws ArithmeticException
} catch (ArithmeticException e) {
System.out.println("Cannot divide by zero: " + e.getMessage());
} finally {
System.out.println("This always runs");
}
Q10. What is the difference between checked and unchecked exceptions? Medium
// Checked exception — must handle
try {
FileReader fr = new FileReader("file.txt"); // throws IOException
} catch (IOException e) { }
// Unchecked exception — optional handling
String s = null;
s.length(); // throws NullPointerException at runtime
Q11. What is the this keyword in Java? Easy
class Person {
String name;
Person(String name) {
this.name = name; // 'this.name' = field, 'name' = parameter
}
}
Q12. What is type casting in Java? Medium
// Widening (automatic)
int i = 100;
long l = i; // automatic widening
// Narrowing (explicit)
double d = 9.99;
int n = (int) d; // explicit cast, n = 9 (decimal truncated)
Q13. What is a Java interface? How is it different from an abstract class? Medium
interface Drawable {
void draw(); // abstract
default void show() { // default method (Java 8+)
System.out.println("Showing...");
}
}
abstract class Shape {
int color; // state allowed
abstract double area(); // abstract method
void describe() { } // concrete method
}
Q14. What is garbage collection in Java? Medium
Q15. What is the difference between Array and ArrayList? Easy
// Array — fixed size
int[] arr = new int[5];
arr[0] = 10;
// ArrayList — dynamic size
ArrayList<Integer> list = new ArrayList<>();
list.add(10);
list.add(20);
list.remove(0); // removes element at index 0
OOP Concepts
Q16. What are the four pillars of OOP? Easy
Q17. What is the difference between method overloading and method overriding? Medium
// Overloading (same class, different params)
class Calculator {
int add(int a, int b) { return a + b; }
double add(double a, double b) { return a + b; }
}
// Overriding (subclass reimplements parent method)
class Animal { void sound() { System.out.println("..."); } }
class Dog extends Animal {
@Override
void sound() { System.out.println("Woof!"); }
}
Q18. What is a constructor? What is constructor chaining? Easy
class Employee {
String name;
int age;
Employee(String name) {
this(name, 25); // chains to next constructor
}
Employee(String name, int age) {
this.name = name;
this.age = age;
}
}
Q19. What is the super keyword? Easy
class Vehicle {
String brand = "Generic";
void start() { System.out.println("Vehicle starting"); }
}
class Car extends Vehicle {
String brand = "Toyota";
void display() {
System.out.println(brand); // Toyota (child)
System.out.println(super.brand); // Generic (parent)
super.start(); // calls parent method
}
}
Q20. What is an abstract class? When should you use it? Medium
abstract class Shape {
String color;
Shape(String color) { this.color = color; }
abstract double area(); // must be implemented by subclasses
void displayColor() { // shared concrete method
System.out.println("Color: " + color);
}
}
class Circle extends Shape {
double radius;
Circle(String color, double r) { super(color); this.radius = r; }
@Override
double area() { return Math.PI * radius * radius; }
}
Q21. What is polymorphism? Give a real-world example. Medium
class Payment {
void process() { System.out.println("Processing payment..."); }
}
class CreditCard extends Payment {
@Override void process() { System.out.println("Processing credit card"); }
}
class UPI extends Payment {
@Override void process() { System.out.println("Processing UPI"); }
}
Payment p = new CreditCard(); // parent ref, child object
p.process(); // "Processing credit card" — runtime dispatch
Q22. What is encapsulation? Why is it important? Easy
class BankAccount {
private double balance; // hidden
public double getBalance() { return balance; } // controlled read
public void deposit(double amount) {
if (amount > 0) balance += amount; // controlled write
}
}
Q23. Can an interface extend another interface? Medium
interface Readable { void read(); }
interface Writable { void write(); }
interface ReadWrite extends Readable, Writable { } // multiple extension
class File implements ReadWrite {
public void read() { System.out.println("Reading..."); }
public void write() { System.out.println("Writing..."); }
}
Q24. What is the difference between aggregation and composition? Hard
Q25. What is the Liskov Substitution Principle? Hard
Collections Framework
Q26. What is the Java Collections Framework? Easy
Q27. What is the difference between ArrayList and LinkedList? Medium
ArrayList<String> arrayList = new ArrayList<>(); // backed by array
LinkedList<String> linkedList = new LinkedList<>(); // backed by linked nodes
linkedList.addFirst("first"); // O(1) — LinkedList advantage
Q28. What is the difference between HashMap and HashSet? Easy
Q29. What is the difference between HashMap and TreeMap? Medium
Map<String, Integer> hashMap = new HashMap<>(); // unordered
Map<String, Integer> treeMap = new TreeMap<>(); // sorted by key
treeMap.put("banana", 2);
treeMap.put("apple", 1);
treeMap.put("cherry", 3);
// Iterates: apple, banana, cherry (sorted)
Q30. How does HashMap work internally? Hard
Q31. What is the difference between fail-fast and fail-safe iterators? Hard
Q32. What is LinkedHashMap? Medium
Map<String, Integer> lhm = new LinkedHashMap<>();
lhm.put("c", 3); lhm.put("a", 1); lhm.put("b", 2);
// Iterates in insertion order: c, a, b
Q33. What is the difference between Iterator and ListIterator? Medium
Q34. What is Collections.synchronizedList()? Medium
Q35. What is the difference between Comparable and Comparator? Medium
// Comparable — class implements it
class Student implements Comparable<Student> {
int age;
public int compareTo(Student other) { return this.age - other.age; }
}
// Comparator — external sorting logic
Comparator<Student> byName = (s1, s2) -> s1.name.compareTo(s2.name);
students.sort(byName);
Multithreading
Q36. What is a thread? How do you create one in Java? Easy
// Method 1: Extend Thread
class MyThread extends Thread {
public void run() { System.out.println("Thread running"); }
}
new MyThread().start();
// Method 2: Implement Runnable (preferred)
Thread t = new Thread(() -> System.out.println("Runnable running"));
t.start();
Q37. What is the difference between start() and run() in threads? Easy
Q38. What is synchronization in Java? Medium
class Counter {
private int count = 0;
synchronized void increment() { // only one thread at a time
count++;
}
}
Q39. What is a deadlock? How can you prevent it? Hard
Q40. What is the volatile keyword? Hard
class SharedFlag {
volatile boolean running = true; // always read from main memory
void stop() { running = false; }
void doWork() {
while (running) { /* work */ }
}
}
Q41. What is ExecutorService? Medium
ExecutorService executor = Executors.newFixedThreadPool(4);
Future<Integer> future = executor.submit(() -> {
return 42; // task returning a value
});
int result = future.get(); // blocks until result ready
executor.shutdown();
Q42. What is the difference between wait() and sleep()? Medium
Q43. What is a ThreadLocal variable? Hard
ThreadLocal<Integer> threadId = ThreadLocal.withInitial(() -> 0);
// Each thread gets its own copy
Runnable task = () -> {
threadId.set((int)(Math.random() * 100));
System.out.println("Thread ID: " + threadId.get());
};
Java 8+ Features
Q44. What are lambda expressions? Easy
// Before Java 8 (anonymous class)
Runnable r1 = new Runnable() {
public void run() { System.out.println("Running"); }
};
// Java 8 lambda
Runnable r2 = () -> System.out.println("Running");
// With Collections
List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
names.forEach(name -> System.out.println(name));
Q45. What is the Stream API? Medium
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
int sumOfEvenSquares = numbers.stream()
.filter(n -> n % 2 == 0) // keep evens: 2,4,6,8,10
.map(n -> n * n) // square: 4,16,36,64,100
.reduce(0, Integer::sum); // sum: 220
System.out.println(sumOfEvenSquares); // 220
Q46. What is a functional interface? Medium
@FunctionalInterface
interface Transformer<T> {
T transform(T input);
}
Transformer<String> upper = s -> s.toUpperCase();
System.out.println(upper.transform("hello")); // HELLO
// Built-in functional interfaces
Predicate<Integer> isEven = n -> n % 2 == 0;
Function<String, Integer> strLen = String::length;
Q47. What is Optional in Java 8? Medium
Optional<String> name = Optional.of("Alice");
Optional<String> empty = Optional.empty();
System.out.println(name.orElse("Unknown")); // Alice
System.out.println(empty.orElse("Unknown")); // Unknown
// Method chaining
Optional<String> result = Optional.of(" hello ")
.map(String::trim)
.filter(s -> !s.isEmpty());
Q48. What are default methods in interfaces? Medium
interface Greetable {
default void greet() {
System.out.println("Hello!");
}
default void greetFormal(String name) {
System.out.println("Good day, " + name);
}
}
class Person implements Greetable {
// greet() is inherited — no need to override
}
Q49. What is method reference in Java 8? Medium
List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
// Lambda
names.forEach(name -> System.out.println(name));
// Method reference (equivalent)
names.forEach(System.out::println);
// Static method reference
List<String> upperNames = names.stream()
.map(String::toUpperCase) // instance method ref
.collect(Collectors.toList());
Q50. What is the difference between map() and flatMap() in streams? Hard
// map() — one to one
List<String> words = Arrays.asList("Hello World", "Java 8");
List<String[]> mapped = words.stream()
.map(s -> s.split(" ")) // Stream<String[]>
.collect(Collectors.toList());
// flatMap() — one to many, then flatten
List<String> flatMapped = words.stream()
.flatMap(s -> Arrays.stream(s.split(" "))) // Stream<String>
.collect(Collectors.toList());
// Result: ["Hello", "World", "Java", "8"]
Quick Revision Tips
| Topic | Key Points |
|---|---|
| JVM vs JDK vs JRE | JDK > JRE > JVM |
| String Pool | Literals cached, new String() bypasses pool |
| HashMap | Array of buckets, hashCode + equals, O(1) avg |
| Thread Safety | synchronized, volatile, atomic, concurrent collections |
| Java 8 | Lambdas, Streams, Optional, Default methods, Method refs |
Related Articles
- Top 50 Python Interview Questions 2026 — Python vs Java: know both for full-stack roles
- Top 50 SQL Interview Questions 2026 — Database skills every Java backend developer needs
- TCS Placement Papers 2026 — Java is the most tested language at TCS
- Infosys Placement Papers 2026 — Java questions feature heavily in Infosys SP/DSE rounds
© 2026 PlacementAdda.com | Updated for latest hiring trends
Advertisement Placement
Explore this topic cluster
More resources in interview-questions
Use the category hub to browse similar questions, exam patterns, salary guides, and preparation resources related to this topic.
More in interview-questions
interview-questions
Top 30 HR Interview Questions with Best Answers (2026)
24 min read
interview-questionsTop 30 System Design Interview Questions for 2026
20 min read
interview-questionsTop 40 React.js Interview Questions & Answers (2026)
29 min read
interview-questionsTop 50 Data Structures Interview Questions 2026
10 min read