Section 3.8. Review


3.8. Review

We've taken a very quick look at the syntax of Java statements, classes, and interfaces. Much of the syntax is very reminiscent of C, though Java's object-oriented features differ in significant ways from C++. We looked at how to put Java classes into packages, and at the implications of this for locating the .class files.

We also showed what the HTML-based Javadoc documentation looks like. These HTML pages will likely be a handy reference for you as you design and write your Java code.

Example 3.30. Single class example: FetchURL
 import java.net.*; import java.io.*; public class FetchURL {   private URL requestedURL;   public FetchURL(String urlName)   {     try {        requestedURL = new URL(urlName);     } catch (Exception e) {        e.printStackTrace();     }   }   public String toString()   {     String rc = "";     String line;     BufferedReader rdr;     try {         rdr = new BufferedReader(           new InputStreamReader(           requestedURL.openConnection().getInputStream()           )         );         while ((line = rdr.readLine()) != null)         {           rc = rc + line + "\n";         }     } catch (Exception e) {         e.printStackTrace();         rc = null;     }     return rc;   }   public static void main(String[] args)   {     int i;     FetchURL f;     for (i = 0; i < args.length; i++)     {       System.out.println(args[i] + ":");       System.out.println(new FetchURL(args[i]));     }   } } 



    Java Application Development with Linux
    Java Application Development on Linux
    ISBN: 013143697X
    EAN: 2147483647
    Year: 2004
    Pages: 292

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net