Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Range of char in java

Tags:

java

The following line of Java code produce error.
Even though datatypes in java are signed?

    char c = -128;  
like image 808
ghostrider Avatar asked Nov 27 '22 17:11

ghostrider


2 Answers

Char is the one data type that isn't signed in java. Its a 16 bit unsigned integer.

like image 107
yhyrcanus Avatar answered Dec 10 '22 10:12

yhyrcanus


Straight from the Oracle tutorial for Java datatypes.

char: The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).

like image 34
munyengm Avatar answered Dec 10 '22 11:12

munyengm