What is Diff. Between Final, Finally, finalized?

1). Final

In Java, Final keyword is modifiers for Class, Method, Variable.
if final class is define so you can't extend a class.
if final method is, so you can't override method.
if final variable , so variable is like constant. no one can change as constant.

2). Finally 

In Java, Finally is a Block. always associated with the try catch block.

ex. try{
            //risky code.....
           - - - -
           - - - -  
           }catch(exception e){
                - - - - 
               //for handling code
           }
           finally{
            //for clean up....
           }

is clean up like , can you close up database connection...


3). Finalized

In Java, Finalized is method. Present in class. which class? is object class.
so, who is called finalized method?
When create object then the garbage collector pointing to the object.garbage collector is destroy your object or unnecessary memory assigning to the object. so object may destroy because garbage collector is job like destroying object. so you need to  clean up garbage collector. and that want to use finalized method to clean up garbage collector. 

ex. obj.finalized(){
              //clean up activity
      }
- - - - - - - - - - - - 

Definition : Finalized() is method which is always invoked by garbage collector just before destroying an object to perform a clean up activity. 

- - - - - - - - - - - - 

so, you people may arise question is finally or finalized() is same work is clean up activity. so what is different between?
finally is use always with try catch block. and finalized is method is always related to the object.



Comments