final, finally and finalize difference

Difference

  1. Definition: 
    1. final is a keyword used as an access modifier. It is used to apply restrictions on a class, object, methods or properties.
    2. finally is the Java block which is used with try catch blocks. This block executes whether a block of code throws an exception or not.
    3. finalize is a method of Java which is used to perform clean up processing just before an object is garbage collected.
  2. Application: 
    1. final is used with classes, objects, methods and properties.
    2. finally is used with try catch block for Exception handling.
    3. finalize is a method used with objects.
  3. Functionality:
    1. Once declared, final variables becomes constant and cannot be modified in future. final methods cannot be overridden even by a subclass. final class cannot be inherited.
    2. Codes written in finally block will execute anyhow, even if there is an exception or not. finally is also used the release the resources used by try catch block.
    3. finalize method is used for clean up process of an object which is garbage collected before the object is destroyed. finalize method is executed just before an object is destroyed.


Comments

Popular posts from this blog

Collections in Java

Exception Handling

OOPS Concept in Java