Interview Prep · Java 2026
Java Developer Interview Questions and FAQs 2026
Quick summary — Java interview prep 2026
Java interviews test both breadth and depth. You need solid foundations (OOP, collections, exceptions) plus real depth in concurrency and frameworks like Spring Boot. This guide covers the most-asked questions with clear answers.
In this guide you will learn:
- Core Java questions — OOP, JVM, strings, exceptions.
- Collections — List, Map, Set, HashMap internals.
- Multithreading — threads, executors, synchronization.
- Spring Boot — DI, REST, JPA basics.
- FAQs — common mistakes and how to answer.
SECTION 01Core Java questions
Every Java interview starts with the fundamentals. These are the most-asked core questions:
| Question | What Interviewers Test | What to Study |
|---|---|---|
| OOP concepts | Encapsulation, inheritance, polymorphism, abstraction | Real examples from projects |
| JVM architecture | Classloader, memory areas, GC basics | JVM diagram + GC |
| String vs StringBuilder | Mutability, performance, immutability | String pool + use cases |
| equals() and hashCode() | Contract, hashmap usage | Implementation + examples |
| Exception handling | Checked vs unchecked, try-with-resources | Best practices |
| Immutable classes | How to design, why useful | final fields, defensive copy |
// The equals() and hashCode() contract
// — MUST be consistent for HashMap to work.
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass())
return false;
User user = (User) o;
return Objects.equals(email, user.email);
}
@Override
public int hashCode() {
return Objects.hash(email);
}
// Interview tip:
// If equals() is overridden, hashCode() MUST be too.
// Otherwise HashMap lookups fail.
// Immutable class example
public final class Money {
private final BigDecimal amount;
private final String currency;
public Money(BigDecimal amount, String currency) {
this.amount = amount;
this.currency = currency;
}
public BigDecimal getAmount() {
return amount;
}
public String getCurrency() {
return currency;
}
// no setters
// final class → no subclass override
// final fields → can't be reassigned
}
// Interview tip:
// Immutability is the foundation of thread safety.
// Java's String, Integer, LocalDate are all immutable.
SECTION 02Collections questions
Collections are tested heavily — especially HashMap internals. Learn these deeply:
| Question | What Interviewers Test | What to Study |
|---|---|---|
| HashMap internals | Buckets, hashing, collision, resizing | Internal working diagram |
| ArrayList vs LinkedList | Time complexity, use cases | When to use which |
| HashMap vs Hashtable | Thread-safety, nulls | Legacy vs modern |
| ConcurrentHashMap | Segmented locking | Thread-safe Map internals |
| Comparator vs Comparable | Sorting, multiple sort orders | compareTo vs compare |
| Streams API | Filter, map, reduce, collectors | Practical examples |
// HashMap internals — interview favourite
// 1. Bucket array (default 16 buckets)
// 2. Key hashed → bucket index = hash & (n-1)
// 3. Collisions handled via linked list
// 4. After 8 entries in one bucket → converts
// to Red-Black tree for O(log n)
// 5. Load factor 0.75 → resize (double) when
// 75% full
// Common questions:
// - Why is HashMap fast? O(1) average
// - Why 16 initial size? power of 2 for mask
// - What if two keys collide?
// Same bucket, list or tree
// - When does resize happen?
// At 75% capacity
Map<String, Integer> counts = new HashMap<>();
counts.merge("java", 1, Integer::sum);
// Streams API — commonly asked
List<String> names = List.of("Amit", "Priya", "Raj");
// Filter + map + collect
List<String> longNames = names.stream()
.filter(n -> n.length() > 3)
.map(String::toUpperCase)
.collect(Collectors.toList());
// Group + count
Map<Integer, Long> byLength = names.stream()
.collect(Collectors.groupingBy(
String::length,
Collectors.counting()
));
// Interview tip:
// Be ready to explain WHY you chose
// stream vs loop — readability matters,
// but so does performance.
SECTION 03Multithreading questions
Concurrency separates mid-level from senior developers. Expect deep questions:
| Question | What Interviewers Test | What to Study |
|---|---|---|
| Thread lifecycle | States, transitions | NEW, RUNNABLE, etc. |
| synchronized vs volatile | Memory visibility, atomicity | Happens-before |
| ExecutorService | Thread pools, submit vs execute | Pool sizing |
| Deadlock | Detection, avoidance | Lock ordering |
| CompletableFuture | Async, chaining | Modern async |
| Concurrent collections | ConcurrentHashMap, CopyOnWriteArrayList | When to use which |
// ExecutorService — modern thread management
ExecutorService pool = Executors.newFixedThreadPool(4);
// Submit returns a Future
Future<Integer> result = pool.submit(() -> {
Thread.sleep(100);
return 42;
});
// Get with timeout — avoid infinite waits
int value = result.get(2, TimeUnit.SECONDS);
pool.shutdown();
pool.awaitTermination(5, TimeUnit.SECONDS);
// Interview tip:
// Always explain:
// - why a pool (avoid thread creation cost)
// - how you sized it (CPU/IO-bound)
// - how you handle shutdown
// CompletableFuture — modern async
CompletableFuture<String> userFuture =
CompletableFuture.supplyAsync(() -> fetchUser(id));
CompletableFuture<List<Order>> ordersFuture =
CompletableFuture.supplyAsync(() -> fetchOrders(id));
// Combine two async results
CompletableFuture<String> combined =
userFuture.thenCombine(ordersFuture, (user, orders) ->
user + " has " + orders.size() + " orders"
);
// Exception handling
String response = combined
.exceptionally(ex -> "Error: " + ex.getMessage())
.join();
// Interview tip:
// Show you understand chaining vs blocking.
// "thenCombine runs in parallel" is a strong answer.
SECTION 04Spring Boot questions
Most modern Java roles involve Spring Boot. Here are the standard questions:
| Question | What Interviewers Test | What to Study |
|---|---|---|
| Dependency Injection | Why DI, bean lifecycle | Constructor vs field injection |
| Spring Boot auto-config | How it works | @EnableAutoConfiguration |
| REST API design | Best practices | Status codes, idempotency |
| JPA & Hibernate | N+1, lazy loading | Fetch strategies |
| Transaction management | @Transactional | Propagation, rollback |
@RestController
@RequestMapping("/api/orders")
public class OrderController {
private final OrderService service;
// Constructor injection — preferred
public OrderController(OrderService service) {
this.service = service;
}
@GetMapping("/{id}")
public ResponseEntity<Order> get(@PathVariable Long id) {
return service.findById(id)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@PostMapping
public ResponseEntity<Order> create(@RequestBody Order order) {
Order saved = service.save(order);
return ResponseEntity.status(201).body(saved);
}
}
// Interview tip:
// Explain WHY constructor injection
// (immutability, testability).
// N+1 problem — a classic interview topic
// BAD — N+1 queries
List<Order> orders = orderRepo.findAll();
for (Order o : orders) {
// One query per order — slow
o.getCustomer().getName();
}
// GOOD — fetch join
@Query("""
SELECT o FROM Order o
JOIN FETCH o.customer
""")
List<Order> findAllWithCustomer();
// Or use @EntityGraph
// Interview tip:
// "How do you avoid N+1?" is almost
// guaranteed in Spring Boot interviews.
// @Transactional — what to explain
@Service
public class PaymentService {
@Transactional
public void transfer(Long from, Long to, BigDecimal amt) {
accountRepo.debit(from, amt);
accountRepo.credit(to, amt);
// if credit fails, debit rolls back
}
}
// Interview points:
// - Default propagation: REQUIRED
// - Rollback on RuntimeException by default
// - Does NOT rollback on checked exceptions
// (unless rollbackFor specified)
// - Proxy-based — self-invocation bypasses it
SECTION 05FAQs & common mistakes
Here are the most common mistakes that cost candidates job offers:
Common mistakes in Java interviews:
□ Memorising definitions — no depth
□ Not knowing why equals/hashCode must be
consistent
□ Confusing HashMap with Hashtable
□ Not understanding HashMap internals
□ Ignoring thread safety when using collections
□ Not knowing why N+1 is bad
□ Confusing @Component with @Bean
□ Not being able to explain DI benefits
□ Trying to memorise stream syntax without
understanding when to use streams
□ Giving "it depends" without specifics
Every mistake above can be fixed by
preparing with real examples.
How to answer well:
Structure:
1. Direct answer — 1 sentence
2. Simple example
3. Real-world context (project / scale)
Example — "What is HashMap?"
Weak: "HashMap is a Map implementation."
Strong: "HashMap is a Map that uses hashing
to give O(1) average lookups. It stores
entries in buckets indexed by key hash,
handles collisions via lists that become
trees after 8 entries. I use it for
caching user sessions at work."
Structure beats memorisation.
Preparation tracker (per topic):
Topic: _________
□ Read fundamental
□ Wrote code example
□ Wrote 1 paragraph explanation
□ Practised out loud
□ Reviewed common pitfalls
Next topic:
1.
2.
SECTION 06Interview Q&A practice
Q1What is the difference between == and equals() in Java?
== checks reference equality (same object).
equals() checks logical equality (can be overridden
to compare content). For primitives, == compares
values.
Q2Why is String immutable in Java?
Immutability provides security (safe as HashMap keys), thread-safety (no synchronization needed), caching (String pool), and easier reasoning. It's a deliberate design choice.
Q3What is the difference between ArrayList and LinkedList?
ArrayList uses an array — O(1) random access, O(n) insert/delete in middle. LinkedList uses nodes — O(n) access, O(1) insert/delete when the position is known. Use ArrayList unless you frequently insert/delete in middle.
Q4How does HashMap handle collisions?
Collisions are stored as a linked list in the bucket. If a bucket exceeds 8 entries, it converts to a Red-Black tree for O(log n) lookup. When the map exceeds its load factor (0.75), it resizes (doubles).
Q5What is dependency injection?
DI is a pattern where an object receives its dependencies from outside rather than creating them itself. Spring uses DI to decouple components — improving testability, flexibility, and clarity. Constructor injection is preferred.
Q6What is the N+1 problem in JPA?
Fetching a list of entities triggers one query, then one query per entity's lazy-loaded relation — so N+1 total. Fix with fetch joins or @EntityGraph.
Q7How do you avoid deadlocks?
Acquire locks in a consistent order, use timeouts (tryLock), avoid nested locks, and keep critical sections small. Use higher-level utilities (ExecutorService, ConcurrentHashMap) instead of manual synchronization where possible.
SECTION 07Test yourself — Java interview quiz
Five questions. No sign-up.
0 / 5Pick an answer to see why it is right or wrong.
SECTION 08Frequently asked questions
What topics are most important for Java interviews?
Core Java (OOP, exceptions, strings), collections (especially HashMap internals), concurrency (threads, executors), and Spring Boot (DI, JPA, transactions) for backend roles.
Do I need to know Spring Boot for Java roles?
For most backend Java roles in 2026, yes. Spring Boot dominates the enterprise Java job market. Basics are usually required.
How much DSA do I need for Java interviews?
Depends on the company. Product companies ask DSA + coding challenges. Service companies focus more on core Java. Both benefit from basic DSA (arrays, strings, hashmaps).
What's the salary for a Java developer in 2026?
Entry-level: ₹4–8 LPA. Mid-level: ₹8–15 LPA. Senior: ₹15–30+ LPA. Product companies and fintech typically pay at the higher end.
How long should I prepare?
4–8 weeks of focused preparation (2 hours daily) covers fundamentals + Spring Boot + DSA basics. Longer if starting from zero.
SECTION 09Related reads
Classroom & online · Noida
Prepare for Java interviews
Our Data Analytics Training Course is designed to help you recover and rebuild — with skills, projects, and interview prep that get you hired.
₹15,500 · full programme- Core Java + Spring Boot
- Mock interviews
- DSA + problem solving
- Weekday & weekend batches