small clarification in String literals
Hi
System.out.print((hello == ("Hel"+"lo")) + " "); Returns "TRUE"
Reason:Strings computed by constant expressions compile time and then treated as if they were literals.
Is it true?String Literal memory allocation at compile time or runtime?
Thanks
**smile
[294 byte] By [
smile4ua] at [2007-11-27 11:40:45]

> Is it true?String Literal memory allocation at
> compile time or runtime?
Memory allocation always happens at runtime, since nothing is executed during compile time.
But yes, true. "Hel"+"lo" in this case gets compiled to "Hello" which already exists. Works differently if any part of the concatenation is a variable.
>
> Is it true?String Literal memory allocation at
> compile time or runtime?
>
String data is stored in the constants table of the class, but when they are loaded the actual, coresponding, String objects are stored in the "intern" pool (after being checked for uniqueness).
This is allocated at run time, and you can add Strings to it explicitly with String.intern()