Symphonious

Living in a state of accord.

java.net.URL or java.net.URI?

I'm going to show my ignorance of the actual differences between URLs and URIs here, but I was a bit surprised by the fact that java.net.URL didn't extend from java.net.URI. Along those lines URL.toURI() suggests that some URLs can't be converted to URIs. Is this just in the context of the URLs that Java previously successfully parsed or is this a generic constraint?

My main reason for asking is I'm trying to determine, when implementing an HTTP caching library, I should be using java.net.URI or java.net.URL to identify the source of resources. My original thought was to use java.net.URL because that's what pretty much everything uses and besides I'm used to support Java 1.3 (URI was only added in Java 1.4). Somehow that seemed overly specific and I should use URI instead. Partly this is because it felt more generic and partly because it just seemed to have more geek cred. I must admit though I really don't have a firm grasp on which I should use when and why. So dear lazy web, can you help?