File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Reg. Unicode escape literals" Watch "Reg. Unicode escape literals" New topic

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

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

[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
I agree. Here's the link:
subject: Reg. Unicode escape literals
It's not a secret anymore!