Java is the most widely used language in Indian tech companies. TCS, Infosys, Wipro, and Cognizant use it for client delivery. Flipkart, Razorpay, and Swiggy build their core services in Java. FAANG India teams use it for large-scale distributed systems. This guide covers the complete Java developer interview question bank for India 2026: Core Java, Spring Boot, multithreading, JVM internals, and system design.
Core Java questions and answers
Core Java interview topics:
1. OOP (4 pillars with examples): - Encapsulation: hiding internal state via private fields and public getters/setters - Abstraction: exposing only what is necessary (abstract classes and interfaces) - Inheritance: subclass inherits from superclass via 'extends'; Java supports only single class inheritance - Polymorphism: the same method name behaves differently depending on the object type (overloading: compile-time; overriding: runtime)
'Difference between abstract class and interface?' Abstract class: can have state (fields), constructor, concrete methods, and abstract methods. Interface: defines a contract; pre-Java 8 only abstract methods; Java 8+ allows default and static methods; Java 9+ allows private methods. Use abstract class for shared behaviour within a class hierarchy; use interface for a contract that unrelated classes can implement.
2. Collections: - ArrayList vs LinkedList: ArrayList O(1) random access, O(n) insert-middle; LinkedList O(n) random access, O(1) insert-middle when pointer is at position. Use ArrayList for almost everything. - HashMap internals: array of buckets; key is hashed, used as bucket index; collision resolution via linked list (Java 7) or red-black tree (Java 8+, when chain length exceeds 8); load factor 0.75 triggers resize (double the capacity, rehash all entries) - HashSet vs TreeSet: HashSet O(1) average operations, unordered; TreeSet O(log n), sorted order (natural ordering or Comparator), backed by red-black tree
3. Generics: - Type safety at compile time: List<String> vs raw List - Bounded wildcards: List<? extends Number> (upper bound, read-only), List<? super Integer> (lower bound, write-ready) - Type erasure: generic type parameters are erased at runtime; List<String> and List<Integer> are both List at runtime
Multithreading questions and answers
Java multithreading interview questions:
1. 'What is a deadlock and how do you prevent it?' Deadlock: two threads each hold a lock the other needs; both wait forever. Prevention: consistent lock ordering (always acquire locks in the same order across all code paths), lock timeout (use tryLock(timeout, TimeUnit) from ReentrantLock instead of synchronized, so a thread can back off), avoid nested locking where possible.
2. 'What is the difference between wait() and sleep()?' wait(): releases the object's intrinsic lock while waiting; must be called from a synchronized block; woken by notify() or notifyAll(). sleep(): does NOT release the lock; simply pauses the current thread; no lock required; throws InterruptedException.
3. 'What is a thread pool and why use one?' Creating a new thread per task is expensive: thread creation takes approximately 1ms and consumes approximately 1MB of stack memory. A thread pool pre-creates reusable worker threads; tasks are queued and executed by the next available thread. Use ExecutorService via Executors.newFixedThreadPool(N) or ThreadPoolExecutor for custom configuration.
4. 'What is the difference between synchronized and ReentrantLock?' synchronized: simpler syntax, automatically released when the block exits, cannot be interrupted while waiting, no fairness option. ReentrantLock: tryLock() with timeout, lockInterruptibly() allows interrupt while waiting, optional fairness (FIFO ordering of waiting threads), multiple Condition objects per lock (finer-grained signalling than wait/notifyAll).
5. 'What are volatile and AtomicInteger for?' volatile: ensures visibility (reads and writes go to main memory, not a thread-local cache) but does NOT ensure atomicity. AtomicInteger: provides lock-free atomic operations (compareAndSet, incrementAndGet) backed by CPU atomic instructions (CAS: compare-and-swap).
Spring Boot questions and answers
Spring Boot interview questions:
1. 'What is dependency injection (DI) and how does Spring implement it?' DI: a design pattern where an object's dependencies are provided externally rather than created internally. Spring uses an IoC (Inversion of Control) container to manage bean lifecycle and inject dependencies. Annotations: @Component (marks a class as a Spring bean), @Service (semantic alias for @Component), @Repository (data layer bean), @Controller/@RestController (web layer). @Autowired injects a matching bean by type. Spring Boot uses @SpringBootApplication which combines @Configuration, @EnableAutoConfiguration, and @ComponentScan.
2. 'How does Spring Boot auto-configuration work?' @EnableAutoConfiguration scans the classpath; for each starter dependency, a corresponding AutoConfiguration class conditionally creates beans if: the class is on the classpath, the beans are not already defined, and property conditions are met. Example: spring-boot-starter-web includes Tomcat and Jackson; SpringMVC auto-configures a DispatcherServlet, error handler, and JSON conversion without any XML.
3. 'What is @Transactional and when do you use it?' @Transactional: declares that a method (or class) should run within a transaction. Spring creates a proxy that begins the transaction before the method and commits or rolls back after. Default behaviour: roll back on RuntimeException; no rollback on checked exceptions (use rollbackFor to change this). Pitfall: calling a @Transactional method from within the same class does not go through the proxy (the transaction annotation is ignored); inject the class and call via the injected reference instead.
Practise Java interview questions with HireStepX's AI voice interviewer. Get scored feedback on OOP explanations, Spring Boot architecture answers, and system design walkthroughs. First 2 sessions free.
Practice freeJVM and performance questions
JVM questions:
1. 'What is the difference between heap and stack memory in Java?' Heap: where objects are allocated; shared across all threads; managed by the garbage collector. Stack: each thread has its own stack; stores local variables, method call frames, and references (not the objects themselves, which live on the heap); stack frames are created on method entry and removed on method return. StackOverflowError: too many recursive calls exhaust the stack.
2. 'What are the main garbage collection algorithms in Java?' G1 (Garbage First): default in Java 9+; divides heap into regions; aims for predictable low-pause GC; good for most production workloads. ZGC and Shenandoah: low-latency collectors with sub-millisecond pause times; use for latency-sensitive services. Parallel GC: maximises throughput (total work done per unit time) at the cost of longer individual pause times; use for batch jobs.
3. 'What is memory leak in Java and how do you detect it?' Java has GC, but memory leaks can still occur when objects are referenced even though they are no longer needed. Common causes: listeners not removed, static collections that grow, thread-local variables not cleaned up. Detection: heap profiling with JProfiler or VisualVM; look for objects whose count grows unboundedly across GC cycles.
4. 'What is the difference between == and equals() for strings?' == compares object references (are these the same object in memory?). equals() compares content (do these strings contain the same characters?). String pool: string literals ('hello') are interned (shared from the pool); 'hello' == 'hello' is true for literals but 'hello' == new String('hello') is false.
Hibernate/JPA and microservices questions
Hibernate/JPA questions:
1. 'What is the difference between FetchType.LAZY and FetchType.EAGER?' LAZY: related entities are loaded from the database only when accessed (default for @OneToMany and @ManyToMany). EAGER: related entities are loaded immediately with the parent entity (default for @ManyToOne and @OneToOne). Use LAZY by default and fetch eagerly when needed via JOIN FETCH in JPQL to prevent N+1 queries.
2. 'What is an N+1 query problem and how do you fix it?' N+1: 1 query fetches N orders; then N queries fetch the user for each order (total: N+1 queries). Fix: use JOIN FETCH in JPQL ('SELECT o FROM Order o JOIN FETCH o.user'), or Spring Data JPA's @EntityGraph, or use select_related equivalent via query builder.
Microservices questions: 1. 'What is the difference between synchronous (REST) and asynchronous (event-driven) communication between microservices?' REST: service A calls service B and waits for the response; tight coupling (if B is down, A fails); simpler to implement. Event-driven (Kafka, RabbitMQ, SQS): service A publishes an event; service B consumes it independently; loose coupling; better resilience; eventual consistency instead of strong consistency.
2. 'How do you handle distributed transactions across microservices?' Saga pattern: a sequence of local transactions, each publishing an event that triggers the next; if a step fails, compensating transactions undo previous steps. Avoid distributed ACID transactions (two-phase commit) in microservices: too slow, too fragile.
Frequently asked questions
Explore more