Hackerdarshi Hackerdarshi - 10 months ago 38
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?


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.