URI : Java Glossary


née URL (Uniform Resource Locator), URIs (Uniform Resource Indicators) are a platform-independent way to specify a file or resource somewhere on the web. Strictly speaking, every URL is also a URI (Uniform Resource Indicator), but not every URI is also a URL. Two RFCs (Request For Comments) specify the format of a URI :RFC 3986: Uniform Resource Identifiers URI : Generic Syntax, amended by  RFC 3986: Format for Literal IPv6 (Internet Protocol Version 6) Addresses in URIs There are many types of URI.

Clever users can even invent new types on the fly, and register them in the java.protocol.handler.pkgs system property. You can specify IPv4 (Internet Protocol Version 4) but not IPv6 numeric IP (Internet Protocol) addresses in URI s.

URI .resolve( String ); lets you construct a new URI using the original as a context to modify. The new URL (String ) constructor lets do the same thing.

Allowable Characters URL vs URI
Formats getResource
Relative vs Absolute Learning More
Component Parts Links

Allowable Characters

URIs must be constructed with the characters 0-9 a-z A-Z $-_.+!*'(), Other characters must be URI-encoded, e.g. space becomes %20 (because space = 0x20) or +, ;/?:@=& need be quoted only when they are not being used for their reserved purpose. For details see the Blooberry Essay. java.net.URLEncoder.encode will encode strings and java.net.URLDecoder.decode will decode strings. Earlier versions of Java were missing the decode and you had to roll your own. Neither java.net.URLEncoder.encode nor java.net.URLDecoder.decode are for encoding/decoding URLs (Uniform Resource Locators). They are for encoding/decoding application/x-www-form-urlencoded form data.

URLs never automatically armour their parameters, where URIs sometimes do.


Please report examples of other URI formats you see so I can add them to this list.
Types of URI
Example Notes
AIM (America Online Instant Messenger) : America online Instant Messenger, an instant mail service.
dbaw://Gloria:8889 Symantec dbAnywhere. Gloria is the name of a local computer on the net with an IP in your HOSTS file. 8889 is the port.
dns://mynameserver.com/mindprod.com JNDI specification of a site for which you want DNS (Domain Name Service) information. You feed these strange double-barrelled URLs to javax.naming.directory.Attributes.DirContext.getAttributes(). See JNDI for more details.
file://localhost/C|/mydir/myfile.txt Old style local file URL. Most browsers today use the C: rather than C| style. To get at a local file you must encode the name in a strange way. That example started out life as C:\mydir\myfile.txt . Use your browser to load a file and it will tell you the URL-encoded name on the top line. JNLP (Java Network Launching Protocol) does not like this form.
file://localhost/C:/mydir/myfile.txt This is a variant of the local file scheme above, popular in more recent browsers. This is the form JNLP likes.
file://localhost/C:/other/mydir/myfile.txt Count’em three slashes after the file: Used to get at a file on local hard disk C:\other\mydir\myfile.txt It is like the localhost form, with the host field left blank.
file://other/mydir/myfile.txt Count’em four slashes after the file: Used to get at a file on remote LAN (Local Area Network) drive \\other\mydir\myfile.txt It is like the localhost form, with the host field and the drive field left blank.
file://localhost/C|/mydir/myfile.txt This is the long form for accessing a local file. It could also be used to access a file on a computer attached via a LAN, by substituting localhost with the host name.
ftp://roedy:sesame@www.hans.org/downloads/getit.zip for FTP (File Transfer Protocol) downloads. roedy is the userid, and sesame is the password. For anonymous FTP, you can leave out the userid and password: ftp://www.hans.org/downloads/getit.zip
FTP for Java client support
gopher://gopher.someplace.edu Gopher protocol is an endangered species largely replaced by HTTP (Hypertext Transfer Protocol).
http://www.hans.org/index.html#FLUORIDE HTTP. It gives the site name and the document name within that site, and the spot within that document. Unfortunately, showDocument in older versions of Opera cannot handle a #FLOURIDE extension.
http://roedy:sesame@www.hans.org/membersonly/goodies.html HTTP. It gives userid, password, the site name, the document name within that site.
http:// :80/index.html HTTP, using an IP and port address 80. It gives the site name and the document name within that site.
myfile.txt Relative URI. Usually this would get you a file on the mother website from which the current page was loaded, relative to the web page being viewed. You can’t use relative URIs directly. You must convert them to absolute URIs using the URI context constructor. An absolute URI must have a complete http: domain, filename and optional #REF. getDocumentBase and getCodeBase are useful in converting relative to absolute URI I know of no tools to go the other way to find the shortest relative URI to express a given absolute URI in a given context. Browsers must convert relative URL links to absolute ones before sending the request to the server.
https://www.hans.org/index.html Secure HTTP for SSL (Secure Sockets Layer) only work inside Netscape.
SSL: to learn how to add support in browsers that don’t directly support https
icq: ICQ (Internet Chat Query) instant messaging service. Also allows file transfer.
jar:file://localhost/C|/bar/baz.jar!/com/foo/Quux.class Local jar file. In JDK1.2+ there are jar URIs for getting at the contents of the individual member of a local jar.
jar:http://www.foo.com/bar/baz.jar!/com/foo/Quux.class Jar on server. In JDK1.2+ there are jar URIs for getting at the contents of the individual member of a remote jar.
jdbc:BorlandBroker://,user,password Typical JDBC (Java Data Base Connectivity) connection.
mailto:someone@somedomain.com Email
n2p: Net To Phone. A scheme where you use the Internet to telephone people without Internet connections.
nap: Napster MP3 file-sharing protocol. Allows peer-to-peer file transfers with a minimum of setup fuss.
news://comp.lang.java.programmer Newsgroup. Needs a newsreader.
pnm: Real Audio streaming format
rlogin: remote login.
rmi://server:1099 rmi access the server.
rmi:Strawberry rmi access an LDAP (Lightweight Directory Access Protocol) object.
rtsp: RTSP (Real Time Streaming Protocol)
telnet://melvyl.ucop.edu/ telnet
urn:isbn:096139210x ISBN (International Standard Book Number) book number

Relative vs Absolute

In Java, the java.net.URI constructor will help you convert a relative URI to an absolute one given the context, e.g. in what webpage the URI link appears. For example, in the context of http://mindprod.com/index.html the relative uri jglossj.html#JAVACEXE is the same as absolute URI http://mindprod.com/jgloss/j.html#JAVACEXE.

However, I have not found any built-in way to convert an absolute URI to the most compact relative representation given a context. You would use this to correct HTML (Hypertext Markup Language) references to their most compact canonical form.


In W95, W98, Me, NT, W2K, XP, W2003, Vista, W2008, W7-32, W7-64, W8-32 and W8-64, *.url files let you create short cuts (bookmarks) to web files on the Internet or your local disk. They are just little text files stored on your disk. If you peek inside one, they look something like this:

When you double click this shortcuts, they wake up a browser and display the web page. You create them inside Internet Explorer with right click ⇒ Save Target As ...


URI is not a subclass of URL . They are independent classes with similar function. URI is more recent, and includes IPv6 formats. You can interconvert them most of the time with the instance methods URL . toURI and URI . toURL

Use of getResource to create URL s


Learning More

Oracle’s Javadoc on URI class : available:
Oracle’s Javadoc on URL class : available:

This page is posted
on the web at:


Optional Replicator mirror
of mindprod.com
on local hard disk J:

Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.
no blog for this page
Your face IP:[]
You are visitor number