It is a keyword used to declare constants, methods, and classes.
Once something is declared as final, it cannot be changed.
For variables: You cannot change the value once initialized.
For methods: You cannot override a final method in subclasses.
For classes: You cannot extend a final class.
final int number = 10; // number cannot be changed later
final class MyClass { } // cannot extend this class
final void show() { } // cannot override this method
2. finalize() method:
It is a method in the Object class.
Java calls finalize() just before an object is garbage collected.
It is used to clean up resources before the object is destroyed [DB connections closure].
You can override finalize() in your class to perform cleanup (e.g., closing files).
Example:
protected void finalize() throws Throwable {
System.out.println("Cleanup before object is garbage collected");
}