*
The moose likes Beginning Java and the fly likes need clairifications about char type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "need clairifications about char type" Watch "need clairifications about char type" New topic
Author

need clairifications about char type

nada saif
Greenhorn

Joined: Nov 14, 2009
Posts: 8
Hi all ,

I found a strange code i couldn't understand , will be great if any can explain how Java compiler translate it






Output is 15


my Questions are

1- can we use char as number??
2- what is the difference the example above between line 5 ,6


Thanks in advance

Nada


Venu Chakravorty
Ranch Hand

Joined: Aug 19, 2009
Posts: 46
1. 'char' is actually a 16-bit unsigned 'int'
2. in line 5 there is an implicit cast, in line 6 you have to cast the resulting 'int' to a
'short'
nada saif
Greenhorn

Joined: Nov 14, 2009
Posts: 8
Thank you venu ,

But how char is an integer , i am lost ..
can you elaborate in this point .. or post some useful URLs..


Bests,


Nada
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38519
    
  23
Java™ Language Specification. That's the link. It will (I hope) tell you that the char type is an unsigned integer type.

Try this:
nada saif
Greenhorn

Joined: Nov 14, 2009
Posts: 8
Thanks guys, i really appreciate your sense of cooperation .



Good luck.

Nada
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38519
    
  23
You're welcome
Venu Chakravorty
Ranch Hand

Joined: Aug 19, 2009
Posts: 46
you're welcome.
jami siva
Ranch Hand

Joined: Oct 16, 2009
Posts: 63
The word of saying 'Thanks' after getting the reply is boosting for the people who post answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need clairifications about char type