Java Reference
In-Depth Information
web pages. Many other features of Java, however, extend Java network program-
ming far beyond just applets. Some of these network-related capabilities include
the following:
java.net contains numerous network-related classes.
Remote Method Invocation (RMI) packages allow a Java program running on one
machine to invoke Java methods in a program running on another machine.
The Streaming I/O architecture in Java provides for a uniform structure in that I/O over
a network is treated the same as I/O to a disk or the console.
Serialization allows objects to be deconstructed, sent over a network, and then recon-
structed on another machine (see Section 9.8).
Threading helps to build server programs since they can create separate threads to tend
to new clients as they connect.
java.security and other packages allow for secure interactions over networks.
Portability of java means that Java networking programs developed on one type of
platform can also run and communicate with each other when used on other platforms.
In the rest of this chapter and the other chapters of Part II, we discuss these and
other features that make Java a powerful tool for network programming.
13.5 The URL class
Browsers obtain resources from the web by specifying web addresses, which are
officially called Uniform Resource Locators (URLs). The formal description of
the URL components goes as follows:
Protocol - ID://Host - IP - address:Port/Filename#Target
The components of the URL include:
Protocol - ID - HTTP , FTP , etc.
Host - IP - address - host name in either numerical IP or hostname format
Port - port number. Default is 80 if omitted
Filename - name of a hypertext web page or other type of file. Default is index.html
or index.htm . The file name can include a directory path such as /data/run5.html
Target - optional reference address within a web page
In Java a URL can be represented by an instance of the java.net.URL class.
Forexample, in an applet you can obtain the URL address of the location of the
applet's code with the method
public URL getCodeBase ()
If you want to download an image from the same directory where the applet code
is located, you can use
getImage (getCodeBase (), filename);
This method combines the URL returned by getCodeBase() with the image
file name to create a URL to locate and download the image file.
Search WWH ::




Custom Search