What is the difference between final, finally and finalize in Java?

NameKindMeaning
finalKeywordA constant variable, a method which can not be overridden, a class which can not be extended
finallyBlockRuns after try and catch, with or without an exception. For cleaning
finalize()MethodCalled by the GC before it removes an object. Deprecated for removal, do not use it

Use try with resources or a Cleaner instead of finalize().

public class Main {
    static int test() {
        try {
            return 1;
        } finally {
            System.out.println("finally runs, even after return");
        }
    }

    public static void main(String[] args) {
        final int limit = 10;
        System.out.println(limit + " " + test());
    }
}
Output

finally runs, even after return
10 1

See Java Exceptions.


Learn more about the similar topics:
Tutorials
Java Exceptions: try, catch, finally and throw
Exercises & Assignments
Create a custom exception for an invalid age
Interview Questions & Answers
What is an exception in Java? What are checked and unchecked exceptions?
What is the difference between final, finally and finalize in Java?
What is the difference between throw and throws in Java?
What are the best practices for exception handling in Java?