Tuesday, January 22, 2013
Difference between URL, URI and URN - Interview Question
All three URI, URL and URN are used to identify any resource or name in internet but there is subtle difference between them. URI is super set of both URL and URN. By the way 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 resource from its location. While URI, in case of URN just uniquely identifies the resource e.g. ISBN numbers which are 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 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 in Internet. URI has two specialization in 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 real word. If you are working on JSP and familiar with using tag library e.g. displaytag and JSTL core tag library, then you may remember 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 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 subset of URI. One of the best example 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.
After knowing what is URI, URL and URN, its easy to find difference between them. Main difference between URI and URL is that every URL is an URI but not vice versa, similarly difference between URI and URN is that every URN is a URI but opposite is not true. Another difference between URI and URL is that URL includes protocol, which is key to retrieve 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 super set 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 unambiguous way to identify a resource. ISBN numbers are best examples of URN.
That's all on 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