Java Interview Questions for Freshers 2026 — Top 50 with Answers
Comprehensive collection of the most commonly asked Java interview questions for freshers and entry-level developers. Covers Core Java, OOP, Collections, Exception Handling, Multithreading, and Java 8+ features. Perfect for TCS NQT, Infosys InfyTQ, Wipro, Cognizant, and campus placement preparation.
Core Java Basics
Q1.What is JVM, JDK, and JRE?
JVM (Java Virtual Machine) executes bytecode. JRE (Java Runtime Environment) = JVM + standard libraries for running Java apps. JDK (Java Development Kit) = JRE + compiler + development tools for building Java apps.
Q2.What is the difference between == and .equals()?
== compares object references (memory addresses). .equals() compares actual content/values of objects. For Strings, always use .equals() to compare values.
Q3.What is autoboxing and unboxing?
Autoboxing is automatic conversion of primitive to wrapper class (int → Integer). Unboxing is the reverse (Integer → int). Example: Integer x = 5; (autoboxing), int y = x; (unboxing).
Q4.Explain the final keyword in Java.
final variable = value cannot be changed. final method = cannot be overridden. final class = cannot be extended/inherited. Example: final int MAX = 100;
Q5.What is the difference between String, StringBuilder, and StringBuffer?
String is immutable. StringBuilder is mutable and not thread-safe (faster). StringBuffer is mutable and thread-safe (synchronized, slower). Use StringBuilder for single-threaded string manipulation.
Q6.What is the static keyword?
static members belong to the class, not instances. static variables are shared across all objects. static methods can be called without creating objects. static blocks run when class is loaded.
Q7.What is type casting in Java?
Widening (implicit): smaller type to larger (int → long). Narrowing (explicit): larger type to smaller (double → int), requires cast: int x = (int) 3.14;
OOP Concepts
Q11.What are the four pillars of OOP?
Encapsulation (wrapping data + methods), Inheritance (child extends parent), Polymorphism (same method behaves differently), Abstraction (hiding complexity). These are the foundation of Java architecture.
Q12.What is the difference between abstract class and interface?
Abstract class can have constructors, instance variables, and both abstract + concrete methods. Interface (before Java 8) has only abstract methods. After Java 8, interfaces can have default and static methods. A class can implement multiple interfaces but extend only one abstract class.
Q13.What is method overloading vs overriding?
Overloading: same method name, different parameters, in the same class (compile-time polymorphism). Overriding: same method signature in child class (runtime polymorphism). Overriding requires @Override annotation.
Q14.What is encapsulation? Give an example.
Encapsulation bundles data (variables) and methods into a single unit (class) and restricts direct access using access modifiers. Example: private variables with public getters/setters.
Q15.Explain the super keyword.
super refers to the parent class. super() calls parent constructor. super.method() calls parent method. super.variable accesses parent variable. super() must be the first statement in child constructor.
Q16.What is the this keyword?
this refers to the current object. Used to disambiguate instance variables from parameters: this.name = name. Also used to call other constructors: this(param).
Collections Framework
Q21.What is the difference between ArrayList and LinkedList?
ArrayList uses dynamic array — O(1) random access, O(n) insert/delete. LinkedList uses doubly-linked list — O(n) random access, O(1) insert/delete at known position. Use ArrayList for most cases.
Q22.What is the difference between HashMap and Hashtable?
HashMap: not synchronized, allows one null key, faster. Hashtable: synchronized (thread-safe), no null keys. HashMap is preferred; use ConcurrentHashMap for thread-safety.
Q23.What is the difference between Set and List?
List: ordered, allows duplicates, accessed by index (ArrayList, LinkedList). Set: unordered, no duplicates (HashSet, TreeSet). Use Set when you need unique elements.
Q24.How does HashMap work internally?
HashMap uses an array of buckets. Each key's hashCode() determines the bucket index. Collisions are handled by linked list (Java 7) or balanced tree (Java 8+ when > 8 entries). Load factor 0.75 triggers resize.
Q25.What is the difference between Comparable and Comparator?
Comparable: natural ordering, class implements compareTo(). Comparator: custom ordering, separate class implements compare(). Use Comparable for default sorting, Comparator for multiple sort criteria.
Exception Handling
Q31.What is the difference between checked and unchecked exceptions?
Checked exceptions must be caught or declared (IOException, SQLException). Unchecked exceptions extend RuntimeException and don't require handling (NullPointerException, ArrayIndexOutOfBoundsException). Errors (OutOfMemoryError) are not exceptions.
Q32.What is try-with-resources?
Introduced in Java 7, automatically closes resources implementing AutoCloseable. Syntax: try (InputStream is = new FileInputStream("file.txt")) { ... }. No need for finally block to close resources.
Q33.Can we have try without catch?
Yes, try can be used with just finally (try-finally) or with try-with-resources. But you cannot have both try without catch and without finally — at least one is required.
Q34.What is the difference between throw and throws?
throw is used to explicitly throw an exception: throw new Exception("error"). throws is used in method signature to declare exceptions: public void readFile() throws IOException.
Multithreading
Q41.What is the difference between Thread and Runnable?
Thread is a class (single inheritance limitation). Runnable is an interface (can implement multiple). Best practice: implement Runnable and pass to Thread constructor. Java 8+: use lambda with Runnable.
Q42.What is synchronization in Java?
Synchronization prevents multiple threads from accessing shared resources simultaneously. Use synchronized keyword on methods or blocks. Every object has an intrinsic lock (monitor).
Q43.What is the volatile keyword?
volatile ensures a variable is read from main memory, not thread cache. Provides visibility guarantee but NOT atomicity. Use for simple flags shared between threads.
Q44.What is deadlock? How to prevent it?
Deadlock occurs when two threads each hold a lock the other needs. Prevention: lock ordering (always acquire locks in the same order), use tryLock() with timeout, avoid nested locks.
Java 8+ Features
Q51.What are Lambda expressions?
Lambdas are anonymous functions. Syntax: (params) -> expression or (params) -> { statements }. Example: list.forEach(item -> System.out.println(item)). Requires a functional interface (single abstract method).
Q52.What is the Stream API?
Streams provide a functional approach to processing collections. Operations: filter(), map(), reduce(), collect(), forEach(). Streams are lazy (operations execute only when terminal operation is called). Example: list.stream().filter(x -> x > 5).collect(Collectors.toList()).
Q53.What is Optional in Java?
Optional is a container that may or may not contain a value. Prevents NullPointerException. Methods: isPresent(), get(), orElse(), orElseThrow(), map(), flatMap(). Example: Optional.ofNullable(value).orElse("default").
Q54.What are functional interfaces?
An interface with exactly one abstract method. Annotated with @FunctionalInterface. Common ones: Predicate<T> (boolean test), Function<T,R> (T→R), Consumer<T> (void accept), Supplier<T> (T get).
Practice Java Code for Interviews
Don't just read — practice! Run code examples in our free online compiler.
Frequently Asked Questions
How many Java interview questions should I prepare?
For freshers, prepare at least 50 core Java questions covering basics, OOP, collections, exception handling, and multithreading. For experienced roles, add 30-50 more on frameworks, system design, and Java 8+ features.
Which Java topics are most asked in interviews?
The most frequently asked topics are: OOP concepts (90% of interviews), Collections Framework (85%), Exception Handling (80%), Multithreading (70%), and Java 8 features like Streams and Lambdas (75%).
Should I practice coding for Java interviews?
Absolutely! Use our free online Java compiler to practice coding. Companies like TCS, Infosys, Wipro, and Cognizant often include coding rounds in their placement tests.
Is Java 8 knowledge enough for interviews?
Java 8 is the minimum. Most companies expect knowledge of Java 8 features (Lambda, Streams). Knowing Java 11, 17, or 21 features gives you an edge, especially for product companies.
How to prepare for TCS NQT Java section?
Focus on: basic Java syntax, OOP concepts, String operations, array programs, and simple algorithms. Practice at least 30 programs in our online compiler. TCS NQT Java section is beginner-to-intermediate difficulty.