Exceptions, I/O and Concurrency Basics
Harry
· 16 Sep 2026
· 11 views
Log in to track your progress and mark lessons complete.
Sponsored
Exceptions
Know the hierarchy and the rules:
- Checked exceptions (
IOException) must be caught or declared. - Unchecked exceptions (
RuntimeExceptionand subclasses likeNullPointerException) need not be. finallyruns whether or not an exception was thrown; catch blocks must be ordered most-specific first.
try (var reader = new BufferedReader(new FileReader("f.txt"))) {
return reader.readLine(); // try-with-resources auto-closes
} catch (IOException e) {
return "error";
}
Try-with-resources
Any resource implementing AutoCloseable can go in the try(...) header and is closed automatically – the exam expects you to recognise this pattern.
Concurrency basics
You should understand creating threads, the Runnable interface, and why shared mutable state needs synchronisation:
Runnable task = () -> System.out.println("running");
new Thread(task).start();
Know that thread scheduling is not guaranteed and that synchronized / concurrent collections protect shared data.
Key points
- Checked exceptions must be handled or declared; unchecked need not be.
finallyalways runs; order catch blocks specific-to-general.- Try-with-resources auto-closes
AutoCloseableresources. - Understand threads,
Runnable, and why shared state needs synchronisation.