wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage collect from javaprepare.com Exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage collect from javaprepare.com Exam" Watch "Garbage collect from javaprepare.com Exam" New topic
Author

Garbage collect from javaprepare.com Exam

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Which of the following are correct related to Garbage Collection. Select all correct answers.
a. It is posible for a program to free memory at a given time.
b. Garbage Collection feature of Java ensures that the program never runs out of memory.
c. It is possible for a program to make an object available for Garbage Collection.
d. The fialize method of an object is invoked before garbage collection is performed on the object.
The answer given is b,c. But I choose b, c and d. B'case if the finalize method exist then it will be invoked right???
help me pls.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Can anyone pls. explain me??
satish
Greenhorn

Joined: Jul 03, 2000
Posts: 27
I don't think garbage collection ensures that your program never runs out of memory. You can code in such a way that you leave references to objects but don't use those objects anymore. Garbage collection can act on only objects that do not have any references.
Regarding the finalize method...to my knowledge, finalize method will be called (if it exists) before removing the object. However if you resurrect your object reference in finalize method then the finalize method will not be called again when u remove the reference to the object later. So, finalize method is called only once for an object.
I am really not sure if I would not select answer d. Inspite of the above scenario, my instinct would be to select d. I am also interested in knowing what others think about this.
satish

satish
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
According to Exam Cram by Bill Brogden ,
"If your class definition declares an instance method that overrides finalize() method, the JVM will run the method after it has decided that an object is eligible for reclamation, but before reclaiming the memory used by the object"
The above statement sounds like it happens only when the finalize() method is overridden.
Anil Kollur
Ranch Hand

Joined: Mar 25, 2000
Posts: 101

IMHO, answers c and d r correct, Garbage Collection of java will not ensure that, program will never run out of memory. And finalize method will be invoked before GCing the object.


Everyday is a Learning phase! Hence ask "What have I learnt today?"
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
So you are all accepting that ans 'd' is correct. I am pretty sure that ans 'b' is correct. B'cas I read somewhere in this discusion that JVM ensures that the program never runs out of memory.
The program should not go out of memory that is why the automatic garbage collection runs in the backround with low-priority. But if you keep on creating objects and make those objects available for GC. If GC never gets a chance to run at that time your memory will keep on gets occupied, at some stage the GC will identify this situation and the GC will start run and our program will not run at that time.
The above concept I read somewhere not 100% sure. Please any one can help us. Planning to take exam on coming weekend.
Pls, pls. help us.
Thanks in advance.
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Surya,
A program can indeed run out of memory. Though the garbage collector will be eventually run by the JVM, there is no guarantee your program will not get impoverished of memory.
Perhaps that's why OutOfMemoryException exists
Ajith


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I believe the answer has been corrected on the website. The correct answer is c,d.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage collect from javaprepare.com Exam