Hi Siu. I am going to answer here instead of in the other one, so as not to get mixed up with Jose�s explanation.
I have noticed that people in this forum count objects. In two contexts, garbage collection and String creation. One wonders if the skill of counting objects is needed for the exam.
While practicing counting String objects, I looked at the class file and the byte codes to check my answers. I learned that some of my assumptions were wrong.
I posted my examples to see if other people would disagree. I want to know if I am doing something wrong.
1. At compile-time, the concatenation of adjacent String literals �one� + �two� + �three� produces only one string �onetwothree� that is stored in the class file.
Jose explained that a String object is created when the string is referenced for the first time.
2. The
Java Programming Language says the compiler �uses a StringBuffer object to build strings from expressions, creating the final String only when necessary�. That is what I see in the byte codes and what I was trying to show in my examples.
Thank you for your interest Siu and for your colorful replies.
[ May 10, 2003: Message edited by: Marlene Miller ]