A char is a single UTF-16 character, that is, a letter, number, punctuation mark, tab, space, or something similar.
A char literal - either a single character enclosed in single quotes, such as
char myCharacter = 'g';
or an escape sequence or even a unicode escape sequence:
char a = '\t'; // Escape sequence: tab char b = '\177' // Escape sequence, octal. char c = '\u03a9' // Unicode escape sequence.
It is worth noting that Unicode escape sequences are processed very early at compile time, and therefore using '\ u00A' will result in a compiler error. For special characters, it is better to use escape sequences, i.e. '\ n' instead of '\ u00A'.
Double quotes for String
, you should use the "double quotes escape sequence" ( \"
) inside strings, where otherwise it would end the string.
For example:
System.out.println("And then Jim said, \"Who at the door?\"");
There is no need to avoid double quotes inside single quotes.
The following line is legal in Java:
char doublequote = '"';
VonC Jan 13 '09 at 16:03 2009-01-13 16:03
source share