URLDemo.java

Java class documentation URL

Wikipedia article URL (Uniform Resource Locator)


// Demonstrate URL.

import java.net.*;

class URLDemo {
	public static void main(String[] args) {
		String str1 = "http://www.mhhe.com:80/index.html";
		String str2 = "http://www.udayton.edu:80/index.html";
		try {
			URL url = new URL(str2);

			System.out.println("Protocol: " + url.getProtocol());
			System.out.println("Port: " + url.getPort());

			System.out.println("Host: " + url.getHost());
			System.out.println("File: " + url.getFile());
		} catch (MalformedURLException exc) {
			System.out.println("Invalid URL: " + exc);
		}
	}
}


Results

Protocol: http
Port: 80
Host: www.udayton.edu
File: /index.html

Reference

Herbert Schildt and Dale Skrien, Java Programming, A Comprehensive Introduction,
McGraw-Hill, 2013. ISBN 978-0-07-802207-4. p 993-995.


Maintained by John Loomis, updated Wed Nov 14 13:39:37 2012