The Puzzle 22:url The Fool
This puzzle exploits a little-known feature in a Java programming language. Please consider what the following program will do?
public class Browertest{public static void Main (string[] args) {System.out.ptintln ("iexplore"); http://www.google.com; System.out.println (": Maximize");}}
This is a bit of a weird question. When we first see this program, we may think that the program compiles errors, but strangely, when you run it, you will find that the program will not do anything special, but instead print iexplore::maximize directly. Well, let's take a closer look at the program and you'll find out. When we learn C language, we have contacted Goto statement, and the mark of the Goto statement can be expressed in http:, and//can be regarded as a comment line, so that the program appears in the middle of the URL is a statement label, followed by the tail comment. Because there are no goto statements in Java, this also leads to less use of labels in Java, and the "little-known features of the Java programming language" referenced in this puzzle can actually place labels in front of any statement. This program labels an expression statement, which is legal, but doesn't work.
Its value is to remind you that if you do want to use the label, then this will be a more reasonable way to format the program:
public class Browertest{public static void Main (string[] args) {System.out.ptintln ("iexplore"); http://www.google.com; System.out.println (": Maximize");}}
In fact, it also shows that we do not need and have no reason to use and add program-independent labels and annotations in the program. So the lesson we can get from this puzzle is that misleading annotations and irrelevant code can cause confusion. Write the notes carefully and keep them abreast of the times, and remove the obsolete code. In addition, if something seems too strange to be true, it is most likely wrong.
Java Puzzle characters (puzzle 22)