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
Why does my function print none?
What is locale?
What is method in research paper?
Which is better stringbuilder or stringbuffer?
What is string in java?
What are the two types of exceptions in java? Which are the differences between them?
What is the use of parseint in java?
What is connection class in java?
What do you mean by exception handling in Java?
What is difference between module and function?
Is int a class in java?
when a request is generated from apache tomcat 5.5 and goes to oracle 10g or mysql,,, how the oracle or mysql reads the request as apache is a web server and oracle 10g is application server? when the oracle 10g provides response, how the apche tomcat reads it???
How do you sing an Applet ?
What is class and object in java?
What is difference between checked and unchecked exception in java?