[an error occurred while processing this directive]

Programming Assignment 1 - Step 1


Writing a Simple Version of the VectorSorter Class

A Java class definition usually has the form
    public class ClassName {

	definition of object variables and methods

    }
The class definition should be placed in a file named ClassName.java. Here, ClassName is the name of the class that you are defining. If you follow Java naming conventions, the name of each word in the class name should be capitalized. Spaces cannot be used in a class name.

Following this template, write a preliminary definition for the VectorSorter class. This preliminary definition will not have any object variables or methods so you will have nothing but a blank line between the braces in the class definition.

Before the class definition, you should also add an import statement:

    import java.util.*;
This allows you to use any class from the Java library package java.util. This package contains, among other things, the Vector class that you will be working with later.

After you have put the import statement and class definition into an appropriately named file, you can compile it with the Unix command

    javac ClassName.java
The compiler will create a file named ClassName.class. Try this with your VectorSorter class. You should not get any error messages from the compiler.

Setting Up Your CLASSPATH Environment Variable

When you write Java code, you will frequently make use of classes in the Java standard class library. These classes are organized into packages. You can use classes in the package named java.lang without doing anything special in your code. For other standard library classes, and for other classes that you are using from outside your current working directory, you need an import statement as described above. Most of the classes that you will write for this course will import classes from the standard package java.util so you will often need to import that package.

In addition, some of the classes that you write will need to import classes from packages that I will provide. In order to do this, you need to define a Unix environment variable to tell the compiler where my packages are. The easiest way to do this is to add the following line to the .cshrc file in your home directory.

    setenv CLASSPATH ~gshute/public/java/classes:.
Be sure to copy this exactly, including the period at the end. Doing this, by itself, has no immediate effect because the .cshrc file is only read when you log on to one of the Unix machines. In order to have an effect without logging out and logging back on, you should give the command
    source .cshrc
You will only have to do this one time; the next time you log in, the .cshrc file will be read automatically.

In the next section, you will write another simple class with an import to check your class path.

Writing a Simple Version of the Test1 Class

Your Test1 class, like the VectorSorter class, will start out with no variables or methods. This class should have two import statements:
    import java.util.*;
    import gshute.util.*;
As in the VectorSorter class, the import statements should appear before the class definition.

After you have put the import statement and class definition into an appropriately named file, you can compile it as described above. If you do not get any error messages then your class path is set up correctly and you are done with this step.

[an error occurred while processing this directive]