CIS 121 January 28, 2000


Important Concepts
import java.io.*;
import USA.USA;

class TestStream {

   public static void main(String[] args) throws IOException {
      StreamTokenizer       fileParser;
      String                inputFileName;
      FileReader            inputFile;
      int                   tokenType;
      int                   numberCount = 0;
      int                   wordCount = 0;
      int                   otherCount = 0;

      inputFileName = USA.getNameOfExistingFile("Enter name of input file: ");
      inputFile     = new FileReader(inputFileName);
      fileParser    = new StreamTokenizer(inputFile);

      tokenType     = fileParser.nextToken();
      while (tokenType != StreakTokenizer.TT_EOF) {
         switch (tokenType) {
            case StreamTokenizer.TT_NUMBER : {
               numberCount++;
               System.out.println("Number: " + fileParser.nval);
               break;
            }
            case StreamTokenizer.TT_WORD : {
               wordCount++;
               System.out.println("Word : " + fileParser.sval);
               break;
            }
            default : {
               System.out.println("Other token type : " + tokenType);
               otherCount++;
            }
         }
         if ((wordCount + numberCount + otherCount) % 20 == 0)
            USA.pause();
         tokenType = fileParser.nextToken();
      }

      System.out.println("In the file '" + inputFileName + "' we found: ");
      System.out.println("   " + wordCount + " words, ");
      System.out.println("   " + numberCount + " numbers, and ");
      System.out.println("   " + otherCount + " other tokens.");
   }

}
Recall our Classpath Example.
package sub;

public class Abc {

   String name;

   public Abc (String name) {
      this.name = name;
   }

   public String toString() {
      return("(Abc): " + name);
   }

}
package sub;

public class Def {

   Abc myAbc;
   int age;

   public Def (String name, int age) {
      this.age = age;
      myAbc = new Abc(name);
   }

   public String toString() {
      return("I am a Def " + age + " years old and is called " + myAbc);
   }

   public static void main(String args[]) {
      Abc anAbc = new Abc("John");
      Def aDef = new Def("David", 21);
      System.out.println("Abc object is : " + anAbc);
      System.out.prnitln("Def object is : " + aDef);
   }

}
import Sub.Def;

public class UseSub {

   public static void main(String[] args) {
      Def aDef = new Def("Mary", 19);
      System.out.println("My Def: " + aDef);
   }

}