This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
K. Tsang wrote:You want to find that out yourself. Do a equals test and a "==" test. The "==" should return false. The only reason the "==" returns true for Strings is that they are pointing to the "same" object.
I thought about that, but I couldn't say whether or not this constituted proof of an object being created "inside a heap". I'm not to clear on that aspect.
Fred Hamilton wrote:I thought about that, but I couldn't say whether or not this constituted proof of an object being created "inside a heap". I'm not to clear on that aspect.
Hmm maybe the K&B SCJP excerpt (ch 3 OO) will convince:
For the most part, the various pieces (methods, variables, and objects) of Java
programs live in one of two places in memory: the stack or the heap. For now, we're
going to worry about only three types of things: instance variables, local variables,
* Instance variables and objects live on the heap.
* Local variables live on the stack.
So what is String? a object so where is it created? on the heap. And in my code, how many string objects? 1, 2, or 3?