Backend · Fresher-relevant
Core Java interview questions on OOPs, collections, multithreading, JVM internals, and exception handling — the primary language tested by TCS, Infosys, and Wipro.
What is the difference between == and .equals() in Java?
Tip: == compares references (whether two variables point to the same object), while .equals() compares logical value. For String literals interned in the string pool == may appear to work, but always use .equals() for content comparison. Override equals() and hashCode() together for custom classes.
Explain the Java memory model: stack vs heap.
Tip: The stack stores method frames, local primitives, and object references — it is per-thread and freed when a method returns. The heap stores all objects and is shared across threads and managed by the garbage collector. Class metadata lives in the Metaspace (post-Java 8, replacing PermGen).
What is the difference between HashMap, HashTable, and ConcurrentHashMap?
Tip: HashMap is unsynchronised and allows one null key. HashTable is fully synchronised (legacy, slow) and disallows nulls. ConcurrentHashMap uses bucket/segment-level locking (CAS + synchronized bins since Java 8) for high-concurrency reads/writes without locking the whole map — prefer it over HashTable.
What are the four pillars of OOP and how does Java implement each?
Tip: Encapsulation (private fields + getters/setters), Inheritance (extends, single class inheritance), Polymorphism (method overriding + dynamic dispatch, overloading at compile time), and Abstraction (abstract classes and interfaces). Mention that Java supports multiple interface inheritance but single class inheritance.
What is the difference between an abstract class and an interface?
Tip: An abstract class can hold state (fields), constructors, and a mix of concrete and abstract methods; a class extends only one. An interface defines a contract — since Java 8 it can have default and static methods, and a class can implement many. Use an interface for "can-do" capabilities, an abstract class for shared base state.
How does garbage collection work in Java? What is a memory leak in a GC language?
Tip: GC reclaims unreachable objects using generational collection (Young/Eden + Survivor, then Old gen). Algorithms include G1 (default since Java 9) and ZGC for low pause times. A leak still occurs when objects remain reachable but are no longer needed — e.g. static collections, unremoved listeners, or unclosed resources holding references.
What is the difference between checked and unchecked exceptions?
Tip: Checked exceptions (extend Exception) must be declared or handled at compile time — e.g. IOException. Unchecked exceptions (extend RuntimeException) signal programming errors like NullPointerException and need not be declared. Do not swallow exceptions; either handle meaningfully or propagate.
Explain the volatile keyword and the difference between volatile and synchronized.
Tip: volatile guarantees visibility — reads/writes go to main memory, preventing stale cached values — but not atomicity. synchronized provides both mutual exclusion (atomicity) and visibility via the happens-before relationship. Use volatile for simple flags; use synchronized or AtomicInteger for compound read-modify-write operations.
InterviewEra generates role-specific questions using your actual projects and skills. Get scored feedback on technical depth, clarity, and structure — free to start.