wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes unicode Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "unicode" Watch "unicode" New topic
Author

unicode

Dan Andrei
Ranch Hand

Joined: Jan 21, 2004
Posts: 92
given the code:
String d14= "\u005cu005a";
String d15="\u0063\u0063\u0063lmn";
System.out.println(d14);
System.out.println(d15);

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 "
StringCharacter:
InputCharacter but not " or \
EscapeSequence
next
2) InputCharacter:
UnicodeInputCharacter but not CR or LF
next
3) UnicodeInputCharacter:
UnicodeEscape
RawInputCharacter
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...
 
jQuery in Action, 2nd edition
 
subject: unicode
 
Similar Threads
Escape sequences and compiler errors
char literals
Comments are not IGNORED!
Dans mock - char escape sequences
Passing two ints (hours and minutes and converting them to proper decimals) ?