Interview Q&A / Java
Java interview questions
Collections, the JVM, strings, exceptions and threads, the backbone of most campus placement rounds.
Prefer rapid revision? Practise Java short interview answers →
- In what order should catch blocks be written, and what is multi-catch in Java?
Catch blocks are checked top to bottom, so subclasses must come before their parents or the code will not compile. Multi-catch uses a pipe to handle several unrelated exceptions in one block.
IntermediateQuick answer1 min read - What does a Java method return when both try and finally contain a return?
The finally block runs before the method actually returns, and a return inside finally overrides the earlier one, so the finally value wins. If finally only changes a variable, a primitive value already chosen for return is not affected.
IntermediateQuick answer1 min read - What is exception chaining in Java and why keep the cause?
Exception chaining wraps a low-level exception inside a higher-level one using the cause argument, so callers get a meaningful message and the stack trace still shows the original failure through getCause().
IntermediateQuick answer1 min read