I saw this code in OCPJP SE 8 preparation book written by Boyarsky and Selikoff. I don't understand why the first one throws an exception but the third one doesn't. I tried running it through my compiler but no RuntimeException was thrown. I am really confused. What am I missing?
Are you saying the first one doesn't throw an exception on your machine? It does on a Mac:
Exception in thread "main" java.lang.IllegalArgumentException: URI has an authority component
I'm guessing you are on Windows?
In any case, it is wrong because a URI needs to be an absolute reference so Java can find it.