what are the differences between final,finally,finalize
methods?

Answer Posted / mukesh makwana

* final – constant declaration.

* 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.

Is This Answer Correct ?    14 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is an immutable object? How do you create one in java?

604


hi am an engineering student and my next plan is for ms in either in us or australia i got my passport but i dont know anything bout visa can u give brief idea 1)How to get prepared for visa and 2)How to apply for top universities and 3)How to pay the fee and so on These all are basic questions plz give me a clear idea

1465


What is operator overloading. Is it is supported in java?

524


Java is pass by value or pass by reference? Explain

535


What is meant by object oriented programming – oop?

545






What is scope & storage allocation of static, local and register variables? Explain with an example.

570


How do you write methodology?

565


What is an example of a constant variable?

537


What is an i/o filter?

570


Difference between object instantiation and construction ?

585


Can you instantiate the math class?

602


What is %02d?

580


What is a platform?

546


Is final static java?

553


What is empty list in java?

628