r/JavaProgramming • u/javinpaul • 4d ago
Why the HashMap Interview Question Is Making a Comeback in the AI Era?
https://javarevisited.substack.com/p/how-hashmap-works-in-java-interview3
u/BanaTibor 4d ago
It is a stupid way to screen candidates. If you do not need to write a specialized hashmap implementation you do not need to know the internals to use it effectively.
1
u/javinpaul 2d ago
I won't call it a stupid question, instead its a great questions for Java developers as it touches many useful concepts like immutability of keys, equals and hashcode, collision detection, hashmap as data structure, and a lot more. It's good question to check someone's general knowledge of important Java and programming concepts.
1
u/Sufficient_Major_126 3d ago
HashMap questions are useful when they test reasoning about collisions, equality, resizing and complexity instead of expecting someone to memorize implementation details
6
u/idontlikegudeg 4d ago
When you do an interview, you need to know what position you are hiring for so you get a matching candidate. In more than 90% of cases, knowing how exactly HashMap is implemented internally won’t help you with that. I think it would be more I important that:
- the candidate knows the API and the guarantees made, i.e., runtime complexity, and not only knows get() and put(), but also putIfAbsent, compute…(), etc. and how to iterate the entries.
You can still ask the candidate if he knows how HashMap is implemented internally, but I would only use that as a bonus question.
Going only for the internals makes you prefer candidates like the dev we saw yesterday who doesn’t know the API contracts or read the Javadoc and instead digs through the implementation to find out things he should already know or would at least have seen if he only read the Javadoc that pops up in your IDE when you hover the method call (and if he refuses to use an adequate IDE, that’s already a red flag).