Thursday, January 5, 2012

JAVA STRING

The new keyword is not required for creating the String object “How are you?” because
it is a string literal. String literals get special treatment by the JVM. Behind the scenes,
the JVM instantiates a String object for “How are you?” and stores it in the string pool.
The greeting reference refers to this String object in the pool. Because String objects
in Java are immutable (which means they cannot be changed), the JVM can optimize the
use of string literals by allowing only one instance of a string in the pool. For example,
the following two String references actually point to the same string in the pool, 

No comments:

Post a Comment