Java Interview Question

What is the difference between checked and unchecked exceptions?

Updated 2026-07-10 · Beginner friendly
Quick answer

Checked exceptions are checked by the compiler, so you must either catch them or declare them with throws, and they usually represent recoverable problems like a missing file. Unchecked exceptions extend RuntimeException, are not checked at compile time, and usually represent programming bugs like a null pointer or an array index out of bounds.

Checked exceptions

These are conditions your program should anticipate and handle, such as a file not being found. The compiler forces you to deal with them, which is why you see try catch or a throws clause.

// Must handle or declare
void read() throws IOException {
    Files.readString(Path.of("data.txt"));
}

Unchecked exceptions

These extend RuntimeException and usually mean a bug in the code. The compiler does not force you to handle them, since the right fix is to correct the code, not to catch the error.

int[] a = new int[2];
int x = a[5];   // ArrayIndexOutOfBoundsException, unchecked
In the interview

A crisp answer is checked for recoverable situations the compiler forces you to handle, unchecked for programming errors that extend RuntimeException. Giving one example of each, like IOException and NullPointerException, seals it.

Want the full Java guide?

Read every Java concept with notes, diagrams, and code in one place. Track your progress as you go.

Open the Java guide All Java questions