Loading
Finally and Finalize

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  What are Finally and Finalize Keywords ?


  • Finally and Finalize
    Sample Img 6

Ans)

final – constant declaration.

public static final String HOST_NAME = "yourhost":

finally – The finally block always executes when the try block exits, except System.exit(0) call.
This ensures that the finally block is executed even if an unexpected exception occurs. But finally is useful for more than just exception handling —
it allows the programmer to avoid having cleanup code accidentally bypassed by a return, continue, or break. Putting cleanup code in a finally
block is always a good practice, even when no exceptions are anticipated.

try {
} finally {
   out.close();
   conn.close();
}

 
finalize() – method helps in garbage collection. A method that is invoked before an object is discarded by the garbage collector,
allowing it to clean up its state. Should not be used to release non-memory resources like file handles, sockets,
database connections etc because Java has only a finite number of these resources and you do not know when the garbage collection
is going to kick in to release these non-memory resources through the finalize() method.



Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

Finally and Finalize


Finally and Finalize

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



Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free