Url class example in java

URL  stands for Uniform Resource Locator  which represents a resource on the World Wide Web

A URL can be  into  below parts

Syntax of URL  :


Examples of protocols include HTTP, HTTPS, FTP etc. The path is also referred to as the filename, and the host is also called the authority.

Some useful methods  of URL are as under

Method Name


equals(Object obj) Compares the URL for equality with another object.
getAuthority() Gets the authority part of this URL.
getContent() Gets the contents of this URL.
getContent(Class[] classes) Gets the contents of this URL.
getDefaultPort() Gets the default port number of the protocol associated with this URL.
getFile() Gets the file name of this URL.
getHost() Gets the host name of this URL, if applicable.
getPath() Gets the path part of this URL.
getPort() Gets the port number of this URL.
getProtocol() Gets the protocol name of this URL.
getQuery() Gets the query part of this URL.
getRef() Gets the reference of this URL.

Example program of URL Class

Output of URL Class

URL class in Java
URL class in Java

URL Connection Class Example

(Visited 107 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *

Reload Image