A Java Syntax Quirk
This little trick is shamelessly stolen from Daniele Futtorovic’s post on comp.lang.java.programmer.
This is legal, compilable Java:
public class Oddity { public static void main(String[] args) { http://blog.uncommons.org System.out.println("Why is the URL allowed above?"); } } |
Why doesn’t the URL being in there upset the compiler? If you’re not sure why it’s valid, click “show” for a spoiler.

A label, plus a comment!
Very funny, Thanks!
I’ve seen it somewhere before, isn’t it in the puzzler book?
Nice
Cool
Are you trying to get popular on digg?
lol
Joshua Bloch and Neal Gafter wrote about this in their book: Java Puzzlers. I don’t really think it’s a quirk in the syntax, just a creative way to combine things.
Casper/Ronald, you’re right, it’s puzzle 22. I have that book but I didn’t remember it when I saw Daniele’s post on CLJP.
Very nice!
Very nice… and funny at the same time…
I guess this is not just a Java quirk afterall… isn’t it valid for most C based languages? Appears so to be so.
Nice one. Would be easier to spot with syntax highlighting!
Patrick, you’re probably right. Single-line // comments aren’t strictly valid in C (they are a C++ innovation), but most compilers would probably accept them.
That’s really nice trick!
I was curious if all compilers out there does silently leave this.. It turns out that C# compiler issues a warning that “the label is not used”.
Is there a better way to read comp.lang.java.programmer. instead of going through google groups?
Un problema de sintaxis en Java…
Este texto ha sido "robado" sin vergüenza, del post A Java Syntax Quirk de Dan Dyer que a su…
Single-line comments are in C99 IIRC.
[...] A Java Syntax Quirk [...]
Subu, there are other web interfaces to USENET, though I can’t remember any at the moment.
Otherwise you’ll need a proper news reader. I just use the one built-in to Opera since that’s the browser that I use. You can use Thunderbird or Outlook Express or any of several others.
[...] New Adventures in Software » A Java Syntax Quirk (tags: java puzzle syntax humor programming) [...]
It’s valid in c#. I get a compile error that the label is not in use.
[...] A Java Syntax Quirk [...]
It’s also legal Javascript !
The syntax hilight really makes it look strange, though. Looks buggy, but isn’t
Worked it out in seconds, but it was very interesting to see. Never thought of it myself.
Nice one
// comments are valid in C99, the latest C revision.
Hahaha.. great.. famous..
And if you ever use this in practice, you should be fired.
You can only do it once though. This doesn’t work
main(…) {
http://somesite.com
http://someothersite.com
}
That is cool. Thanks!
URL being there upset the compiler . Iit ain’t valid, unless you are referencing this label somwhere in your code
Oh, it’s old like the world
What about this ?
class String
{
public static void main(String args[])
{
String String = new String();
}
}
[...] A Java Syntax Quirk [...]
Nice one. I would treat this as a trick(?) created by combining two java features.
Keep posting such tricks(?)
[...] Idea originally from here. [...]
Am I missing something? What could you use this quirk for? Forgive me, I’m a frontend developer.
Rauno, I don’t think you should use it anywhere
It’s just an interesting corner case.
[...] source: New Adventures in Software [...]