Finally block in java

Using Finally in java

The Finally block is used with a try{}catch block to execute a group of statements if an exception is occured or not. The finally block is used to close connections, close files, etc...

public class FinallyBlock {

    public static void main(String args[]) {
        try {
            // This throw NullPointerException
            String nullStr = null;
            nullStr.toLowerCase();

        } catch (Exception e) {
            // Catch exceptions
            System.out.println(e);
        } finally {
            System.out.println("I'm executed no matter what happens");
        }
    }

}