Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

diffrence b/w heap and pool

 
vinaykumar singh
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all..
i m not getting whats the exactly diffrence b/w heap and pool. please discribe it breifly.

thanks

vinay
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joshua Smith
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinaykumar-

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.
Josh

[ February 05, 2006: Message edited by: Joshua Smith ]
[ February 05, 2006: Message edited by: Joshua Smith ]
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic