Package Imports

Instead of importing each class you need individually, you can import an entire package by replacing the class name with an asterisk (*) like this:
import java.net.*;

public class URLSplitter {

  public static void main(String[] args) {
   
    for (int i = 0; i < args.length; i++) {
      try {
        URL u = new URL(args[i]);
        System.out.println("Protocol: " + u.getProtocol());
        System.out.println("Host: " + u.getHost());
        System.out.println("Port: " + u.getPort());
        System.out.println("File: " + u.getFile());
        System.out.println("Ref: " + u.getRef());
      }
      catch (MalformedURLException e) {
        System.err.println(args[i] + " is not a valid URL");
      }
    }
       
  }
}

This does not affect the final compiled code at all. However compilation will take a little longer. In general the time you save in not having to recover from error messages about missing classes more than makes up for the time you lose in compilation.


Previous | Next | Top | Cafe au Lait

Copyright 1997, 1998 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified February 22, 1998