Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Difference between final, finally and finalize in Java?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 30-01-2010
Member
 
Join Date: Dec 2009
Posts: 18
Difference between final, finally and finalize in Java?
  

I am intermediate programmer in the programming world. Right now i am learning the programming language like C++, C sharp, Core Java, SQL and HTML. This days, i am working on Core Java and i have doubt that what is difference between the final, finally and finalize? Please help me.

Reply With Quote
  #2  
Old 30-01-2010
Member
 
Join Date: Jan 2008
Posts: 1,513
Re: Difference between final, finally and finalize in Java?

I think this three method/functions are not that hard to understand and yes, they all are different from each other. I would say that "final" is known to be a keyword, which is used to declare constants. The "finally" block is used mainly in the exception handling. And the "finalize" method is usually called by garbage collector, in order to remove/throwout the object from memory if it no longer has been used. Hope i have clear your doubt.
Reply With Quote
  #3  
Old 30-01-2010
Member
 
Join Date: Feb 2008
Posts: 1,844
Re: Difference between final, finally and finalize in Java?

The final is a keyword and used for making a member/variable as a constant which will not be modified once declared. The finally is a method and used during the exception handling to release any resource hold by try block. And the finalize method, all the resources mention will be garbage collected as soon as GC is called. The finalize and finally seems to be similar, but the difference is finally is gone execute every-time whether you call it or not, and this not similar with finalize.
Reply With Quote
  #4  
Old 30-01-2010
Member
 
Join Date: May 2008
Posts: 2,379
Re: Difference between final, finally and finalize in Java?

According to me, all the three final, finally and finalize are different from each other and plays very important role in Java. The final is used for constant declaration, the finally is used in the exception handling and the finalize is used in the garbage collection. The finally and finalize has similar action of releasing the resources, but the difference is that finally will execute compulsorily and finalize will not. Hope your doubt would be cleared now.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #5  
Old 30-01-2010
Member
 
Join Date: Apr 2008
Posts: 1,946
Re: Difference between final, finally and finalize in Java?

Final: The final keyword is used for making variable as a constant.
Finally: The finalize method are used to handle exception. The finally block is known to optional and it provides a mechanism to clean up without regarding of what happens inside the try block.
Finalize: The finalize method provide help in the garbage collection. This method is call before any object is discarded by the garbage collector, which will allow it to clean up its state.
Reply With Quote
  #6  
Old 30-01-2010
Member
 
Join Date: May 2008
Posts: 2,004
Re: Difference between final, finally and finalize in Java?

Finalize: This method is used for garbage collection. This method will get execute before Garbage Collection is done, because it release the resource which are hold by the program.
Finally: This method is used for in the exception handling mechanism. Once try block is executed, then finally block is must to execute. This block will release the resource hold by the try block.
Final: The final keyword is used declaring variables as constant.
Hope your doubt would be clear after this answer. All the best.
Reply With Quote
  #7  
Old 31-01-2010
softtrickseo
 
Posts: n/a
Re: Difference between final, finally and finalize in Java?

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.
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.
final – constant declaration.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Difference between final, finally and finalize in Java?"
Thread Thread Starter Forum Replies Last Post
Final keyword in Java Level8 Software Development 4 26-10-2011 08:04 PM
Equivalent to Java finally keyword in PHP Jaganmohini Software Development 6 12-08-2010 10:20 AM
What is the 'finally' Block in Java? Damien25 Software Development 4 18-02-2010 04:31 AM
what is the difference between c and java? Linoo Software Development 5 28-11-2009 04:11 PM
Nadal finally conquers grass, beats Federer in Wimbledon final Yogesh Off Topic Chat 0 07-07-2008 12:13 PM


All times are GMT +5.5. The time now is 02:21 PM.