Primitive stuff in SCJP..
HI,
I have just started preparing for SCJP 1.4..I am studying Kathy Sierra and Bert Bates ,All in One Java 2 Book..
I see a section where primitves are explained..and i felt some confusions ...
char c = (char) -98 //Legal
The character is unsigned 16 bit so,how it can be negetive..And again when i am doing a println for any negetive value (-98 0r -29 ,70000etc) I am getting the output> ? .
char d = (char) 70000;
System.out.println("char d = " + d);
//Output
char d = ?
Can any one please explain wat's happening here?
Thanks in advance.
[611 byte] By [
profilemia] at [2007-11-27 9:43:12]

Here is basically what's happening:
-98 is an int litteral. Its binary representation (two's complement) is:11111111111111111111111110011110
the (char) applies a narrowing conversion to -98, thus keeping only the 16 lowest order bits:1111111110011110
the value above represents the number 65438 (remember, the char type is unsigned.)
It is therefore the value of the c variable, and represents a Unicode code point (the HALFWIDTH KATAKANA VOICED SOUND MARK character), which your console is not able to display. Therefore, it converts it into a question mark, as it does for all the characters that are not part of its charset.