What is the difference between final, finally, and finalize in Java?
These three sound similar but are unrelated. final is a keyword that makes a variable constant, a method not overridable, or a class not extendable. finally is a block that always runs after a try and catch, used for cleanup. finalize was a method called before an object was garbage collected, and it is now deprecated and should not be used.
final: prevents change
final int MAX = 100; // cannot be reassigned
final class Config {} // cannot be extended
finally: always runs
A finally block runs whether or not an exception was thrown, which makes it perfect for releasing resources like files or database connections.
try {
// risky work
} catch (Exception e) {
// handle
} finally {
// always runs, close resources here
}
finalize: deprecated cleanup hook
finalize was meant to run before an object was collected, but it was unreliable and is now deprecated. Modern code uses try with resources or explicit close methods instead.
Interviewers ask this to test attention to detail. Answer each in one line and stress that finalize is deprecated and you would never rely on it, which shows you know current best practice.
Common follow up questions
Related interview questions
Want the full Java guide?
Read every Java concept with notes, diagrams, and code in one place. Track your progress as you go.
Open the Java guide All Java questions