GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE
Go To First  |  Previous Question  |  Next Question 
 J2EE  |  Question 67 of 104    Print  
what is the difference between finally block and finalize method?

  
Total Answers and Comments: 3 Last Update: December 16, 2006     Asked by: challanaveen 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
November 10, 2006 16:56:47   #1  
anuragverma Member Since: August 2006   Contribution: 1    

RE: what is the difference between finally block and f...
finally -The finally block is optional and provides a mechanism to clean up regardless of what happens within the try block (except System.exit(0) call). Use the finally block to close files or to release other system resources like database connections statements etc.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.
 
Is this answer useful? Yes | No
November 20, 2006 06:39:36   #2  
srinivasreddy        

RE: what is the difference between finally block and f...

A method which is declared as finalize can not be overridden in subclasses which extends the class has the finalized method

Finally block will be exeuted in a programe at any case

if wether programe terminates in try or catch block finally it executes the finnaly block.


 
Is this answer useful? Yes | No
December 15, 2006 18:50:11   #3  
ujwala        

RE: what is the difference between finally block and f...
finalize() method is executed prior to the execution of a garbage collector. When a object is no longer in use but it holds some resources before garbage collector collects this object these resources must be released. you should define finalize() method so that before the gc takes places all the resources released.While finally block is optional and executed before the class exicution exits. Finally block is used to release database connections system resources. Execution of finally block do not depend upto the execution of try catch block.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape