Open In App

Difference Between URL and URN in Java

Last Updated : 09 May, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

URL stands for Uniform Resource Location. A URL contains a protocol, server name or IP Address, Port Number, filename, or directory name. URL is a subset of URI as perceived from the image shown below that describes the network address or location where the source is available.  URL begins with the name of the protocol to be used for accessing the resource and then the specific resource location. URLs build on the Domain Name Service (DNS) to address hosts symbolically and use a file-path-like syntax to identify specific resources at a given host. For this reason, mapping URLs to physical resources is straightforward and is implemented by various Web browsers.

Here, the uniform is related to the uniform identification of the web resources/network-resource i.e. any static or dynamic files hosted on a particular network. And we need a standard way to identify the particular file or resource by its location means which basically contains information about how we can fetch the resource by using location. Generally, we named a URL as a web address.

Illustration:

An XML file does not appear to have any style information associated with ii for which the document tree is as follows:

This 
<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
<Key>wp-content/uploads/2021030515058/g.png</Key>
<RequestId>976QM4R3JWBBPE4Z</RequestId>
<HostId>
yQ/SHq/9wwvXszbY4pAQrZOk+3q6IexIpESeQelGcgX09MVMV6woZFMpaKbXXTrezQqb6HQ7h+4=
</HostId>
</Error>

From the above XML file we can get a fair understanding as follows:

  1. HTTPS is a protocol that we are using.
  2. media.geeksforgeeks.orgis the server name for which access is denied because of security and maintaining the privacy of the organization.
  3. /wp-content/uploads/2021030515058/ is the directory name and g.png is the file name.

Now dwelling on the second concept which is closely related.

URN stands for Uniform Resource Name. It is a URI that uses a URN scheme. URL identifies the web resources/network resource by name in a given namespace followed by colons, followed by namespace-specific strings. URN does not imply the availability of the identified resource.URNs are location-independent resource identifiers and are designed to make it easy to map other namespaces into URN space.

Syntax:

<URN> ::= "urn:" [NID] ":" [NSS]

Note: NID is a namespace identifier and NSS is a namespace specific string.

Illustration:

If it is customary to search on Google the image depicts out that 

  1. URN is a Uniform Resource Name.
  2. ISBN is a namespace identifier. ISBN is used to identify books by book number, it is International Standard Book Number.
  3. 0451450523 is namespace specific string which is the book number.

Now after having adequate knowledge of both URL and URN, let do conclude out major differences between them which are listed in the tabular format below as follows:

URL URN
URL is also called Uniform Resource Locator URN is also called Uniform Resource Name
It uses location to fetch the resource from the network. It is used to fetch the resource by name.
A URL contains a protocol, IP address, port number, directory name, host, etc. It starts with the prefix urn followed by a namespace identifier, followed by a namespace-specific string.
It points to a resource on the world wide web. It is also the subset of URI.
The definitions of URL cannot be used to infer the behavior of the getRequestURI() and getRequestURL() methods. It only identifies a resource but does not indicate its location or how to access it.

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads