Read url properties in java

Method Description
getProtocol() It returns the protocol of the URL.
getHost() It returns the host name of the URL.
getPort() It returns the Port Number of the URL.
getFile() It returns the file name of the URL.
getAuthority() It returns the authority of the URL.
getPath() It returns the path of this URL.
getQuery() It returns the query of this URL.
getRef() It returns the reference of the URL.

Read url properties in java

package com.w3spoint;
 
import java.net.MalformedURLException;
import java.net.URL;
 
public class URLTest {
	public static void main(String args[]){
		try {
			    String url = "https://www.w3spoint.com:8080/";
		            URL myUrl = new URL(url);
		            System.out.println("Protocol: "+myUrl.getProtocol());
		            System.out.println("Host: "+myUrl.getHost());
		            System.out.println("Port: "+myUrl.getPort());
		            System.out.println("Athority of the URL: "+myUrl.getAuthority());
		            System.out.println("Query: "+myUrl.getQuery());
		            System.out.println("Reference: "+myUrl.getRef());
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }
	}
}

Output

Protocol: https
Host: w3spoint.com
Port: 8080
Athority of the URL: w3spoint.com:8080
Query: null
Reference: null
Please Share