Exceptions, I/O and Concurrency Basics

Harry · 16 Sep 2026 · 11 views
Log in to track your progress and mark lessons complete.

Exceptions

Know the hierarchy and the rules:

  • Checked exceptions (IOException) must be caught or declared.
  • Unchecked exceptions (RuntimeException and subclasses like NullPointerException) need not be.
  • finally runs 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.
  • finally always runs; order catch blocks specific-to-general.
  • Try-with-resources auto-closes AutoCloseable resources.
  • Understand threads, Runnable, and why shared state needs synchronisation.
Share this post:

Comments (0)

Please login or register to comment.

Create a free account to keep reading

You've enjoyed a free tutorial! Register (it's free) to unlock every tutorial, track your progress and save code.

Already have an account? Log in