Hackerdarshi Hackerdarshi - 1 year ago 69
Java Question

Why does a HTTP URL in Java compile?

If you have a program like this:

public class ABC
public static void main(String args[])

Note the URL
written in between the two output statements.

Why does the program compile without any errors?

Answer Source

The reason the program compiles without error is that the program considers http: as a label, which is allowed in Java, and is mostly used with loops.
The second part, i.e., //example.com is a comment, due to the //, and is therefore ignored by the compiler.

Hence it compiles properly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download