URI : Java Glossary
home U words local find no local find frame, full screen Google search web for topic jump to footer translate with Babelfish by Roedy Green ©1996-2008 Canadian Mind Products
Go to : punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all)
URI
née URL, URIs (Uniform Resource Identifier) are a platform-independent way to specify a file or resource somewhere on the web. Strictly speaking, every URL is also a URI, but not every URI is also a URL. Two RFCs specify the format of a URI:RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax, amended by RFC 2732: Format for Literal IPv6 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 but not IPv6 numeric IP addresses in URIs.

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.

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

Formats

Please report examples of other URI formats you see so I can add them to this list.
Types of URI
Example Notes
AIM: America on-line 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 Server) information. You feed these strange double-barrelled URLs to javax.naming.directory.Attributes.DirContext.getAttributes(). See JNDI for more details.
file:///C|/mydir/myfile.txt Old style local file URN. 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 Netscape 4.79 to load a file and it will tell you the URL-encoded name on the top line. JNLP 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:///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 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 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.
http://www.hans.org/index.html#FLUORIDE Hypertext Transfer Protocol. 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 Hypertext Transfer Protocol. It gives userid, password, the site name, the document name within that site.
http://65.110.21.43:80/index.html Hypertext Transfer Protocol, 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 web site 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 URIS. 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 (encrypted secure socket) connections, only work inside Netscape.
SSL: to learn how to add support in browsers that don’t directly support https
icq: ICQ instant messaging service. Also allows file transfer.
jar:file:///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://193.174.106.43:1600/sample,user,password Typical JDBC 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 object.
rtsp: Real Tme Streaming Protocol
telnet://melvyl.ucop.edu/ telnet
urn:isbn:096139210x ISBN 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 references to their most compact canonical form.

Component Parts

HTTP: URI Component Parts
http://roedy@www.mindprod.com:80/products/abc.html?type=all&colour=brown#DEF
Example Part URI.method Name
http://roedy@www.mindprod.com:80/products/abc.html?type=all&colour=brown#DEF toString url
http getProtocol protocol, scheme
getAuthority authority
roedy getUserInfo Userinfo, email address
www.mindprod.com getHost host
mindprod.com - domain
80 getPort port, nearly always 80 for http.
/products/abc.html getPath path, URI: Uniform Resource Identifier
type=all&colour=brown getQuery query, used in CGI queries to pass data to the server.
DEF getRef ref, fragment, reference, target. Not technically part of the URI. Anchor in document to point to.
fragment getFragment part after #, ref, fragment, reference, target. Not technically part of the URI. Anchor in document to point to.

In W95/W98/Me/NT/W2K/XP/W2K3/Vista, *.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:

[DEFAULT]
BASEURL=file://E:\mindprod\jglosse.html
[InternetShortcut]
URL=file:///E:/mindprod/jglosse.html#ESSAYS
Modified=B0D4B81B0AADC001CF
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 ...

URL vs URI

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 URLs

Note getResource creates URLs not URIs.

Learning More

Sun’s Javadoc on the URI class : available:

CMP_homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.16] Visit care2.org
You are visitor number 32,533.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/Mindprod website mirror)
http://mindprod.com/jgloss/uri.html J:\mindprod\jgloss\uri.html