Results 1 to 7 of 7

Thread: Difference between final, finally and finalize in Java?

  1. #1
    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.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    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.

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    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.

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    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.

  5. #5
    Join Date
    Apr 2008
    Posts
    1,948

    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.

  6. #6
    Join Date
    May 2008
    Posts
    2,012

    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.

  7. #7
    softtrickseo Guest

    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.

Similar Threads

  1. Final keyword in Java
    By Level8 in forum Software Development
    Replies: 4
    Last Post: 26-10-2011, 08:04 PM
  2. Equivalent to Java finally keyword in PHP
    By Jaganmohini in forum Software Development
    Replies: 6
    Last Post: 12-08-2010, 10:20 AM
  3. What is the 'finally' Block in Java?
    By Damien25 in forum Software Development
    Replies: 4
    Last Post: 18-02-2010, 05:31 AM
  4. what is the difference between c and java?
    By Linoo in forum Software Development
    Replies: 5
    Last Post: 28-11-2009, 05:11 PM
  5. Replies: 0
    Last Post: 07-07-2008, 12:13 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,620,473.84430 seconds with 17 queries