3.10.6
Escape Sequences for Character and String Literals
LEXICAL STRUCTURE
Thus, the test program consisting of the compilation unit ( 7.3):
package testPackage;
class Test {
public static void main(String[] args) {
String hello = "Hello", lo = "lo";
System.out.print((hello == "Hello") + " ");
System.out.print((Other.hello == hello) + " ");
System.out.print((other.Other.hello == hello) + " ");
System.out.print((hello == ("Hel"+"lo")) + " ");
System.out.print((hello == ("Hel"+lo)) + " ");
System.out.println(hello == ("Hel"+lo).intern());
}
}
class Other { static String hello = "Hello"; }
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:
Literal strings within the same class ( 8) in the same package ( 7) represent
references to the same
String
object ( 4.3.1).
Literal strings within different classes in the same package represent refer
ences to the same
String
object.
Literal strings within different classes in different packages likewise represent
references to the same
String
object.
Strings computed by constant expressions ( 15.27) are computed at compile
time and then treated as if they were literals.
Strings computed at run time are newly created and therefore distinct.
The result of explicitly interning a computed string is the same string as any
pre existing literal string with the same contents.
3.10.6 Escape Sequences for Character and String Literals
The character and string
escape sequences
allow for the representation of some
nongraphic characters as well as the single quote, double quote, and backslash
characters in character literals ( 3.10.4) and string literals ( 3.10.5).
26
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved