Character Data Type in Java

2 min read ·

The char data type stores a single character.
  • Size: 2 bytes
  • Uses single quotes
  • Internally stores Unicode values
Example:

ASCII Values

Each character has a numeric ASCII value.
Example:
Output:
  • A
  • 65
The ASCII value of A is 65.

Unicode in Java

Java uses Unicode, which supports many international characters.
You can assign characters using Unicode values.
Example:
Output:
  • A
Unicode allows Java to support multiple languages.

Char to int Conversion

In Java, char is internally stored as a number.
Example:
Output:
  • 66
This happens because char is stored as its numeric Unicode value.

Escape Characters

Escape characters are special characters preceded by a backslash.
Common escape characters:
  • \n new line
  • \t tab
  • \ backslash
  • ' single quote
  • " double quote
Example:
Escape characters are very useful when formatting text output.

Boolean and character data types are fundamental in building logic, conditions, and text handling in Java programs.