This page is obsolete.
This document instructs you on how to use the Mac OS X Terminal with Java.
You will use the Java compiler javac to compile your Java programs and the Java interpreter java to run them. To verify that Apple's implementation of Java 2 Standard Edition (Java SE 6) is already installed:
You will type commands in an application called the Terminal.
Then typemachine:~ wayne$ java -version java version "1.6.0_26" Java(TM) SE Runtime Environment (build 1.6.0_26-b03-384-10M3425) Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-384, mixed mode)
machine:~ wayne$ javac -version javac 1.6.0_26
You will use the javac command to convert your Java program into a form more amenable for execution on a computer.
machine:~ wayne$ cd introcs/hello machine:~/introcs/hello wayne$
If everything went well, you should see no error messages.machine:~/introcs/hello wayne$ javac HelloWorld.java machine:~/introcs/hello wayne$
You will use the java command to execute your program.
If all goes well, you should see the output of the program - Hello, World.machine:~/introcs/hello wayne$ java HelloWorld Hello, World
|Input and Output|
If your program gets stuck in an infinite loop, type Ctrl-c to break out.
If you are entering input from the keyboard, you can signify to your program that there is no more data by typing Ctrl-d for EOF (end of file). You should type this character on its own line.
When I try to run java I get: Exception in thread "main" java.lang.NoClassDefFoundError. First, be sure that HelloWorld.class is in the current directory. Be sure to type java HelloWorld without a trailing .class or .java. If this was not your problem, it's possible that your CLASSPATH was set by some other program so that it no longer includes the current working directory. Try running your program with the command line
If this works, your classpath is set incorrectly.machine:~/introcs/hello wayne$ java -cp ./ HelloWorld
I get the error "class file has wrong version 50.0, should be 49.0" when I compile from the Terminal. What does this mean? It's probably because DrJava is configured to use Java 6.0 and and your Terminal is configured to use Java 5.0. To change the default version of Java in your Terminal, launch Java Preferencest. Drag the Java SE 6 - 64-bit entry to appear first.
How do I get the menu to display at the top of the screen instead of at the top of the frame? Execute with java -Dapple.laf.useScreenMenuBar=true
Where can I learn more about the command line? Here is a short tutorial on the command-line.