Difference Between URL and URN in Java
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 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 identifies the particular file or resource by their location means it basically contains information about how we can fetch the resource by using location. Generally, we named a URL as a web address.
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:
- HTTPS is a protocol that we are using.
- ‘media.geeksforgeeks.org‘ is the server name for which access is denied because of security and maintaining privacy of the organization.
- ‘/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.
<URN> ::= "urn:" [NID] ":" [NSS]
Note: NID is a namespace identifier and NSS is a namespace specific string.
If it is customary to search on Google the image depicts out that
- urn is a Uniform Resource Name.
- isbn is a namespace identifier. ISBN is used to identify books by book number, it is International Standard Book Number.
- 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.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.