Category: character (unsigned integer)

The character category defines only one data type: char.

A char is an unsigned integer.

Ex: Use single quotes , avoid making mistake of using double quotes.

char c1 = 'D';

Internally, Java stores char data as an unsigned integer value (positive integer). It’s therefore acceptable to assign a positive integer value to a char, as follows:

char c1 = 122;

NOTE: The char data type in Java doesn’t allocate space to store the sign of an integer. If you try to forcefully assign a negative integer to char, the sign bit is stored as the part of the integer value, which results in the storage of unexpected values.

Last updated