Hi, Minu - Welcome to JavaRanch. The compiler happens because you're telling the compiler to end the line! Here's what the compiler sees:
and that's a compiler error because the line is not terminated properly, nor is there a "right value" to assign to the variable ch. Why does it do that? Because Java source code files are considered Unicode by default. [ October 10, 2003: Message edited by: Jeff Bosch ]
Give a man a fish, he'll eat for one day. <br />Teach a man to fish, he'll drink all your beer.<br /> <br />Cheers,<br /> <br />Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Because Unicode escapes are processed very early, it is not correct to write '\u000a' for a character literal whose value is linefeed (LF); the Unicode escape \u000a is transformed into an actual linefeed in translation step 1 (�3.3) and the linefeed becomes a LineTerminator in step 2 (�3.4), and so the character literal is not valid in step 3. Instead, one should use the escape sequence '\n' (�3.10.6). Similarly, it is not correct to write '\u000d' for a character literal whose value is carriage return (CR). Instead, use '\r'.
Originally posted by Thomas Paul: You could write your entire program in unicode if you liked. It would be hard to debug though.
Is the following program (UC.java) hard to debug? \u0070\u0075\u0062\u006C\u0069\u0063\u0020\u0063\u006C\u0061\u0073\u0073\u0020\u0055\u0043\u0020\u007B\u000D\u0009\u0070\u0075\u0062\u006C\u0069\u0063\u0020\u0073\u0074\u0061\u0074\u0069\u0063\u0020\u0076\u006F\u0069\u0064\u0020\u006D\u0061\u0069\u006E\u0028\u0053\u0074\u0072\u0069\u006E\u0067\u0020\u0061\u0072\u0067\u0073\u005B\u005D\u0029\u0020\u007B\u000D\u0009\u0009\u0053\u0079\u0073\u0074\u0065\u006D\u002E\u006F\u0075\u0074\u002E\u0070\u0072\u0069\u006E\u0074\u006C\u006E\u0028\u0022\u0048\u 0065\u006C\u006C\u006F\u0022\u0029\u003B\u000D\u0009\u007D\u000D\u007D