Java puzzles (puzzle 22)
Puzzle 22: URL Spoofing
This puzzle utilizes a little-known feature in a java programming language. 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 strange problem. When we see this program for the first time, we may think that the program will be compiled incorrectly; But the strange thing is that after you run it, we will find that this program will not do anything special, instead, print the iexplore: maximize directly. Then, let's take a closer look at this program, and you will find the clues. When we learned the C language, we had access to the goto statement, and the label of the goto statement can be expressed by http:, while // can be regarded as a comment line, therefore, the URL in the middle of the program is a statement label followed by the end comment. Because java does not have a goto statement, this causes fewer labels to be used in java, in this puzzle, the reference "little-known features in java programming language" is actually a label that can be placed before any statement. This program marks an expression Statement, which is legal but does not work.
Its value is to remind you that if you really want to use labels, this will be a more reasonable formatting method:
public class BrowerTest{public static void main(String[] args){System.out.ptintln("iexplore");http://www.google.com;System.out.println(":maximize");}}
In fact, this also illustrates that there is no need or reason to use and Add labels and annotations irrelevant to the program. So the lesson we can learn from this puzzle is that misunderstanding of comments and irrelevant code can cause confusion. Write comments carefully and keep them up with the times; remove obsolete code. In addition, if something looks so strange that it is not right, it is very likely to be wrong.