• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Page 268 Be The Garbage Collector

 
Ranch Foreman
Posts: 854
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is code from Head First Java 3rd edition.   It wants me to figure out something about eligibility for the Garbage Collector.   I'm having trouble with some basic concepts that I didn't see the book discussing.  I have some questions about the code before looking into Garbage Collection.  I copied and pasted two parts of the code at the top to ask things about it.  I



Is it making one of these classes into an object?  



Here is the entire code from the book:


 
Marshal
Posts: 79058
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A lot of examples in HFJ are aimed at people who are hoping to sit a certification exam; in this case the reader is expected to work out how many objects are “unreachable”. Such questions can come up in the exam.
The correct way to answer it is to get pencil and paper, and write down which vaiable points to which object. Try it with the two methods first. Work out which of the methods do and don't make any changes that actually last after the method completes. When the main() method completes, you should work out how many objects have been created and are no longer reachable.
I suggest you go back and revise what it says about methods and what their modifiers and return types are.
 
kevin Abel
Ranch Foreman
Posts: 854
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell,

After I asked the question here I mapped out the objects.   I might have been close.  

Then i couldn't decide if the question wanted me to substitute one line at a time into where "A"  is located or if they are cumulative.  

At first I thought it was one at a time but the answers were not matching.  Then I switched to cumulative and messed up my drawing by adding and removing arrows to my drawing.

Can you tell by the question what they expect?

I found a question and discussion on Code Ranch from 14 years ago talking about this same thing and still wasn't sure.

Thanks,

Kevin
 
kevin Abel
Ranch Foreman
Posts: 854
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the link to this from way back in time:

https://coderanch.com/t/426503/certification/GARBAGE-COLLECTION-HFJ-PG
 
Campbell Ritchie
Marshal
Posts: 79058
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for delay in replying.

kevin Abel wrote:. . . couldn't decide if the question wanted me to substitute one line at a time into where "A"  is located or if they are cumulative. . . .

One at a time, I think.
 
kevin Abel
Ranch Foreman
Posts: 854
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell,

I'll make a note on the quiz and go back to it after getting to the end of the book.   I'm on page 302 of 700.  

Thanks,

Kevin
 
reply
    Bookmark Topic Watch Topic
  • New Topic