This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Reg. Unicode escape literals 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Reg. Unicode escape literals" Watch "Reg. Unicode escape literals" New topic
Author

Reg. Unicode escape literals

Angela Narain
Ranch Hand

Joined: Apr 14, 2001
Posts: 327
For Unicode escape literals

Is that when we use then as literals value for assigning
to a character we cannot use their hexadecimal equivalent.
For eg:
char c = '\u000a' gives compile error.
so we have to use
char c = '\b';
Pls. correct if wrong and explain to me.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
JLS 3.2 explains very well that topic...
but char c = '\u000a'; is not allowed because when compiled the line would look like this:
char c = '
'; //note the line break
Val


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Just to further Val's post, you cannot use '\u000A' or '\u000D' in a String literal or in single-line comments.
One of the first things the compiler does is evaulate Unicode literals. The above are intrepeted literally as 'newline' and 'carriage return'. They will break your code.
Always use '\n' and '\r'
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Reg. Unicode escape literals