Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage collection query

 
vidhya suvarna
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Source: http://www.akgupta.com/Java/mock_exam.htm

Which of the foll are true?
1) Because of Garbage collection java program doesnot run out of memory
2) Garbage collection use mark and sweep algorithm
3) Garbage collection is implementation dependent
4) Garbage collection is platform independent
5) System.gc forces Garbage collection

according to me option 4 appear to be one to the correct answer. Option 5 is wrong for sure.

Can anybody verify and tell me know the exact right answer for this?

Thanks,
Vidhya
 
Marco Piva
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IMHO the correct answer is:

3) Garbage collection is implementation dependent
 
vidhya suvarna
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can someone confirm the answer
 
Hrishikesh Maluskar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Because of Garbage collection java program doesnot run out of memory
False -> Since we cannot control garbage collection , it is completely controlled by the JVM. Only thing assured is that whenever we are short of memory the Garbage collector will try its best to utilize the memory effictively , but not guranteed to run.

2) Garbage collection use mark and sweep algorithm
False -> Java Specification does not gurantee any particular Implementation

3) Garbage collection is implementation dependent
True -> JVM designers are free to design their own implementation for garbage collection.They can also not implement it at all.

4) Garbage collection is platform independent
True -> JAVA language is platform independent , hence anything associated with it is platform independent.

5) System.gc forces Garbage collection
False -> Nothing in this world can force garbage collection.System.gc is just a request to the JVM.
 
Paul Somnath
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't understand option Four.
Does that mean that garbage collection happens in every underlying OS?
If that is the case, then yes its true.
But Garbage collection algorithms are different for different platforms.
 
Pranav Bhatt
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Out of all i doubt about option 3 to be True i.e
3)
by Hrishikesh Maluskar..
Garbage collection is implementation dependent
True -> JVM designers are free to design their own implementation for garbage collection.They can also not implement it at all.


You can implement GC on your code but even if you implement you are not sure that GC will take place. Moreover even if you don't, GC may run too. So it would be independent of implementation.
 
sweety sinha
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
3) Garbage collection is implementation dependent
True -> JVM designers are free to design their own implementation for garbage collection.They can also not implement it at all.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
You can implement GC on your code but even if you implement you are not sure that GC will take place. Moreover even if you don't, GC may run too. So it would be independent of implementation.
...............................................................
there seems to be two different answers regarding option 3.
so which is the most appropriate answer that is whether it is implementation dependent or not. please confirm
 
kaushik vira
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Out of all option 3 is True. GC is not platform dependent but you can choose you GC implementation by passing some option in start up jvm instruction.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic