Java Reference
In-Depth Information
System.out.println("The secret message is in
C:\\Temp\\Secret.txt");
This statement prints
The secret message is in C:\Temp\Secret.txt
Another escape sequence occasionally used is \n , which denotes a newline or line
feed character. Printing a newline character causes the start of a new line on the
display. For example, the statement
System.out.print("*n**n***n");
prints the characters
*
**
***
161
162
on three separate lines. Of course, you could have achieved the same effect with
three separate calls to println .
Finally, escape sequences are useful for including international characters in a
string. For example, suppose you want to print ȒAll the way to San JosÈ!ȓ, with an
accented letter (È). If you use a U.S. keyboard, you may not have a key to generate
that letter. Java uses the Unicode encoding scheme to denote international
characters. For example, the È character has Unicode encoding 00E9. You can
include that character inside a string by writing \u , followed by its Unicode
encoding:
System.out.println("All the way to San
Jos\u00E9!");
You can look up the codes for the U.S. English and Western European characters
in Appendix B, and codes for thousands of characters in reference [ 1 ].
A DVANCED T OPIC 4.5: Strings and the Char Type
Strings are sequences of Unicode characters (see Random Fact 4.2 ). Character
constants look like string constants, except that character constants are delimited
by single quotes: ÒHÓ is a character, ÐHÑ is a string containing a single character.
Search WWH ::




Custom Search