Java Characters

The char data type is a single 16-bit Unicode character. It is used to store any character, such as a letter, digit, or symbol.

Key Topics

1. Character Declaration

You can declare a char variable by enclosing a single character in single quotes.

char letterA = 'A';
char digitOne = '1';
char symbol = '@';

2. Unicode Characters

You can use Unicode values to represent characters.

char letterOmega = '\u03A9'; // Greek capital letter Omega
System.out.println(letterOmega);

Output:

Ω

Key Takeaways

  • The char type stores single characters using Unicode encoding.
  • Use single quotes for character literals and double quotes for strings.
  • Unicode allows for a wide range of characters from different languages.