Java interview questions — 5 years experience
These are the questions a candidate with 5 years of experience gets asked. The same question is asked at many levels — what changes is how deep the follow-ups go, so read section 3 of each 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 readOopHow 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 readCollectionsWhen 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 readCollectionsWhy 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 readStringsWhat 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 readExceptions