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

Program to output as below formate: 1 2 3 4 5 6 7 8 9 10

4 Answers   Huawei,


Is java based on c?

0 Answers  


What is singleton class and how can we make a class singleton?

0 Answers  


Define an enumeration?

0 Answers  


How to access arraylist elements in java?

0 Answers  






What are the parameters used in Connection pooling?

1 Answers   IBM,


What are the two main uses of volatile in Java?

0 Answers  


What does substring mean?

0 Answers  


What is the vector class in java programming?

0 Answers  


What is are packages?

0 Answers  


can we create a instance for intwerface?

3 Answers  


public class Test { public static void main(String[] args) { int countA = 0; int countB = 0; int countC = 0; int countD = 0; int countE = 0; int countF = 0; int countG = 0; int countH = 0; int countI = 0; int countJ = 0; int countK = 0; int countL = 0; int countM = 0; int countN = 0; int countO = 0; int countP = 0; int countQ = 0; int countR = 0; int countS = 0; int countT = 0; int countU = 0; int countV = 0; int countW = 0; int countX = 0; int countY = 0; int countZ = 0; } } Can anybody tell me any alternate solution(like loop or something) to automate this initialization process. Ex:- for(char chr='A';chr<='Z'; chr++) { (int) String "count"+chr = 0; }

0 Answers  


Categories