wood burning stoves
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes diffrence b/w heap and pool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "diffrence b/w heap and pool" Watch "diffrence b/w heap and pool" New topic

diffrence b/w heap and pool

vinaykumar singh

Joined: Jan 14, 2006
Posts: 13
hello all..
i m not getting whats the exactly diffrence b/w heap and pool. please discribe it breifly.


Marcus Green
arch rival

Joined: Sep 14, 1999
Posts: 2813
I'm not sure your question has any meaning. The internals of compilers decide if information is on the heap or stack and in Java there is a String pool, but that is a separate issue.

SCWCD: Online Course, 50,000+ words and 200+ questions
Joshua Smith
Ranch Hand

Joined: Aug 22, 2005
Posts: 193

From what I've read, basically all you have to know about the heap and the stack for the exam is that local variables (variables declared inside of methods) live on the stack and objects and instance variables live on the heap.

Also know when an object is eligible for garbage collection.

Like Marcus said, Java also uses a String pool for optimization. Basically if you create a reference to a String literal, Java looks in a special section of memory for a matching String literal. If there's one there, then it points the reference at that String literal. If not, it creates a new String literal. If you use the new keyword (String myString = new String("blah") ;) , then it skips using the String pool altogether and creates a new String literal just like any other object. There's usually no need to do this and many coding standards prohibit creating Strings with the new keyword. You might have to have some knowledge of this stuff for the exam, but for the real world I think it basically comes down to never using the new keyword with Strings and always using myString.equals(otherString) instead of == to compare Strings.

Hope that helps.

[ February 05, 2006: Message edited by: Joshua Smith ]
[ February 05, 2006: Message edited by: Joshua Smith ]

Rational Pi Blog - Java, SCJP, Dev Bits- http://rationalpi.wordpress.com
Marcus Green
arch rival

Joined: Sep 14, 1999
Posts: 2813
In my experience of the Sun Certified Java programmers exam (going back to 1998) there have never been any questions that expect knowledge of the heap and Stack, but you do need to understand the String pool.
I agree. Here's the link: http://aspose.com/file-tools
subject: diffrence b/w heap and pool
It's not a secret anymore!