char myCharacter = 'g';
Some characters are hard to type. For these Java provides escape sequences. This is a backslash followed by an alphanumeric code. For instance '\n'
is the newline character. '\t'
is the tab character. '\\'
is the backslash itself. The following escape sequences are defined:
\b | backspace |
\t | tab |
\n | linefeed |
\f | formfeed |
\r | carriage return |
\" | double quote, " |
\' | single quote, ' |
\\ | backslash, \ |
System.out.println("And then Jim said, \"Who's at the door?\"");
It isn't necessary to escape the double quote inside single quotes. The following line is legal in Java
char doublequote = '"';