What is the difference between HashMap and Hashtable?
Both implement Map, but they target very different needs.
HashMap — not synchronized, allows one null key and many null values, faster. The default for single-threaded use.
Hashtable — synchronized (legacy), no nulls, slower. Considered obsolete; use ConcurrentHashMap for thread-safe maps.
Iteration — HashMap iterators are fail-fast; Hashtable's old
Enumerationis fail-safe but considered legacy.
Always recommend ConcurrentHashMap over Hashtable for thread safety. Know the null handling difference (HashMap allows null key, Hashtable does not).
The internal implementation differences (segment locking vs method locking) show deep knowledge.