Java Language Literals Character literals

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!


Character literals provide the most convenient way to express char values in Java source code. A character literal consists of:

  • An opening single-quote (') character.
  • A representation of a character. This representation cannot be a single-quote or a line-break character, but it can be an escape sequence introduced by a backslash (\) character; see Escape sequences in literals.
  • A closing single-quote (') character.

For example:

char a = 'a';
char doubleQuote = '"';
char singleQuote = '\'';

A line-break in a character literal is a compilation error:

char newline = '
// Compilation error in previous line
char newLine = '\n';  // Correct

Got any Java Language Question?