what are the differences between final,finally,finalize
methods?
Answer Posted / ramudu
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 ? | 1 Yes | 0 No |
Post New Answer View All Answers
How many bytes is a string java?
Write a program in java to calculate the difference between the sum of the odd level and even level nodes of a binary tree.
What is the use of bufferedreader?
Why wait(),notify(),notifyAll() methods defined in Object class althought we are using in only threads.
What is object of class in java?
What is module in oop?
What is empty string literal in java?
what are the methods in object?
What's a method in programming?
What is operator overloading. Is it is supported in java?
Explain Basics of OOP Language in java
Explain wait(), notify() and notifyall() methods of object class ?
What is void keyword?
What is canonical name in java?
What is time complexity algorithm?