☕ Java Beginner

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

Why Interviewers Ask This

This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex Java topics. It also reveals how well you can explain technical ideas to non-experts.

Answer

These three keywords are completely unrelated despite similar spelling. final is a modifier: makes a variable a constant, a method non-overridable, or a class non-inheritable. finally is a block in exception handling that always executes after the try-catch block — used for cleanup code (closing resources). finalize() is a method in the Object class that the garbage collector calls before an object is destroyed — it was meant for cleanup but is unreliable and deprecated since Java 9. Always use try-with-resources instead of finalize for resource cleanup, as the GC may never call finalize or may call it much later than expected.

Pro Tip

This topic has Java-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.