Hello, World in Java on Mac OS X

This documents instructs you on how to setup a Java programming environment for your Mac OS X computer and provides a step-by-step guide to creating, compiling, and executing a Java program. We assume you are running at least OS X 10.2.3. All of the software is freely available on the Web.


You will use the Java compiler javac to compile your Java programs and the Java interpreter java to run them. Mac OS X includes implementation of Java 2 Standard Edition (J2SE) 1.4.1, so there is nothing to do in this step.

Command line interface

You will type commands in an application called the Terminal. You might enjoy reading Neal Stephenson's light-hearted essay In the Beginning was the Command Line.

Text Editor

You will type and edit your programs in a text editor called JEdit. JEdit is similar to conventional word processors like MS Word, but it features many specialized programming tools including syntax highlighting, bracket matching, auto indenting, indent shifting, line numbering, and commenting out code. It's even written in Java.

Apple purists may prefer Project Builder which can be found in the Finder via Computer -> OS X Partition -> Developer -> Applications -> Project Builder.

Create the program

Now you are ready to write your first Java program.

Compile the program

It is now time to convert your Java program into a form more amenable for executing on a computer.

Execute the program

Now it is time to run your program. This is the fun part.

Congratulations, you are now a Java programmer!


When I try to run java I get: Exception in thread "main" java.lang.NoClassDefFoundError Your CLASSPATH may have been set by some other program so that it no longer includes the current working directory in the search path. Try running your program with the command line

[username:] ~/introcs/hello> java -classpath ./ HelloWorld