Java Puzzle characters (puzzle 22)

Source: Internet
Author: User

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");; 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");; 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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.