Other Java™ resources from O’Reilly
Java™ and XML
Java™ Enterprise in a Nutshell
Java™ in a Nutshell
Java™ Performance Tuning
Java™ Programming with
java.oreilly.com is a complete catalog of O’Reilly’s books on
Java and related technologies, including sample chapters and
OnJava.com is a one-stop resource for enterprise Java developers, featuring news, code recipes, interviews, weblogs, and
O’Reilly brings diverse innovators together to nurture the ideas
that spark revolutionary industries. We specialize in documenting the latest tools and systems, translating the innovator’s
knowledge into useful skills for those in the trenches. Visit conferences.oreilly.com for our upcoming events.
Safari Bookshelf (safari.oreilly.com) is the premier online reference library for programmers and IT professionals. Conduct
searches across more than 1,000 books. Subscribers can zero in
on answers to time-critical questions in a matter of seconds.
Read the books on your Bookshelf from cover to cover or simply flip to the page you need. Try it today with a free trial.
Java Network Programming
Elliotte Rusty Harold
Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo
a URL object has been constructed, its fields do not change. This has the side effect of
making them thread-safe.
Creating New URLs
Unlike the InetAddress objects in Chapter 6, you can construct instances of java.
net.URL. There are six constructors, differing in the information they require. Which
constructor you use depends on the information you have and the form it’s in. All
these constructors throw a MalformedURLException if you try to create a URL for an
unsupported protocol and may throw a MalformedURLException if the URL is syntactically incorrect.
Exactly which protocols are supported is implementation-dependent. The only
protocols that have been available in all major virtual machines are http and file, and
the latter is notoriously flaky. Java 1.5 also requires virtual machines to support
https, jar, and ftp; many virtual machines prior to Java 1.5 support these three as
well. Most virtual machines also support ftp, mailto, and gopher as well as some custom protocols like doc, netdoc, systemresource, and verbatim used internally by
Java. The Netscape virtual machine supports the http, file, ftp, mailto, telnet, ldap,
and gopher protocols. The Microsoft virtual machine supports http, file, ftp, https,
mailto, gopher, doc, and systemresource, but not telnet, netdoc, jar, or verbatim. Of
course, support for all these protocols is limited in applets by the security policy. For
example, just because an untrusted applet can construct a URL object from a file URL
does not mean that the applet can actually read the file the URL refers to. Just
because an untrusted applet can construct a URL object from an HTTP URL that
points to a thir