Computer >> Computer tutorials >  >> Programming >> Java

Difference Between Final, Finally and Finalize in Java


In this post, we will understand the difference between ‘Final’, ‘Finally’, and ‘Finalize’ in Java.

Final

  • It is a keyword.

  • It is used to apply restrictions on classes, methods and variables.

  • It can’t be inherited.

  • It can’t be overridden.

  • Final methods can’t be inherited by any class.

  • It is needed to initialize the final variable when it is being declared.

  • Its value, once declared, can’t be changed or re-initialized.

Finally

  • It is a block.

  • It is used to place important code in this block.

  • It gets executed irrespective of whether the exception is handled or not.

Finalize

  • It is a method.

  • It is used to perform clean up processing right before the object is collected by garbage collector.