Difference between finally and finalize - Coddicted

Difference between finally and finalize

finally block is used in exception handling.

    //code that may or may not throw exception, goes here
catch(Exception e)
    //handling exception
    //Code goes here
The finally block executes after a section of code in a method. For example, if you have code that might throw an exception, the finally block executes whether the exception is thrown or not. It is guaranteed to run.
The finalize method is supposed to be called before an object is garbage collected. It is not guaranteed to be called in that an object might not be garbage collected.
source: coderanch
Rate this post

Leave a Reply