Top Java Interview Questions for Freshers (2026) — with Answers
Updated August 2026
Java is the default interview language at TCS, Infosys, Cognizant and most mass recruiters — even if you coded your test in Python, expect Java-flavoured OOP questions in the technical round.
These are the questions interviewers actually open with. Learn to answer each in 30–60 seconds, then practise saying them out loud.
Frequently asked questions
What are the four pillars of OOP?
Encapsulation (bundling data with methods and restricting direct access), inheritance (a class acquiring properties of another), polymorphism (one interface, many implementations — overloading and overriding), and abstraction (exposing only essential details via abstract classes/interfaces).
Why is Java called platform-independent?
Java source compiles to bytecode, which runs on any machine that has a JVM. "Write once, run anywhere" — the JVM, not the OS, executes your program.
Difference between JDK, JRE and JVM?
JVM executes bytecode. JRE = JVM + core libraries, enough to run Java programs. JDK = JRE + compiler and dev tools, needed to write them.
Method overloading vs overriding?
Overloading: same method name, different parameter lists, same class, resolved at compile time. Overriding: subclass redefines a superclass method with the same signature, resolved at runtime.
Why are Strings immutable in Java?
Security (strings carry file paths, credentials), thread safety, and the string pool — immutability lets identical literals share one object safely.
String vs StringBuilder vs StringBuffer?
String is immutable. StringBuilder is mutable and fast but not thread-safe. StringBuffer is mutable and synchronized (thread-safe, slightly slower). Use StringBuilder for loops that build strings.
ArrayList vs LinkedList?
ArrayList is a resizable array: O(1) random access, slow middle insertions. LinkedList is a doubly-linked list: O(1) insert/delete at the ends, O(n) access. In practice ArrayList wins for most workloads.
HashMap vs HashTable?
HashMap is unsynchronized, allows one null key; HashTable is legacy, synchronized and allows no nulls. For thread safety today, use ConcurrentHashMap.
What is an abstract class vs an interface?
Abstract class: can have state, constructors, and both abstract and concrete methods; a class extends only one. Interface: a contract of behavior; a class can implement many. Since Java 8 interfaces can also carry default methods.
What are checked and unchecked exceptions?
Checked exceptions (IOException, SQLException) must be handled or declared — the compiler enforces it. Unchecked (RuntimeException like NullPointerException) indicate programming bugs and are not enforced at compile time.
What is the static keyword?
A static member belongs to the class, not to instances — one copy shared by all objects. Static methods can be called without an object but cannot use instance variables directly.
Explain garbage collection in Java.
The JVM automatically frees memory of objects with no live references. You cannot force it — System.gc() is only a request. This is why Java has no manual free()/delete like C/C++.
Don't just read Java questions — get asked them
Phiny's AI interviews you on exactly these topics, follows up on weak answers, and tells you what a stronger answer looks like. Text interviews are free and unlimited.
Start a free AI mock interviewHow to prepare
- Interviewers chain questions: String immutability → string pool → == vs .equals(). Prepare the chains, not isolated answers.
- Always follow a definition with a one-line code example or real-world analogy — that is what separates a memorized answer.
- For TCS/Infosys, be ready to write a small program using OOP (e.g., a BankAccount class) on paper.
Where these questions get asked
- TCS NQT guide and Infosys hiring guide — the two biggest exams these questions appear in.
- All company placement guides — pattern, syllabus and rounds for every mass recruiter.