Compiling a Java Program
Systems Configuration
Before compiling your java program make sure that your computer is
properly configured.
That is, when Java 2 (jdk1.3) was installed on your machine, the
autoexec.bat file should be set properly. See:
Download &
Install
Java2 SDK
Compiling From The Command
Line
Java programs can be compiled from the command line in one of three ways.
The method chosen will depend on the location of your program files.
Here are the three possible ways that your files could have been stored.
- All of your java files are in one directory (package).
- Some of your java files are in a subdirectory/subdirectories
(package) of the current directory that contains the class with main.
- Your subdirectories (packages) are on the same level as the
current directory (package) that contains the class with main.
- Your subdirectories (packages) are above the level of the
current directory (package) that contains the class with main.
Cases I & II
Compile
If all of the files are in the same directory, you can compile the program
by enlisting all of the files, or by using the wild card option.
If some of the files are in sub-directories of the current directory, you
can compile the program by enlisting all of the files that are in the
current directory, or by using the wild card option.
When listing the files, use the following pattern:
javac file1.java file2.java ....
When using the wild card option, use the following pattern:
javac *.java
Execute
Use the following pattern to execute the program:
java theMainClass
Cases II & III will be covered when we have looked at inheritance
Go Back