Java Reference
In-Depth Information
The processing logic would interpret that the second quotation mark
symbol marks the end of the output string. But if the string ends in this
symbol, then the rest of the statement is undecipherable and a compiler
error is produced.
Other special characters are used to format output. For example, when
the value 0x0a (decimal 10) is sent to the console the device moves the
cursor to the next screen line. From the days of teletype machines and
typewriters this is called a linefeed . By the same token, when the code
0x0d (decimal 13) is sent to the console the cursor is moved to the start of
the line. This action is called a carriage return . The values that perform
these special actions are called control codes .
Java uses the \ symbol as a special character. It serves to indicate that
the character that follows is to be interpreted in a special way. The \ sym-
bol is called the escape character . The escape character is used to display
characters that are used in statement formatting and to execute control
codessuchasnewlineandcarriagereturns. Table5-1 showstheJavaEs-
cape Characters.
Table 5-1
Java Escape Characters
LITERAL
VALUE
ACTION
\b
0x08
backspace
\t
0x09
horizontal tab
\n
0x0a
new line
\f
0x0c
form feed
\r
0x0d
carriage return
\"
double quotation mark
\'
single quotation mark
\\
backslash
By using the escape character we can now reformat the previous state-
ment, as follows:
System.out.println("She said her name was \"Mary\"");
The new line character (\n) is often used to end the current text line or
to produce a blankline on the screen. The following code displays the
words “Hello” and “World” separated by two blanklines.
System.out.print("Hello"); // First word
System.out.print("\n\n"); // Two blank lines
System.out.print("World"); // Second word
System.out.flush();
 
Search WWH ::




Custom Search