A finally block runs after the try and catch blocks, no matter what happened. It runs if the try succeeds. It runs if an exception is caught. It even runs if an exception is not caught and is about to propagate up.
try {
System.out.println("try");
} catch (Exception e) {
System.out.println("catch");
} finally {
System.out.println("finally");
}
You use finally for cleanup work that must happen regardless of success or failure. Closing a file, releasing a database connection, or resetting a shared variable are all common uses. Without finally, you would need to duplicate that cleanup code in both the try and catch blocks.