Difference between URL, URI and URN - Interview Question

All three URI, URL, and URN are used to identify any resource or name on the internet, but there is a subtle difference between them. URI is the superset of both URL and URN. By the way, the main difference between URL and URI is protocol to retrieve the resource. URL always include a network protocol e.g. HTTP, HTTPS, FTP etc to retrieve a resource from its location. While URI, in case of URN just uniquely identifies the resource e.g. ISBN numbers which are a good example of URN is used to identify any book uniquely. In this article, we will briefly see what is URI, URL, and URN and then see the main difference between URI, URL, and URN.

What is URI
URI stands for Uniform Resource Identifier. URI is a text which is used to identify any resource or name on Internet. URI has two specializations in the form of URL (Uniform Resource Locator) and URN (Uniform Resource Name) to identify resource and name. We mostly see examples of URL and URN in the real word. If you are working on JSP and familiar with using tag library e.g. display tag and JSTL core tag library, then you may remember the use of URI to locate binary corresponding to a tag library.

What is URL
URL standards for Uniform resource locator and it is a subset of URI or Uniform Resource Identifier. URL includes location as well as the protocol to retrieve the resource e.g. in http://java67.blogspot.sg/2012/09/what-is-new-in-java-7-top-5-jdk-7.html, HTTP is a protocol which can be used to retrieve resource what-is-new-in-java-7-top-5-jdk-7.html available in location http://java67.blogspot.com directory. It's not necessary that URL always include HTTP as protocol, it can use any protocol e.g. ftp://, https:// or ldap://.

What is URN
URN stands for Uniform Resource Name. URN is also the subset of URI. One of the best examples of URN is ISBN number which is used to uniquely identify a book. URN is completely different than URL as it doesn't include any protocol.


Difference between URI, URL, and URN

After knowing what is URI, URL, and URN, it's easy to find the difference between them. The main difference between URI and URL is that every URL is a URI but not vice versa. Similarly, every URN is a URI, but the opposite is not true. Another difference between URI and URL is that URL includes the protocol, which is key to retrieving information from any location. Here are few differences between URI, URL and URN in point format:

1) Every URL and URN is URI because URI is the superset of both URL and URN.

2) URL includes protocol e.g. http://, ftp:// along with location to identify resource e.g. http://www.blogspot.com/abc.html.

3) URN are the unambiguous way to identify a resource. ISBN numbers are best examples of URN.

Here is a diagram which clearly reflect the relationship of URL, URI, and URN on the internet:

Difference between URL and URI and URN

That's all on the difference between URI, URL, and URN. It’s good to know how much difference they are though you mostly need to deal with URL.

Other Interview questions from Java67 Blog

1 comment:

  1. I am still not clear about URN.
    Can you please confirm me, according to RFC 3986 is ":" (colon) is reserved character for URN ?