Browsing WWW with URL classes
The java.net.* package includes URL and its assotiated classes providing a simplified interface to the World Wide Web (WWW) on the Internet. URL class represents a Uniform Reference Locator - a reference to an object on the World Wide Web. This is a constant object, once it is created, its fields cannot be changed. URL object can be created from a string like "http://aol.com". getContent() method of the class returns requested object, that can be a document or image in a GIF format. In such a case, when URL points to GIF file the method returns Image object. URLConnection class represents an active connection to an object pointed by URL. The class constructor starts a URL connection to the specified URL. connect() method of this class provides the second phase of the process making finally the URL connection. It can be used for writing data to specified by URL address. We create URL object first. Then we create URLConnection object using openConnection() method. We prepare the connection for output using setDoOutput() method. Then we can get output stream for the connection and write data out. The data format should be supported by HTTP protocol. URLEncoder class turns Strings of text into x-www-form-urlencoded format URLStreamHandler class is for URL stream openers. It can be used to create streams for particular protocol types. Back To Java Networking