C
C
Core Java
Search…
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.
1
char c1 = 'D';
Copied!
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:
1
char c1 = 122;
Copied!
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 modified 2yr ago
Copy link