Thanks and Regards, Amit Taneja
Cheers,<br />Jagadesh.<br /> <br />--------------------------------<br />SCJP 1.4 , SCBCD 1.3 , SCWCD 1.4<br />--------------------------------
*** one more thing ... why the method local innenr class can't be marked public,private, protected, static, ???
Cheers,<br />Jagadesh.<br /> <br />--------------------------------<br />SCJP 1.4 , SCBCD 1.3 , SCWCD 1.4<br />--------------------------------
The string "local variable" will not be in the heap it will be in the string pool. An object will be created in the heap only when string is created using new.
Tony Morris
Java Q&A (FAQ, Trivia)
Cheers,<br />Jagadesh.<br /> <br />--------------------------------<br />SCJP 1.4 , SCBCD 1.3 , SCWCD 1.4<br />--------------------------------
Tony Morris
Java Q&A (FAQ, Trivia)
Originally posted by Tony Morris:
That article is flawed and contains fallacy.
SCJA 1.0 (98%), SCJP 1.4 (98%)
Tony Morris
Java Q&A (FAQ, Trivia)
Tony Morris
Java Q&A (FAQ, Trivia)
Originally posted by Tony Morris:
"Equivalent String Literals (even those stored in separate classes in separate packages) will refer to the same String object." - no they won't (need I explain it again?).
and the compilation unit:
package other;
public class Other { static String hello = "Hello"; }
produces the output:
true true true true false true
This example illustrates six points:
1. Literal strings within the same class (�8) in the same package (�7) represent references to the same String object (�4.3.1).
2. Literal strings within different classes in the same package represent references to the same String object.
3. Literal strings within different classes in different packages likewise represent references to the same String object.
4. Strings computed by constant expressions (�15.28) are computed at compile time and then treated as if they were literals.
5. Strings computed at run time are newly created and therefore distinct.
6. The result of explicitly interning a computed string is the same string as any pre-existing literal string with the same contents.
"I'm not back." - Bill Harding, Twister
For any two classes which are in the same JVM at the same time, equivalent string literals will refer to the same object. It's only when classes are not in the JVM at the same time that we may find exceptions to the above rule. This requires that we have two different class loaders
Tony Morris
Java Q&A (FAQ, Trivia)
"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
For any two classes which are in the same JVM at the same time, equivalent string literals will refer to the same object. It's only when classes are not in the JVM at the same time that we may find exceptions to the above rule.
Tony Morris
Java Q&A (FAQ, Trivia)
"I'm not back." - Bill Harding, Twister