Java
What gets asked
The Java questions that come up in nearly every round.
The Java interview is more predictable than almost any other part of the process. The same eight or nine things come up, and they come up because each one has a wrong answer that sounds right.
What follows is not a list to memorise. It is what each question is actually checking, which is the part that decides how you do.
The ones that always come up
"Difference between an interface and an abstract class." Since default methods arrived the mechanical differences shrank, so the honest answer is about intent: an interface is a capability something has, an abstract class is a partial implementation things share. If you only recite "a class can implement many interfaces", you have answered the 2010 version.
"What is the difference between == and .equals()?" Reference identity
against value equality. The follow-up is always about String, and the answer
involves the string pool: literals are interned and shared, new String("a") is
not, so == can be true for two literals and false for two objects holding the
same characters.
"Is Java pass by value or pass by reference?" Always pass by value. The subtlety is that when the value is a reference, you get a copy of the reference, so you can mutate the object it points at but reassigning the parameter does nothing outside the method. People who say "pass by reference for objects" are describing the right behaviour with the wrong words, and the interviewer is listening for exactly that.
"Why must you override hashCode when you override equals?" Because a
hash-based collection finds the bucket first and compares second. Get this one
right and it usually ends the topic.
"What does static actually mean?" It belongs to the class, not an instance.
The real follow-up is why a static method cannot use this, and whether static
state is safe across threads, which it is not.
"What is final?" Three separate meanings: a field that cannot be
reassigned, a method that cannot be overridden, a class that cannot be extended.
Note the first one does not make the object immutable, and
say so before they ask.
More on this is coming, and asking moves it up the list.
Want this written up?
Sign in and tell us. We write the ones people actually ask for, and asking takes one click.
Sign in to askOr sit with someone on it instead of waiting for us to write it.