• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

char=100 why is working?

 
barivarasu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai guys
will u please explain me about my doubt
char ch=100;
actuly it is working but as per primitives 100 is a integer literal how it is working
 
kriti sharma
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

java has unicode character set.each character has a integer value equivalent
ranging from 0 - 65535(0 to 2^16-1).u might be knowing the ASCII codes.
'a' is represented by the integer 97 etc.
i hope this clears ur doubt.
 
frank davis
Ranch Hand
Posts: 1479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its called an implicit narrowing of type. its when a literal integer (not a variable) is converted to another type of smaller capacity. It works if the literal is within range of the destination variable. In this case the limit of the destination variable is about 65,000. So if you tried char c = 68,000 you should get an error. The conversion translates the integer into a character as the prior response states.
 
barivarasu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks kriti and solob
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
barivarasu,
Please read the JavaRanch Name Policy and re-register with a name that complies with the rules.
Thanks for your cooperation.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
barivarasu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my name is baladhandapani arivarasu
so barivarasu b'cause of long name
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi barivarasu,
You don't have to use both your full names if you don't want to; but we do require two names .. maybe 'Bari Varasu' ... that would comply with the rules.
Thanks.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic