Fun with

I'm writing a little app to check the health status of my server and came accross a confusing feature in I remembered I struggle with this behaviour when I came from C# to Java. So this might be helpful for Java newbies.

URL url1 = new URL("");  
URL url2 = new URL("");


The output is:


What? This URLs are not the same, they just run under the same IP. So this sound like a design flaw.

And here is the funny part: While disconnecting the internet connection the output is:


That means that if you have an Internet connection there is a DNS lookup in the equals method. Imagine a map full of URLs...this might be horrible slow.

Let me clarify that this sounds like a bug, but in fact it's documented in the JavaDocs.

By the way, is here to rescue:

        URI uri1 = new URI("");
        URI uri2 = new URI("");