Java interview questions

5 questions across 4 topics, ordered by how often they actually come up.

Starting Java from scratch?

The roadmap is the full path from your first program to senior-level judgement — what to learn in what order, and something to build at the end of every stage.

Open the Java roadmap →

By years of experience

By level

By what changed in which version

Collections

2 entries
  • How does HashMap work internally?

    A lazily-created array of buckets indexed by a spread hash; collisions chain into a linked list that becomes a red-black tree only when the bin holds 8+ nodes AND the table is at least 64 slots.

    Asked constantlyintermediate1–8 yrs9 min read
  • When would you use LinkedList instead of ArrayList?

    Almost never. LinkedList only wins at the ends of the list, and when you need that you want ArrayDeque instead. Its famous advantage — cheap mid-list insertion — is 23x slower than ArrayList on real hardware, because you must walk to the index first.

    Asked constantlyintermediate0–8 yrs9 min read

Exceptions

1 entry
  • What is the difference between checked and unchecked exceptions?

    Checked exceptions are enforced by the compiler; unchecked ones are not. The interesting question is not the definition but why every major Java framework since 2004 has moved to unchecked exceptions — and lambdas finished the argument in Java 8.

    Asked constantlyintermediate0–8 yrs10 min read

Oop

1 entry
  • What is the contract between hashCode() and equals()?

    Equal objects must return the same hash code. Unequal objects are free to collide — that is legal and normal, not a bug. Break the first rule and hash-based collections lose your data silently.

    Asked constantlyintermediate1–8 yrs8 min read

Strings

1 entry
  • Why is String immutable, and what is the string pool?

    String is immutable because nothing in its API exposes a mutator — not because its byte[] field is final. The pool is a JVM-wide cache of literals that makes == accidentally work on literals and fail everywhere else.

    Asked constantlyintermediate0–8 yrs9 min read