Java is the most widely used programming language in Indian software development: powering the backend systems of TCS, Infosys, Wipro, and most Indian BFSI companies, as well as critical services at Flipkart, PhonePe, and Razorpay. A Java interview in India tests a combination of core language knowledge, OOP principles, collections framework, multithreading, JVM understanding, and practical Spring Boot. This guide covers what is actually tested.
Core Java questions most tested in India
Q: What is the difference between JDK, JRE, and JVM? JVM (Java Virtual Machine): the runtime environment that executes Java bytecode. Platform-specific: Windows JVM, Linux JVM. JRE (Java Runtime Environment): JVM + standard library (java.lang, java.util etc). Enough to run Java programs. JDK (Java Development Kit): JRE + compiler (javac) + development tools. Needed to write and compile Java programs.
Q: What is the difference between == and .equals() in Java? `==` compares references (are these the same object in memory?). `.equals()` compares values (are these objects logically equal?). For Strings: `"hello" == "hello"` may be true due to the String pool, but this is an implementation detail: always use `.equals()` for String comparison. Violating this is a common real-world bug.
Q: What is autoboxing and unboxing? Autoboxing: automatic conversion from primitive (int) to wrapper class (Integer). Unboxing: automatic conversion from wrapper to primitive. Performance trap: autoboxing in a loop creates many temporary Integer objects. NullPointerException trap: unboxing a null Integer causes NPE.
Q: What is the difference between final, finally, and finalize()? `final`: keyword to make a variable constant, prevent method overriding, or prevent class inheritance. `finally`: block in try-catch that always executes regardless of exception. `finalize()`: deprecated method called by GC before object collection: never rely on it for resource cleanup (use try-with-resources instead).
Q: What is the String pool? Java maintains a pool of String literals in the heap. String literals (`"hello"`) are interned: same literal resolves to the same object. `String.intern()` adds a runtime String to the pool. This saves memory for repeated literals but means == comparison for Strings can give misleading results.
Java Collections and Generics
Q: When do you use ArrayList vs LinkedList? ArrayList: backed by a dynamic array. O(1) random access (get by index). O(n) insertion/deletion in the middle. LinkedList: doubly-linked list. O(n) random access. O(1) insertion/deletion at head/tail when you have a reference. In practice: use ArrayList for most cases: cache locality makes it faster than LinkedList even for insertions in real benchmarks.
Q: What is the difference between HashMap, LinkedHashMap, and TreeMap? HashMap: O(1) average get/put, no ordering guarantee. LinkedHashMap: maintains insertion order. Slightly slower than HashMap. TreeMap: sorted by key (natural order or Comparator). O(log n) operations. Use when you need sorted keys.
Q: What is the difference between HashSet and TreeSet? HashSet: backed by HashMap. O(1) add/contains, no ordering. TreeSet: backed by TreeMap. Sorted, O(log n). Use TreeSet when you need sorted unique elements.
Q: How does HashMap handle hash collisions in Java 8+? Before Java 8: chaining with a linked list at each bucket. After Java 8: when a bucket's linked list exceeds 8 elements, it converts to a balanced tree (red-black tree), reducing worst-case from O(n) to O(log n). This matters when using a poorly-implemented hashCode that puts many keys in the same bucket.
Q: What are Java Generics and what is type erasure? Generics provide compile-time type safety. `List<String>` ensures you cannot add an Integer. Type erasure: at runtime, generic type information is removed: `List<String>` and `List<Integer>` are both `List` at runtime. This means you cannot use generics in certain ways (cannot instantiate `new T()`, cannot use generic arrays).
Java multithreading and Java 17 features
Q: What is the difference between Thread, Runnable, and Callable? Thread: the actual execution unit: extend Thread and override run(). Runnable: a functional interface with run() method, no return value, no checked exceptions. Callable: like Runnable but returns a value (Future<V>) and can throw checked exceptions. Prefer Callable/ExecutorService over raw Thread creation.
Q: What is synchronized and what problems does it solve? `synchronized` ensures only one thread executes the synchronized block/method at a time, preventing race conditions. Methods marked synchronized lock on `this`. Static synchronized methods lock on the class object. Over-synchronization causes performance bottlenecks: prefer java.util.concurrent classes (ConcurrentHashMap, AtomicInteger, ReentrantLock) for fine-grained control.
Q: What is volatile in Java? Volatile guarantees visibility: writes to a volatile variable are immediately visible to all threads (bypasses CPU cache). It does NOT provide atomicity. `volatile int counter`: reading is thread-safe but `counter++` (read-modify-write) is not atomic. Use AtomicInteger for atomic increment operations.
Java 17 features tested at modern Indian product companies:
- Records: immutable data classes with less boilerplate. `record Point(int x, int y) {}` auto-generates constructor, getters, equals, hashCode, toString.
- Sealed classes: restricts which classes can extend a class. Used with pattern matching.
- Text blocks: multi-line strings with `"""`. Perfect for JSON/SQL in code.
- Pattern matching for instanceof: `if (obj instanceof String s) { s.length() }`: no explicit cast needed.
Frequently asked questions
Practice these questions on HireStepX