LEXICAL STRUCTURE
String Literals
3.10.5
3.10.5   String Literals
A
string literal
 consists of zero or more characters enclosed in double quotes.
Each character may be represented by an escape sequence.
A string literal is always of type
String
 ( 4.3.3,  20.12). A string literal
always refers to the same instance ( 4.3.1) of class
String
.
StringLiteral:
"
StringCharacters
opt
 "
StringCharacters:
StringCharacter
StringCharacters StringCharacter
StringCharacter:
InputCharacter
 but not
"
 or
\
EscapeSequence
The escape sequences are described in  3.10.6.
As specified in  3.4, neither of the characters
CR
 and
LF
 is ever considered to
be an
InputCharacter
; each is recognized as constituting a
LineTerminator
.
It is a compile time error for a line terminator to appear after the opening
"
and before the closing matching
"
. A long string literal can always be broken up
into shorter pieces and written as a (possibly parenthesized) expression using the
string concatenation operator
+
 ( 15.17.1).
The following are examples of string literals:
""
//
the empty string
"\""
//
a string containing
 "
alone
"This is a string"
//
a string containing 16 characters
"This is a " +
//
actually a string valued constant expression,
"two line string"
//
formed from two string literals
Because Unicode escapes are processed very early, it is not correct to write
"\u000a"
 for a string literal containing a single linefeed (
LF
); the Unicode escape
\u000a
 is transformed into an actual linefeed in translation step 1 ( 3.3) and the
linefeed becomes a
LineTerminator
 in step 2 ( 3.4), and so the string literal is not
valid in step 3. Instead, one should write
"\n"
 ( 3.10.6). Similarly, it is not correct
to write
"\u000d"
 for a string literal containing a single carriage return (
CR
).
Instead use
"\r"
.
Each string literal is a reference ( 4.3) to an instance ( 4.3.1,  12.5) of class
String
 ( 4.3.3,  20.12).
String
 objects have a constant value. String literals 
or, more generally, strings that are the values of constant expressions ( 15.27) 
are  interned  so as to share unique instances, using the method
String.intern
( 20.12.47).
25






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java hosting

 

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