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!"
String d14= "\u005cu005a"; seems to compile to \Z which gives the same error. (illegal escape character)
Joined: Jan 21, 2004
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...