what is the use of finalize()Method
please explain with an example

Answers were Sorted based on User's Feedback



what is the use of finalize()Method please explain with an example..

Answer / mrudang

Sometimes u have seen that some objects of java need to
perform an non- java resoures like file handler etc..

Now Suppose that object going to distroy.So java provides
the mechanism that some specific action will perform when u
delect or try to distory that object..

The opration that u want to perform when such kind of
object Distory is written in finalize method...

Is This Answer Correct ?    12 Yes 4 No

what is the use of finalize()Method please explain with an example..

Answer / priyabrata patro

Once object is created than as java does not support delete keyword to delete the object , so , just imagine in our program when we create number of object than how it is deleted how memory occupied by this object recycled.
So,thankfully java supports gargage collector which is a program in jvm ,listen jvm is also a collection of program and garbage collector is one of them. Thus garbage collector is purely under cotrol of jvm .
So , now let us see what is the usage of finalize method .
When you go on creating the object , object occupies memory
and as memory is not infinite than you are prohibited to go on beyond the memory , but at that instance your program needs to have an object and memory is not available .So, there exactly we need finalize method to force garbage collector to recycle unused memory.
And you can say that as garbage collector is working why we need to use finalize method . As mentioned earlier that garbage collector is purely under control of jvm ,so jvm decides when it should work.okkk

Is This Answer Correct ?    8 Yes 6 No

what is the use of finalize()Method please explain with an example..

Answer / hasan balhabak

to free the resources thar are held by any other objent

Is This Answer Correct ?    3 Yes 2 No

Post New Answer

More Core Java Interview Questions

i need example for java abstraction. where we use abstraction and why we need abstraction.

2 Answers   Oracle,


What kind of variables can a class consist?

0 Answers  


What is the difference between equals() and == in java?

0 Answers  


Explain the concept of polymorphism with examples?

6 Answers   Summation Tech,


Can there be an abstract method without an abstract class?

0 Answers  






Can a constructor be private and how are this() and super() method used with constructor?

0 Answers   Flextronics, Hexaware,


What is difference between variable declaration and definition?

0 Answers  


What are the differences between getting and load method?

0 Answers  


Explain why wait(), notify() and notifyall() methods are in object class rather than in the reading class?

0 Answers  


What are keywords in programming?

0 Answers  


What is the need to implement Serializable interface (with no methods) for objects which are to be serialized ? We can write our own functionality which writes objects to streams then why we need to implement and tell JVM that which objects can be serialized.

6 Answers   iFlex, Sapient,


How to perform bubble sort in java?

0 Answers  


Categories