posted 18 years ago
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 ]