wood burning stoves
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes unicode Big Moose Saloon
Register / Login

Bookmark "unicode" Watch "unicode" New topic


Dan Andrei
Ranch Hand

Joined: Jan 21, 2004
Posts: 92
given the code:
String d14= "\u005cu005a";
String d15="\u0063\u0063\u0063lmn";

for the first line I get the following compile error:
C:\j2sdk1.4.2_03\JLS2.0\TestUnicode.java:33: illegal escape character
I use j2sdk1.4.2. compiler
the second line compiles fine and prints : ccclmn as expected
in my opinion the first line should compile and print \u005a, since
\u005c is the Unicode for \
IF I add another \ to the beggining of the escape sequence it compiles fine
and prints \u005cu005a whic is OK also.
Am I wrong?

"Did anyone understand what I have just explained? ... because I did not!"
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
String d14= "\u005cu005a"; seems to compile to \Z which gives the same error. (illegal escape character)
Dan Andrei
Ranch Hand

Joined: Jan 21, 2004
Posts: 92
no it doesn't , this is from JLS 2.0:
"The character produced by a Unicode escape does not participate in further Unicode escapes. For example, the raw input \u005cu005a
results in the six characters \ u 0 0 5 a, because 005c is the Unicode value for \. It does not result in the character Z, which is Unicode
character 005a, because the \ that resulted from the \u005c is not interpreted as the start of a further Unicode escape."
However I might have foun an expalnation for the error:
The grammar for string literals is the following:
1) StringLiteral:
" StringCharactersopt "
InputCharacter but not " or \
2) InputCharacter:
UnicodeInputCharacter but not CR or LF
3) UnicodeInputCharacter:
so from this I understand that you cannot have in a string literal
an Unicode escape for \ " CR or LF
So we have to use ecape sequence in order to print those characters ?
can someone give some input on these please...
subject: unicode
It's not a secret anymore!