☕
Free Study Guide · 2025
Top 10 JavaInterview Questions & Answers (2025)
Java is the backbone of enterprise software in India — asked in every TCS, Infosys, Wipro, Cognizant campus drive and product company interview. These questions cover everything from core OOP to Spring Boot, multithreading, and JVM internals.
✓ 10 questions
✓ Detailed answers
✓ 100% free
1What are the four pillars of Object-Oriented Programming?▼
Encapsulation (binding data and methods together, hiding internals via access modifiers), Inheritance (a child class acquires properties of a parent class), Polymorphism (one interface, many implementations — method overloading and overriding), and Abstraction (hiding complexity, exposing only essential features via abstract classes or interfaces).
2What is the difference between an abstract class and an interface?▼
An abstract class can have implemented methods, constructors, instance variables, and can extend only one class. An interface (prior to Java 8) only had abstract methods; since Java 8 it can have default and static methods but no instance state. A class can implement multiple interfaces but extend only one class. Use interfaces for capability contracts, abstract classes for shared base implementations.
3What is the difference between == and .equals() in Java?▼
== compares object references (memory addresses) for objects, and values for primitives. .equals() compares the logical content of objects — it's overridden in String, Integer, and other classes to compare values. Always use .equals() to compare String content; == on String literals may appear to work due to the String pool but is unreliable for non-literal strings.
4What is the Java Memory Model? Explain heap and stack.▼
The stack stores method call frames, local primitives, and object references — each thread has its own stack. The heap stores all objects and class instances — shared across threads. The Metaspace (replaced PermGen in Java 8) stores class metadata. Understanding this distinction is key for diagnosing OutOfMemoryErrors and threading issues.
5What is garbage collection in Java?▼
Java's garbage collector automatically reclaims memory from objects that are no longer reachable (no live references). The JVM uses generational GC: most objects are young (created and quickly collected in Eden space), survivors move to older generations. Modern collectors include G1 (default since Java 9), ZGC, and Shenandoah — all designed for low-pause-time collection.
6What is the difference between ArrayList and LinkedList?▼
ArrayList is backed by a dynamic array — O(1) random access but O(n) insertion/deletion in the middle. LinkedList is a doubly-linked list — O(1) insertion/deletion at ends but O(n) random access. Use ArrayList for most use cases (better cache locality); use LinkedList only when frequent insertions/deletions at both ends outweigh the overhead of pointer traversal.
7What is the difference between HashMap and Hashtable?▼
HashMap is not synchronised (not thread-safe), allows one null key and multiple null values, and is faster. Hashtable is synchronised (thread-safe via method-level locking), allows no null keys or values, and is slower. In modern code, use ConcurrentHashMap for thread-safe maps — it uses segment-level locking for much better concurrent performance than Hashtable.
8What is the difference between checked and unchecked exceptions?▼
Checked exceptions (IOException, SQLException) are verified at compile time — you must either catch them or declare them with throws. Unchecked exceptions (RuntimeException subclasses like NullPointerException, ArrayIndexOutOfBoundsException) are not checked at compile time. Checked exceptions model recoverable conditions; unchecked model programming errors.
9What is multithreading and how do you create a thread in Java?▼
Multithreading allows concurrent execution of multiple threads within a process, sharing heap memory. You can create threads by: (1) extending Thread class and overriding run(), (2) implementing Runnable and passing it to Thread, or (3) implementing Callable with an ExecutorService for tasks that return values. The modern approach is using ExecutorService and thread pools rather than managing threads directly.
10What is synchronisation in Java and why is it needed?▼
Synchronisation prevents race conditions by ensuring only one thread at a time executes a critical section. Use the synchronized keyword on methods or blocks. volatile ensures visibility of variable changes across threads but doesn't ensure atomicity. Java's java.util.concurrent package provides higher-level tools: ReentrantLock, Semaphore, CountDownLatch, and atomic classes.
Level up your prep
Get company-specific Java questions
Upload your resume → get questions tailored to Google, Amazon, TCS, and 50+ companies.