Unchecked exceptions extend RuntimeException—compiler does not force handling (NullPointerException, IllegalArgumentException). Checked exceptions extend Exception (but not RuntimeException)—callers must catch or declare with throws.
Checked example
void readFile() throws IOException {
// ...
}
Design guidance
Use checked exceptions for recoverable, expected failures callers should handle. Many modern APIs prefer unchecked exceptions for cleaner code—Spring and many libraries lean runtime exceptions for non-recoverable programming errors.
Important interview questions and answers
- Q: Why checked exceptions exist?
A: Force explicit handling of recoverable conditions at compile time—debated in modern Java style. - Q: Is NullPointerException checked?
A: No—it is unchecked (RuntimeException subclass).
Self-check
- What keyword declares a method may throw an exception?
- Name one checked and one unchecked exception.