Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Character ranges

 
Shafeeq Sheikh
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys....
char a = '\u000A';
gives a compiler error but
char a = '\u000B'; compiles cleanly......
Can't seem to figure out the correct range of a CHAR literal....
Can anybody throw some light on this???
Thanks....
 
sushant
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
the problem that u seem to have is that the character '\u000a'
is reserved.
thats the reason that u cant assign it to anything else.
sushant
 
rajsim
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember unicode escapes are processed before actual compilation.
Thus your code
char a = '\u000A';
becomes
char a = '
';
as \u000a is the new-line character

That is clearly an error.
Also check-out '\u0027' which is single-quote
char a = '\u0027';
means
char a = ''';
and '\u005c' which is back-slash.
char a = '\u005c';
means
char a = '\';

 
Shafeeq Sheikh
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this mean that one has to remember/memorize all of these codes so that questions of these types in the SCJP can be answered correctly???
That'll be tough!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic