Difference between Final ,Finally and Finalize (java)
final - means immutable. eg: final classes, final methods, final variables.
once you say final, it is the final definition of that component, no one can change it.
finally - is used with try-catch block to make sure that you are cleaning all the system resources properly when an exception occurs.
what ever the code you write, will be executed with out fail once try block exits.
finalize - is the method that will be executed(called) before that object is being garbage collected.
Garbage collector will make sure that it will finalize() method of an object, before it cleans that object.
Garbage collector will clean only java resources and java memory. In your program if you are using any non java resources like files,
sockets, graphic contexts, or allocating memory using a c program then garbage collector will not clean all those resources.
It is the responsibility of the programmer to clean them properly, For that we use finalize method.
Note: Don't depend too much on finalize() method to clean non java resources.
Back To Top