Character Literals

Character literals are enclosed in single quotation marks.

Any printable character, other than a backslash (\ ), can be specified as the single character itself enclosed in single quotes. Some examples of these literals are 'a', 'A', '9', '+', '_', and '~'.

Some characters, such as the backspace, cannot be written out like this, so these characters are represented by escape sequences. Escape sequences, like all character literals, are enclosed within single quotes. They consist of a backslash followed by one of the following:

  • A single character (b, t, n, f, r, ", ", or \ )

  • An octal number between 000 and 377

  • A u followed by four hexadecimal digits specifying a Unicode character

The escape sequences built from single characters ...

Get Special Edition Using Java 2 Standard Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.