File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Valid Unicode character assigments

 
Roberto Sanchez
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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'.
 
Roberto Sanchez
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic