Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unicode

 
Arnb Sen
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

If Unicode characters are represented using hexadecimal, why don't we write in "0x" format ? Why do we write them as "\u" format ?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can write hex integers in Java using 0xNNNN. They're normal numbers, and you can add and subtract them, etc.

A \uNNNN is not a number. The Java compiler translates these "Unicode escapes" into their corresponding characters very early in the compilation process, so that the translated version is what serves as input to the compiler. For example, if you write

int x = 2 \u002b 3;

then the compiler sees

int x = 2 + 3;

and the code compiles just fine. Get it?
 
Arnb Sen
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok.. so this means ---

* 0xNNNN reprsents a number while \uNNNN returns a character.

Thus, if I want '5', I will have to use \u format while if I want 5 I will have to use 0x format.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, If you want '5', you should use '5'.

\uXXXX is turned into program text before the compiler starts to look at the program. You use Unicode escapes to include characters in your program text that you can't type from your keyboard -- i.e., if you want your variables to have names made up of Arabic characters, or you want to print a String in Hebrew.
 
Arnb Sen
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh I see.. just as we used to type alternate texts by pressing ALT and some combination of numbers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic