This document instructs you on how to setup a Java programming
environment for your Mac OS X computer and provides a step-by-step
guide for creating, compiling, and executing a Java program.
You must be using Mac OS X v 10.4.5 Tiger or later.
(Previous versions do not support Java 1.5.)
All of the software is freely available on the Web.
|
|
To check if Apple's implementation of Java 2 Standard Edition (J2SE 5.0) is already installed:
|
|
You will develop your Java programs in an application called DrJava. DrJava features many specialized programming tools including syntax highlighting, bracket matching, auto indenting, indent shifting, and line numbering. To install DrJava:
|
|
Now you are ready to write your first Java program.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
|
|
It is now time to convert your Java program into a form more amenable for execution on a computer. To do this, click the Compile button.
If all goes well, you should see the following message in the Compiler Output window at the bottom:
Compilation completed.
If DrJava complains in some way, you mistyped something, and you should check your program carefully. Use the error messages in the Compiler Output window to guide your search.
|
|
Now it is time to run your program. This is the fun part.
Welcome to DrJava. Working directory is /Users/wayne/introcs/hello > java HelloWorld Hello, World
|
|
How do I break out of an infinite loop in DrJava? Click the Reset button in the menubar or select the menu option Tools -> Reset Interactions.
How do I use Java from the command-line. Here are instructions for compiling and executing Java from the command-line.