Compiling and Running a Java Program in Clapp 202 (Windows)
- Optional: Create a new directory where you will store the files for the program. This step is more important if you are using packages. I am not requiring that you use packages for your assignments in this class. But, if you do use packages, you must create a directory tree that matches your package name. For example, if you have a package named "networks.webserver", all files in that package MUST be in a directory named "webserver" that is in a directory named "networks".
- Open up your favorite text editor and write your code. You
can write your code using JBuilder, but for your first
assignment you should compile using java 1.1.8. This is not the
version of java JBuilder uses. What this means is that instead
of using the "Build" function in JBuilder, you should open up a
command window, navigate to the directory where JBuilder has
saved your code, and use the command line instructions to
compile and run your program.
- Save the file. Important: The name of the file must be the class name with a .java extension. If you are writing a class named Test, your file MUST be named Test.java.
- cd into the directory where your code has been saved. Note: I am assuming that you are not using packages..
- In order to compile, the java compiler must be in your path
OR you must use the absolute path name to specify the location
of the compiler. The Java 1.1.8 compiler is located in
C:\tools\jdk1.1.8\bin. To set your path (in windows), type
set PATH=c:\tools\jdk1.1.8\bin;%PATH%
- Compile by typing javac filenames where filenames are space-separated names of the files you wish to compile. You can compile more than one file at a time. For example, javac UIExample.java GetListener.java. If the compiler doesn't spit out any errors, it should have generated a ".class" file for every compiled file (UIExample.class and GetListener.class in the example above). Do a "dir" to verify the class files are there.
- Run by typing java classname. Here, you must only specify ONE classname -- the name of the class that contains your main method. For example, java UIExample.
- You should see the output and/or the UI window if your program uses UI components.
Sami Rollins