Thursday, July 5, 2012

Study about Final Finally finalize in Java


The complete detaile study of Java Final ,Finally and Finalize key words.


Final 
Final is the key word in Java and it can be added before variable method and class as well.


Final Variable
if the final keyword added for variable the variable can become constant.


Example:


Inside the program if user try to change the a value as 20 it will through an exception.


Final method
if the method has declared with final keyword it can not be override.


Final class
if the class has declared with final keyword the class will hot be inherited which means it cant be sub classed.


Finally 
Finally is the keyword in Java.Finally always used along with Try catch. Finally is used when the exceptions caught or not still Finally will be executed. The purpose of finally key word is always it will execute along with try block even thought exception is caught or not.


Example 






This program explained like here always i want to execute some information along with try block or user needs to confirm my try block executed successfully.


Finalize


Java does not have destructor this job will taken care by garbage colletor.Garbage collector will do cleanup process periodically if the object no longer called by any thread. when the periodically clean up the object at the time finalize method will be called by Garbage collector.But no body sure when the garbage collector called the finalize method. This works with mark and sweep algorithm.

No comments:

Post a Comment