Java Reference
In-Depth Information
It is a compile-time error for the character following the
SingleCharacter
or
Es-
capeSequence
to be other than a
'
.
the closing
'
.
As specified in §
3.4
, the characters CR and LF are never an
InputCharacter
; each is
recognized as constituting a
LineTerminator
.
The following are examples of
char
literals:
•
'a'
•
'%'
•
'\t'
•
'\\'
•
'\''
•
'\u03a9'
•
'\uFFFF'
•
'\177'
•
'Ω'
Because Unicode escapes are processed very early, it is not correct to write
'\u000a'
for
a character literal whose value is linefeed (LF); the Unicode escape
\u000a
is trans-
formed into an actual linefeed in translation step 1 (§
3.3
) and the linefeed becomes
a
LineTerminator
in step 2 (§
3.4
), and so the character literal is not valid in step 3.
to write
'\u000d'
for a character literal whose value is carriage return (CR). Instead, use
'\r'
.
In C and C++, a character literal may contain representations of more than one char-
acter, but the value of such a character literal is implementation-defined. In the Java
programming language, a character literal always represents exactly one character.
3.10.5. String Literals
A
string literal
consists of zero or more characters enclosed in double quotes. Characters
the range U+0000 to U+FFFF, two escape sequences for the UTF-16 surrogate code units
of characters in the range U+010000 to U+10FFFF.
StringLiteral: