finalize() method?

Answers were Sorted based on User's Feedback



finalize() method?..

Answer / ramanareddy333

every class inherits the finalize() method from
java.lang.Object
the method is called by the garbage collector when it
determines no more references to the object exist
the Object finalize method performs no actions but it may
be overridden by any class
normally it should be overridden to clean-up non-Java
resources ie closing a file
if overridding finalize() it is good programming practice
to use a try-catch-finally statement and to always call
super.finalize() (JPL pg 47-48). This is a saftey measure
to ensure you do not inadvertently miss closing a resource
used by the objects calling class
protected void finalize() throws Throwable {
try {
close(); // close open files
} finally {
super.finalize();
}
}

any exception thrown by finalize() during garbage
collection halts the finalization but is otherwise ignored
finalize() is never run more than once on any object

Is This Answer Correct ?    4 Yes 1 No

finalize() method?..

Answer / guest

Every class Inherits the finalize() from
java.lang.class.this method called by Garbage collector
for clean up processing(like Realesing memory Resorces,file
closing,socket closing..) for any unreachble object before
destroing the object .

Is This Answer Correct ?    4 Yes 3 No

finalize() method?..

Answer / harika.thota001@gmail.com

Before an object is garbage collected, the runtime system calls its finalize() method. The intent is for finalize() to release system resources such as open files or open sockets before getting collected.

Is This Answer Correct ?    0 Yes 0 No

finalize() method?..

Answer / jigar gandhi

When the garbage collector is ready to release the storage
ed for your object, it will first call finalize( ),

Is This Answer Correct ?    0 Yes 1 No

finalize() method?..

Answer / chandu

to clean up objects from memory after executing the program

Is This Answer Correct ?    0 Yes 4 No

Post New Answer

More Core Java Interview Questions

What is a conditional statement explain with example?

0 Answers  


What is the super void?

0 Answers  


How do you remove all elements from an arraylist in java?

0 Answers  


Define Multiprogramming and Multiprocessing in java.

0 Answers   Akamai Technologies,


Are primitives objects?

0 Answers  






How do you end a program?

0 Answers  


What does int argc char * argv [] mean?

0 Answers  


Write program to print Hello World and print each character address in that string and print how many times each character is in that string? Ex: H: 0 & 1 e:1 & 1 l :2,3,8 & 3 o:4,6 & 2 w:5 & 1 r: 7 & 1 d 9 & 1

7 Answers   Huawei, IBM,


How to perform merge sort in java?

0 Answers  


Distinguish method overloading and method overriding

4 Answers   Tech Mahindra,


How to sort an array from smallest to largest java?

0 Answers  


WHAT IS JDK,JVM,CLASS DEFINE ALL?

2 Answers  


Categories