When a string is being created or displayed, its text must be enclosed within double quotation marks. These quotation marks are not displayed, which brings up a good question: What if you want to display double quotation marks?
To display them, Java has created a special code that can be put into a string: ”
. Whenever this code is encountered in a string, it is replaced with a double quotation mark. For example, examine the following:
System.out.println("Jane Campion directed "The Piano" in 1993.");
This code is displayed as the following:
Jane Campion directed "The Piano" in 1993.
You can insert several special characters into a string in this manner. The following list shows these special characters; note that each is preceded by a backslash ().
The newline character causes the text following the newline character to be displayed at the beginning of the next line. Look at this example:
System.out.println("Music by Michael Nyman");
This statement would be displayed like this:
Music by
Michael Nyman
3.23.101.1