JavaIntermediate#exceptions

What are checked vs unchecked exceptions?

Checked exceptions extend Exception (not RuntimeException) and must be declared or handled — e.g., IOException. Unchecked extend RuntimeException — e.g., NullPointerException — and are not enforced by the compiler.

Example
void readFile() throws IOException { // checked, must declare
  new FileReader("a.txt");
}
int[] arr = new int[2];
arr[5] = 1; // ArrayIndexOutOfBoundsException, unchecked

Related Questions

1
JavaBeginner#strings

What is the difference between String, StringBuilder, and StringBuffer?

Open
2
JavaIntermediate#strings

Why are Strings immutable in Java?

Open
3
JavaIntermediate#collections

Explain the Collections framework hierarchy.

Open