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 variable argument in java?

775


What is java autoboxing?

733


Difference between object instantiation and construction ?

823


What are jee technologies?

769


Is sizeof a keyword in java programming?

822


Does set allows null in java?

715


What is the statements?

830


Which is easier .net or java?

853


Are variables stored in ram?

773


What is hash table in java?

684


What is a concrete classes? Is Java object class is concrete class?

748


What is the format specifier?

720


Why are pointers not secure?

786


Explain the importance of join() method in thread class?

851


Is 0 true or false in java?

764