aspose file tools*
The moose likes Beginning Java and the fly likes Unicode Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Unicode" Watch "Unicode" New topic
Author

Unicode

Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
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 ?


Regards,<br />Arnab
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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?


[Jess in Action][AskingGoodQuestions]
Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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

Joined: Feb 23, 2004
Posts: 145
oh I see.. just as we used to type alternate texts by pressing ALT and some combination of numbers.
 
Don't get me started about those stupid light bulbs.
 
subject: Unicode