Compiling Java code

Compiling code on the command-line

As discussed on the first slide, all the code is contained in the workspace you specified in the home directory. If you followed the example image, your workspace is a folder called CMSC202 in your home directory.

Browse to your project folder (Lab1), then the source code folder (src). In your source folder should be a folder called proj1.

The example below illustrates how to compile your lab1 code directly from a UNIX terminal.

The first step will be to create a directory called /bin, which we do with the following command:

mkdir bin

Next, we use the javac command to compile the contents of the proj1 directory.
javac -d bin proj1/*.java

To execute your code, use the command

java lab1.Lab1