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 (LabAssignments), then the source code folder (src). In your source folder should be a folder called lab1.

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

We use the javac command to compile the contents of the lab1 directory into the current directory.
javac -d . lab1/*.java

To execute your code, use the command

java lab1.HelloWorld