I agree with Soni's description.
I believe the compiler will concatenate all these literals into one before the program even runs, as it can see that they are all "constant string literals" as Soni puts it.
In his other example, it's not "safe" for the compiler to concatenate the strings. Although I would guess, that "two", "three", and "four" would still get combined by the compiler, and you would end up with only 3 strings:
obj1 = "one" // referenced by str1
obj2 = "twothreefour" // in the string literal pool, but not referenced by the program code
obj3 = "onetwothreefour" // referenced by str2
Perhaps not, though, because of order of operations? Maybe you end up with 5 strings in Soni's example, but 3 strings if you do the following:
hrmmm.... the tough part of proving this programatically is that the whole design goal of Strings being immutable and constant Strings being put in a pool, is that your program should never know the difference... I remember seeing some posting where people used "==" tests, or maybe some kind of identity hashcode, to try to infer about the string literal pool...
This is just the sort of thing that is fully defined by the
Java spec, so we can get a conclusive answer if someone who is not currently running late for work looks it up
-- Jon