• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Mock question

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the answer for the question? and please explain it.

Which statements describe guaranteed behavior of the garbage collection and finalization mechanisms?
1. Objects are deted when they can no longer be accessd through any reference.
2. The finalize() method will eventually be called on every object.
3. The finalize() method will never be called more than once on an object.
4. An object will not be garbage collected as long as it is possible for an active part of the program
to access it throught a reference.
5. The garbage collector will use a mark and sweep algorithm.
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1,3,5 seem to me as the right ones.
"5" - The Sun JVM does use a mark and sweep algorithm(See Appendix E - Thinking in Java).
"4" - is right too (I missed it the first time!!).
"3" - I have read about this one somewhere. If u resurrect an object in its finalize() method, the finalize() is not called again.
"1" - looks pretty straight forward (unless there is sonmething else!!)
Hope it was useful.
Ankur
[This message has been edited by Ankur (edited July 05, 2000).]
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Daniel and Ankur;
Answer 1 is absolutely wrong, it would have been right if it is phrased like this: an object will be eligible for gc (note that it is not guaranteed that it will be deleted)when they can be no longer referenced by any reference.
So, IMHO, 3, 5 would be correct, but I am not sure about 4, I will choose it.
Correct me if I am wrong.
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My answer would be 3 and 4.
5. is not true for all environments
Savithri
 
Ankur Gupta
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right Jason. "deleted", "removed" are not actually equivalent to garbage collected !!
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1 false
--The objects are eligible for gc,the statement deleted
makes me feel it is wrong,although it is a ambiguous q
2.false
--You have to override the finalize() method in order for it
to be invoked.
3.true
--The java document says,the finalize() method is never invoked
more than once by a JVM for any given object.
4.true
--The gc checks if a refernce is still valid/asociated with a variable.
5.false
--The catch here is the "will" statemnet.You cannot say for sure
which algorith may be used.Although it also is a bit ambiguous
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic