File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage collection (program) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage collection (program)" Watch "Garbage collection (program)" New topic
Author

Garbage collection (program)

Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
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.



The future belongs to those who believe in the beauty of their dreams.Dream BIG!
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
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

Joined: Aug 31, 2004
Posts: 11343

What book are you using to learn Java?
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
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.
ahmed yehia
Ranch Hand

Joined: Apr 22, 2006
Posts: 424
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

Joined: Nov 05, 2007
Posts: 661
Can you suggest some link where i can brush my basics?
ahmed yehia
Ranch Hand

Joined: Apr 22, 2006
Posts: 424
Sun Java Tutorial
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage collection (program)
 
Similar Threads
Self Join Query Help
Examples for Builder Patterns??
Question related to garbage collection
cewolf data points not visible
Doubt with garbage collection