This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

char literal question

 
Brian Nguyen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I just have a little question about char literal:

char c6 = '\uface';

Why the above declaration valid? As I know if we use hexadecimal literal, we have to put a prefix with 0x. Does that mean that if we use unicode, the base would be hexadecimal?

Thanks,
Brian
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My understanding is that the Unicode \u is always followed by exactly 4 hexadecimal digits. Hexadecimal is implied by the \u, so the prefix of 0x (as used with Java numeric literals) is not needed.

But here's where I'm stuck...

These characters compile for me; but those above \u007f (the 128 non-extended ASCII characters) just display as question marks. In reviewing previous posts here, I gather that hexadecimal Unicode is converted to characters before the code is compiled. So, is this a limitation of the application in which the source code is saved (e.g., Wordpad)?


[ September 22, 2004: Message edited by: marc weber ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Based on what I've found in a Sun forum, the Windows Command Prompt is capable of displaying only the non-extended ASCII characters, so anything beyond \u007f will default to the question mark. However, in a Java GUI, the proper Unicode character should display.

Ref: http://forum.java.sun.com/thread.jsp?forum=31&thread=335146

As far as the SCJP exam goes, my understanding is that you need only recognize that '\uXXXX' is the format for a Unicode character (where X represents a hexadecimal digit, 0-f). You should not be asked to convert these.


[ September 22, 2004: Message edited by: marc weber ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic