Java Reference
In-Depth Information
TABLE 2.2
Character Escape Codes
Escape
Meaning
New line
\n
Tab
\t
Backspace
\b
Carriage return
\r
Formfeed
\f
Backslash
\\
Single quotation mark
2
\'
Double quotation mark
\”
Octal
\ d
Hexadecimal
\x d
Unicode character
\u d
String Literals
The final literal that you can use in a Java program represents strings of characters. A
string in Java is an object rather than a primitive data type. Strings are not stored in
arrays as they are in languages such as C.
Because string objects are real objects in Java, methods are available to combine strings,
modify strings, and determine whether two strings have the same value.
String literals consist of a series of characters inside double quotation marks, as in the
following statements:
String quitMsg = “Are you sure you want to quit?”;
String password = “swordfish”;
Strings can include the character escape codes listed previously in Table 2.2, as shown
here:
String example = “Socrates asked, \”Hemlock is poison?\””;
System.out.println(“Sincerely,\nMillard Fillmore\n”);
String title = “Sams Teach Yourself Ruby on Rails While You Sleep\u2122”
In the last of the preceding examples, the Unicode code sequence \u2122 produces a ™
symbol on systems that have been configured to support Unicode.
 
Search WWH ::




Custom Search