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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How java enabled high performance?

804


Is string a datatype?

743


What happens if constructor is private?

780


Why java is said to be pass-by-value ?

795


what is enumset?

799


What are measurable parameters?

789


How would you convert bytes to string?

762


how to write a server program and sending the mails to the server using smtp protocol please help me

1784


What are thread local variables?

777


What is the arraylist in java?

750


How is hashset defined in java?

734


how we can use debug in myeclipse 6.0 in order solve the problems that exist in our program when there are 900 to 1000 pages in a web application

1881


What is an immutable class? How to create an immutable class?

789


What is the purpose of the finalize() method?

953


What is boolean strategy?

874