Java Reference
In-Depth Information
< Day Day Up >
Puzzle 22: Dupe of URL
This puzzle takes advantage of a little-known feature of the Java programming language. What does
this program do?
public class BrowserTest {
public static void main(String[] args) {
System.out.print("iexplore:");
http://www.google.com;
System.out.println(":maximize");
}
}
Solution 22: Dupe of URL
This is a bit of a trick question. The program doesn't do anything special. It simply prints
iexplore::maximize . The URL that appears in the middle of the program is a statement label [JLS
14.7] followed by an end-of-line comment [JLS 3.7]. Labels are rarely needed in Java, which
thankfully lacks a goto statement. The "little-known feature of the Java programming language" to
which the puzzle refers is that you are allowed to put a label on any statement. This program labels
an expression statement , which is legal but useless.
For what it's worth, this would be a more reasonable way to format the program, assuming that you
really want to include the label:
public class BrowserTest {
public static void main(String[] args) {
System.out.print("iexplore:");
http: // www.google.com;
 
 
Search WWH ::




Custom Search