URL Properties In Java Example
Chapter:
Networking
Last Updated:
09-09-2016 14:45:08 UTC
Program:
/* ............... START ............... */
import java.net.MalformedURLException;
import java.net.URL;
public class JavaURLProperties {
public static void main(String a[]) {
try {
String url = "https://www.javascan.com";
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 ex) {
ex.printStackTrace();
}
}
}
/* ............... END ............... */
Output
Protocol: https
Host: www.javascan.com
Port: 80
Athority of the URL: www.javascan.com:80
Query: query=ok
Reference: header
Notes:
-
The URL class provides utility methods that let you query URL objects.
- You can get the protocol, authority, host name, port number etc. from URL.
Tags
URL Properties, Java