File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes char literal question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "char literal question" Watch "char literal question" New topic
Author

char literal question

Brian Nguyen
Greenhorn

Joined: Mar 19, 2002
Posts: 22
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

Joined: Aug 31, 2004
Posts: 11343

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 ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: char literal question
 
Similar Threads
Dan question
Doubt for char in K&B
Character Literals
Bit operatation question
Confusion creating String