+9  A: 

The URL class gives you everything you need. See http://download.oracle.com/javase/6/docs/api/java/net/URL.html

URL url = new URL("protocol://user:password@host:port/path/document?arg1=val1&arg2=val2#part");
url.getProtocol();
url.getUserInfo();
url.getAuthority();
url.getHost();
url.getPort();
url.getPath(); // document part is contained within the path field
url.getQuery();
url.getRef(); // gets #part
Codemwnci
+3  A: 

In Java, just use the URL class. It provides methods such as getProtocol, getHost, etc. to obtain the different parts of the URL.

Jen
+4  A: 

Use the java.net.URI class for this. URLs are for real resources and real protocols. URIs are for possibly non-existent protocols and resources.

EJP
Then why should I use URI for URL if I am going to operate addresses of real web pages?
Ivan
Because you asked for a parsing implementation, which is what java.net.URI is. java.net.URL is a connection mechanism.
EJP