Java Interview Questions That Still Matter for Backend and Platform Roles

Stackademic

Core Java topics interviewers probe—memory model, collections, concurrency, JVM basics, and how to answer with working examples.

Java still shows up in backend interviews because the JVM ecosystem powers large payment, logistics, and data platforms. Interviewers rarely ask trick puzzles; they probe whether you understand how the language behaves under load and how you would debug production issues.

How Java interviews are structured today

Most loops combine:

  • Language fundamentals — types, generics, equals/hashCode, exceptions
  • Collections and streams — when to use which structure, performance traps
  • Concurrency — threads, pools, java.util.concurrent, common bugs
  • JVM and memory — heap vs stack, GC basics, profiling mindset
  • Framework awareness — Spring Boot lifecycle at a high level (not annotation trivia)

Below are question themes that recur, with what a strong answer sounds like.

Core language and OOP

Explain == vs equals() in Java

== compares references for objects (and values for primitives). equals() compares logical equality when properly overridden. For strings, always compare content with equals() because string literals may be interned but dynamically created strings are not guaranteed to share references.

Mention that overriding equals() requires consistent hashCode() for hash-based collections.

Why are strings immutable?

Immutability enables string pooling, safer sharing across threads, and stable hash codes for map keys. It also avoids subtle bugs when strings are passed through security-sensitive APIs (file paths, class names).

Checked vs unchecked exceptions

Checked exceptions must be declared or handled (IOException). Unchecked extend RuntimeException and represent programming bugs or unrecoverable states (NullPointerException). In modern APIs, teams often wrap checked exceptions in runtime exceptions at boundaries to avoid leaking implementation details—be ready to discuss trade-offs, not dogma.

Collections you must know cold

StructureTypical useWatch out for
ArrayListRandom access, append-heavyInsert/remove in the middle is O(n)
LinkedListRare; queue/deque scenariosPoor cache locality
HashMapKey-value lookupsHash collisions, load factor, not thread-safe
ConcurrentHashMapShared mapsSize/compute methods have specific semantics
TreeMapSorted keysO(log n) operations
PriorityQueueTop-K, schedulingIterator order is not sorted

ArrayList vs LinkedList for a hot path

Default to ArrayList unless you have measured proof that linked nodes help. Interviewers want to hear about cache locality and amortized resizing, not big-O alone.

How does HashMap work internally?

Buckets backed by array; keys hashed; collisions handled with linked lists or trees (treeify after a threshold in modern JDKs). Mention capacity, load factor, and rehashing when the table grows.

Generics and type erasure

What is type erasure?

Generic type parameters are removed at compile time. At runtime, List<String> and List<Integer> share the same class. This enables backward compatibility but limits reflective access to generic types.

Why can't you do new T()?

Because T is not reified at runtime. Patterns include factories, Supplier<T>, or explicit Class<T> parameters.

Concurrency questions that separate levels

synchronized vs ReentrantLock

Both provide mutual exclusion. synchronized is simpler and JVM-managed. ReentrantLock offers try-lock, timeouts, and fair ordering at the cost of verbosity. Prefer higher-level constructs (ConcurrentHashMap, atomic classes) before raw locks.

What is a thread pool and why use one?

Creating threads per request does not scale. Pools bound concurrency, reuse workers, and queue excess tasks. Be ready to name risks: unbounded queues hiding overload, deadlocks when pool size is too small for chained tasks.

volatile vs synchronized

volatile guarantees visibility and ordering for a single field, not compound atomicity. It is appropriate for status flags, not for incrementing counters—use AtomicInteger instead.

Common concurrency bug example

private int count = 0;

public void increment() {
  count++; // not atomic: read-modify-write
}

Fix with AtomicInteger or synchronized blocks—explain lost updates under contention.

JVM, memory, and performance

Heap vs stack

Stack frames hold local variables and call metadata per thread. Heap stores objects. Interviewers want you to connect this to GC pressure: short-lived objects are cheap in generational collectors; long-lived caches change tuning needs.

What triggers OutOfMemoryError?

Besides heap exhaustion: metaspace (class loading), direct buffers, thread creation. Mention you would inspect heap dumps and GC logs before blindly raising -Xmx.

How would you profile a slow endpoint?

  1. Measure p95 latency and error rate in APM.
  2. Capture thread dumps if CPU is pegged.
  3. Use async profiler or JFR for hot methods.
  4. Check DB query plans and pool exhaustion.

You do not need to cite specific tools—show a methodical path.

Modern Java features worth mentioning

  • Records for immutable data carriers (Java 16+).
  • Sealed classes to model restricted hierarchies.
  • Pattern matching for switch to reduce boilerplate.
  • Virtual threads (Project Loom) for high concurrency with blocking code—know the use case (many blocking I/O tasks), not every limitation.

Spring Boot (high level)

Expect questions like “What happens when a Spring Boot app starts?” Touch on component scanning, auto-configuration, embedded server startup, and dependency injection of beans. Avoid reciting every annotation—explain how configuration properties bind to typed classes and how you would structure layers (controller → service → repository).

Coding exercise themes

Practice implementing or explaining:

  • LRU cache (linked hash map or doubly linked list + map)
  • Producer-consumer with blocking queue
  • Rate limiter (token bucket)
  • Merge sorted iterators/streams
  • Serializable deep copy pitfalls

Always state time and space complexity and mention tests you would write.

Behavioral pairing

When a question touches production, connect to experience:

  • “We saw GC pauses correlate with a cache warm-up job; we moved warm-up off-peak and switched to G1 with explicit heap sizing.”
  • “We eliminated duplicate submits with an idempotency key stored in Redis with TTL.”

Even sample projects benefit from this framing.

FAQ

Is Java still relevant with Kotlin and Go rising?
Yes for large enterprise backends, Android, and teams invested in JVM tooling. Interviews reflect maintenance and scale challenges more than hype cycles.

Should I memorize Big-O for every JDK method?
Know the major structures. For obscure methods, reason from implementation principles.

How deep should GC knowledge go?
Understand generational hypothesis, stop-the-world pauses, and when tuning helps vs when code changes help.

Do interviewers expect design patterns by name?
Helpful for factory, strategy, and builder in API design. Do not force patterns where simple functions suffice.

How do I handle a question I do not know?
Outline how you would learn it in production: docs, JDK source, small reproducer, mentor review.

Mock interview week plan

DayFocusActivity
MonCollections + streamsImplement groupingBy on sample orders
TueConcurrencyFix a broken counter with atomics
WedJVMInterpret a sample GC log snippet
ThuSpringWalk through request lifecycle aloud
FriMixed45-minute timed loop with a peer

Repeat until you can explain why the JDK chose a data structure, not only what it does.

Strong Java interview answers blend precise language behavior with production instincts: measure first, choose the simplest structure that meets constraints, and explain how you would validate the solution before shipping.