Explained: URL and URI Classes

If you’re in tech field or programming field more specifically, you might have worked with URL and URI classes. You might have extracted URL as a string from URI. But what’s the difference between them? Many people get confused with these concepts. Today I will be trying to explain these concepts more clearly and I will try to clear all the confusion around it.

First Things First

URI stands for Uniform Resource Identifier.

URL stands for Uniform Resource Locator.

URN stands for Uniform Resource Name.

URL is a subset of URI i.e. every URL is a URI but the converse isn’t true. The URN is also a subset of URI. The URN is an optional point here and we’re discussing it to complete the URI concept.



To identify a resource on the internet (locally too), we use URI. But how does it look for the resource? It does either by looking for resource name or resource location just like if we need to reach out to someone, we need to know the NAME of the person and the ADDRESS of the person. Here, NAME is given by URN and resource’s address is located by URL. For example,


represents a URL as it specifies the exact location of the resource we are looking for. On the other hand,


represents a URN as it just tells us a name and no resource address.

So what the hell URI will do? A URI can be classified as a locator, name or both. It means, I repeat, every URL is a URI and every URN is also a URI. A URL is a locator, a URN provides name but a URI can do either or both.

Clear The Confusion!

Now let’s get down to the basics. To remember the concepts, keep these in mind:

  • URI that specifies the LOCATION = URL
  • URI that specifies the NAME = URN
  • URI that specifies both the LOCATION and the NAME = URI


Some examples of URI are:

  • mailto:myemailadd@gmail.com
  • news:comp.lang.java

Some examples of URL are:

  • http://www.thewindowsclub.com/ultimate-windows-tweaker-4-windows-10
  • http://www.thewindowsclub.com/fixwin-for-windows-10

URI and URL Classes In Java

So why even bother to use URI class if you can have URL stored as a String or in a URL object? The reason is URI class provides many useful functions to extract a specific part of the URL. A URI is made up of various parts namely scheme, authority, path, query and fragment.


In programming, sometimes we just need to extract specific parts of the URL. URI class provides functions like getPath(), getFragment()and this is the reason we use URI class.


Do share your thoughts in comments 🙂

Related posts