Core Java fundamentals questions

"What is the difference between an abstract class and an interface in Java?" An abstract class can have state (fields), constructor logic, and both abstract and concrete methods. An interface (since Java 8) can have default and static methods but no state. A class can implement multiple interfaces but extend only one abstract class. Use abstract classes when you have shared implementation to inherit; use interfaces to define a contract that unrelated classes can fulfill.

"Explain the Java memory model and the difference between the stack and heap." The heap stores all objects and is shared across threads. The stack stores local variables and method call frames and is thread-local. Primitives on the stack are not shared. Objects on the heap are shared and require synchronisation for safe concurrent access. Garbage collection runs on the heap. Stack overflow occurs with infinite recursion; heap OutOfMemoryError occurs when the heap is exhausted.

Concurrency and threading questions

"What is the difference between synchronized, volatile, and AtomicInteger?" synchronized provides mutual exclusion: only one thread executes the block at a time, and it establishes happens-before guarantees. volatile ensures reads and writes are visible across threads without caching, but does not provide atomicity for compound operations like increment. AtomicInteger provides lock-free atomic operations (compare-and-swap), faster than synchronized for simple counters.

"What is a thread pool and why use one?" A thread pool maintains reusable worker threads, avoiding the overhead of creating and destroying threads per task. Benefits: bounded resource usage, reduced per-task latency, easier lifecycle management. Creating a new Thread per task can exhaust system resources under high load.

Spring Framework questions

"Explain dependency injection and how Spring implements it." Dependency injection means a class receives its dependencies from outside rather than creating them itself. Spring's IoC container instantiates beans and injects them via constructor injection (preferred), setter injection, or field injection. Constructor injection makes dependencies explicit and enables immutability.

"What is the difference between @Component, @Service, @Repository, and @Controller?" All four trigger Spring bean registration. The differences are semantic: @Repository enables exception translation. @Controller marks MVC controllers. @Service marks business logic. @Component is the generic fallback. Using the right annotation makes intent clearer.

How to prepare

Cover modern Java features: generics, Stream API, lambdas, Optional, records (Java 16+), sealed classes (Java 17+), and virtual threads via Project Loom (Java 21). For Spring roles, build a complete REST API with Spring Boot, Spring Data JPA, and Spring Security. Know the standard design patterns you have used in production (Builder, Strategy, Observer) with real examples. For algorithm rounds, clean Java syntax under pressure requires practice: list comprehensions do not exist in Java, so know the idiomatic equivalents.

Get real-time help in your next interview
Live Interview Help listens to your interview and surfaces personalised answers in real time. Free 20-minute trial on Google Meet, Teams, and Zoom.
Install Free on Chrome

Frequently asked questions

Is Java still in demand for backend development in 2026?
Yes. Java remains one of the most widely used backend languages, particularly in financial services, enterprise software, and large-scale web services. Spring Boot dominates enterprise Java. The job market for experienced Java developers is strong and salaries are competitive with other backend languages.
What Java version should I target in 2026?
Java 21 (LTS) is the recommended target for new projects. It introduced records, sealed classes, pattern matching for switch, and virtual threads via Project Loom. Many production systems still run Java 8 or 11; knowing the migration path and key differences between versions is useful interview knowledge.