Is the following a legal Java program? If so, what does it print?
\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0020\u0020\u0020\u0063\u006c\u0061\u0073\u0073\u0020\u0055\u0067\u006c\u0079\u007b\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0073\u0074\u0061\u0074\u0069\u0063\u0076\u006f\u0069\u0064\u0020\u006d\u0061\u0069\u006e\u0028\u0053\u0074\u0072\u0069\u006e\u0067\u005b\u005d\u0020\u0020\u0020\u0020\u0020\u0020\u0061\u0072\u0067\u0073\u0029\u007b\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u006c\u006e\u0028\u0020\u0022\u0048\u0065\u006c\u006c\u006f\u0020\u0077\u0022\u002b\u0022\u006f\u0072\u006c\u0064\u0022\u0029\u003b\u007d\u007d
Of course this is a legal Java program! Isn't that obvious? It prints Hello world. Oh, maybe it's not that obvious. In fact, this program is simply incomprehensible. Every time you do not need to use a unicode escape character, it will make your program more understandable, and the program will take this approach to the extreme. If you are curious, you can see the following code after the Unicode escape characters are converted to the characters they represent:
public class Ugly{publicstaticvoid main(String[]args){System.out.println(“Hello w”+“orld”);}}
The following figure shows the format after formatting:
public class Ugly { public static void main(String[] args){ System.out.println("Hello w"+"orld"); }}
The lesson of this puzzle is that you can not express it in the proper way. Or, if you do this will cause damage, please do not do it! More seriously, this puzzle is a supplement to the previous three lessons: unicode escape characters are required only when you want to insert characters that cannot be expressed in any other way to the program. Otherwise, you should not avoid using them. Unicode escape characters reduce the definition of the program and increase the possibility of generating bugs.
For Language designers, it is possible to use Unicode escape characters to indicate that ASCII characters should be defined as invalid. In this way, the program in puzzles 14, 15, and 17 can be illegal, eliminating a lot of confusion. This restriction does not cause any difficulties for programmers.
Puzzle 17: Um?