wood burning stoves*
The moose likes Beginning Java and the fly likes Valid Unicode character assigments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Valid Unicode character assigments" Watch "Valid Unicode character assigments" New topic
Author

Valid Unicode character assigments

Roberto Sanchez
Greenhorn

Joined: Oct 18, 2007
Posts: 3
Hi,
I was looking the other day some mock exams for the programmer certification exam, and found a question asking if the fllowing is a legal assigment:
char c1 = '\u000A';
I though it was valid, but I found that is not. But, the following is valid:
char c1 = '\u000B';
So, my question is: Why is the first assigment invalid?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Welcome to JavaRanch!

According to JLS - 3.10.4 Character Literals...
Because Unicode escapes are processed very early, it is not correct to write '\u000a' for a character literal whose value is linefeed (LF); the Unicode escape \u000a is transformed into an actual linefeed in translation step 1 (�3.3) and the linefeed becomes a LineTerminator in step 2 (�3.4), and so the character literal is not valid in step 3. Instead, one should use the escape sequence '\n' (�3.10.6). Similarly, it is not correct to write '\u000d' for a character literal whose value is carriage return (CR). Instead, use '\r'.


"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
Roberto Sanchez
Greenhorn

Joined: Oct 18, 2007
Posts: 3
Thanks for your answer!!! By the way, does somebody know if questions like this one is likely to appear in the java programmer certification exam? (Sorry, I know this second question might belong to a different thread).
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Roberto S�nchez:
...does somebody know if questions like this one is likely to appear in the java programmer certification exam? (Sorry, I know this second question might belong to a different thread).

I think it could appear on the SCJP exam, but I don't know how likely this would be.

(We have a special forum for SCJP topics. You might try posting there.)
 
Consider Paul's rocket mass heater.
 
subject: Valid Unicode character assigments