• 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

Garbage collection (program)

 
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
This is the code
I got from a book explaining Garbage Collection.Cannot understand any part of the progam.Would be grateful if someone explain the stepwise execution of the program.
Also I did not understand

HeavyItem list=createList("X");
list = createList("Y");

itemA=new HeavyItem(itemID,null);

and the code written in the main method.

What exactly do you mean by these lines.

 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nabila Mohammad:
...Also I did not understand

HeavyItem list = createList("X");
list = createList("Y");
itemA = new HeavyItem(itemID, null);...


It would be difficult to grasp garbage collection without understanding object creation, because garbage collection is all about "unreachable" objects that can be cleared from memory.

new HeavyItem(itemID, null) creates a new instance of HeavyItem by calling a HeavyItem constructor that takes arguments of a String and a HeavyItem. In this case, the String is referenced by itemID, and the HeavyItem is a null reference.

createList is a method that takes a String argument and returns a reference to a HeavyItem. In fact, the method creates three new instances of HeavyItem and returns a reference to one of these. But this HeavyItem HAS-A HeavyItem, which in turn HAS-Another HeavyItem.
 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey.
Can you tell me where I can get the details of Object creation
besides the regular stuff.
ie.
MyClass obj=new MyClass();
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What book are you using to learn Java?
 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I m using A Programmer's guide to Java Certification by Khalid A.Mughal and Rolf W.Rasmussen.
I was referred for this book by one of my teachers.
 
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nabila
If you are preparing for Java Certification, then this book is for you, although others are recommended for SCJP, see JavaRanch FAQ.

However a Certification guide is not intended for teaching language basics instead teaches exam stuff.. If you aren't interested in SCJP then better find an introdutory book which focuses on learning the language.
 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you suggest some link where i can brush my basics?
 
ahmed yehia
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sun Java Tutorial
 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic