Java backend interviews in India follow a predictable pattern. Core Java comes first, then Spring Boot, then microservices and design, and finally a deep dive into your project. What has changed in 2026 is the baseline. Interviewers increasingly expect you to know Java 21 features such as virtual threads, and to be aware of Spring Boot 4. This guide lists the questions that come up most often, with short model answers.
Version facts in this article were checked against OpenJDK, Oracle and Spring sources in October 2026.
What has changed for 2026 interviews
- Java baseline: Java 21 (September 2023) and Java 25 (September 2025) are the current LTS releases on Oracle’s roadmap. Java 21 finalised virtual threads (JEP 444), record patterns (JEP 440), pattern matching for switch (JEP 441) and sequenced collections (JEP 431).
- Spring Boot: Spring Boot 4.0 arrived in November 2025 and 4.1 on 10 June 2026, built on Spring Framework 7. Open-source support for Spring Boot 3.5 ended in June 2026, according to endoflife.date.
- AI tools: some interviewers now ask how you use AI coding assistants and how you verify what they produce.
Core Java questions
1. What is the difference between HashMap and ConcurrentHashMap?
HashMap is not thread-safe and allows one null key. ConcurrentHashMap supports safe concurrent access with fine-grained locking and CAS operations, does not allow null keys or values, and its iterators are weakly consistent rather than fail-fast.
2. Explain equals() and hashCode() contracts.
Equal objects must have equal hash codes. If you override equals() without hashCode(), hash-based collections such as HashMap and HashSet behave incorrectly. Records generate both automatically from their components.
3. What are virtual threads and when should you use them?
Virtual threads, final in Java 21, are lightweight threads managed by the JVM. They make blocking I/O cheap, so thread-per-request code can scale to very large numbers of concurrent tasks. They suit I/O-bound work such as HTTP calls and database queries, not CPU-heavy computation. Watch out for pinning inside long synchronized blocks in older JDKs, and don’t pool virtual threads.
4. What are records and sealed classes?
Records are concise, immutable data carriers with generated constructor, accessors, equals, hashCode and toString. Sealed classes restrict which classes can extend them. Combined with pattern matching for switch, the compiler can check that you have covered every case.
5. Explain the Java memory model basics and garbage collection.
Objects live on the heap, and each thread has its own stack. The G1 collector is the common default for server workloads, and JDK 27 makes G1 the default in all environments (JEP 523). Know the difference between minor and major collections, and how to read GC logs at a basic level.
6. Other frequent core Java topics
- String immutability and the string pool
- Checked versus unchecked exceptions; try-with-resources
- Streams: intermediate versus terminal operations,
mapversusflatMap, collectors ComparableversusComparatorvolatile,synchronized, the executor framework andCompletableFuture- Immutable classes and defensive copying
Spring and Spring Boot questions
7. What does @SpringBootApplication do?
It combines @Configuration, @EnableAutoConfiguration and @ComponentScan. Auto-configuration sets up beans based on the classpath and properties, and you can override any of them.
8. Constructor injection versus field injection?
Prefer constructor injection. It makes dependencies explicit, supports immutable final fields and makes unit testing easier without a Spring context.
9. Explain bean scopes.
Singleton (the default, one per container), prototype (a new instance per request for the bean), and web scopes such as request and session. Injecting a prototype into a singleton needs care: use a provider or lookup method.
10. How does @Transactional work, and when does it fail?
Spring creates a proxy that starts and commits or rolls back a transaction around the method. Common pitfalls:
- Self-invocation: a call from another method in the same class bypasses the proxy.
- By default, only unchecked exceptions trigger rollback.
- Putting the annotation on private methods has no effect with proxy-based AOP.
11. What is the N+1 problem in JPA and how do you fix it?
Loading a list of entities and then lazily loading each one’s association triggers one query plus N more. Fix it with fetch joins, entity graphs, batch fetching, or DTO projections designed for the use case.
12. How do you handle exceptions globally in a REST API?
Use @RestControllerAdvice with @ExceptionHandler methods that return consistent error responses. Spring’s ProblemDetail support follows the RFC-standard problem format for errors.
13. How do you secure a Spring Boot API?
Use Spring Security with a stateless JWT or OAuth2 resource-server setup. Configure authorisation rules per endpoint, hash passwords with BCrypt, and validate inputs. Never log tokens or secrets.
14. What is new in Spring Boot 4.1?
According to InfoQ’s coverage, Spring Boot 4.1 adds gRPC auto-configuration, SSRF mitigation for HTTP clients, lazy datasource connections, automatic context propagation for @Async methods and better OpenTelemetry support. It keeps a Java 17 baseline.
Microservices questions
15. When should you not use microservices?
For small teams, early-stage products or simple domains. A well-structured modular monolith is often faster to build and easier to operate. Microservices bring network failures, distributed data and operational overhead.
16. How do services communicate?
Synchronously over REST or gRPC, or asynchronously through messaging such as Kafka or RabbitMQ. Use asynchronous events when you need to decouple services and absorb spikes in load.
17. How do you handle a failing downstream service?
Use timeouts, retries with backoff, circuit breakers (for example Resilience4j), bulkheads and fallbacks. Make retried operations idempotent.
18. How do you keep data consistent across services?
Avoid distributed transactions. Use the saga pattern, either orchestrated or choreographed, with compensating actions. Use the transactional outbox pattern so database changes and published events stay in sync.
19. What is an API gateway?
A single entry point that handles routing, authentication, rate limiting and aggregation. Spring Cloud Gateway is a common choice in Java stacks.
20. How do you debug a request that spans many services?
Use distributed tracing with OpenTelemetry, propagate correlation IDs, use centralised logging, and track metrics such as latency percentiles and error rates.
How to prepare in four weeks
| Week | Focus |
|---|---|
| 1 | Core Java: collections, concurrency, Java 21 features; write small programs |
| 2 | Spring Boot: REST, JPA, transactions, security; build or refresh one API |
| 3 | Microservices: messaging, resilience, sagas, observability; add Kafka to your project |
| 4 | Mock interviews, project deep-dive answers and DSA revision |
Frequently asked questions
Do interviewers ask about Java 25 features?
Some do, but Java 21 features (virtual threads, records, pattern matching, sequenced collections) come up far more often. Knowing what Java 25 added, such as scoped values and flexible constructor bodies, is a bonus.
Should I say I know Spring Boot 4 if my project uses Spring Boot 3?
Be honest. Say you work on Spring Boot 3 and have explored version 4’s changes. Interviewers value accuracy, and they often ask follow-up questions.
How many microservices questions should a fresher expect?
Freshers usually get basic questions: what microservices are, REST versus messaging, and simple trade-offs. Deep questions on sagas and resilience are more common for candidates with two or more years of experience.
Official sources
- OpenJDK: JDK 21
- OpenJDK: JDK 25
- Oracle Java SE Support Roadmap
- Spring blog: Spring Boot 4.1.0 available now
- InfoQ: Spring Boot 4.1 features
- endoflife.date: Spring Boot
- Inside.java: JDK 27 available

Leave a Reply