Compiling and Running Hello World

To make sure your Java environment is correctly configured, bring up a command-line prompt and type

javac nofile.java
If your computer responds with

error: Can't read: nofile.java
you're ready to begin. If, on the other hand, it responds
javac: Command not found
or something similar, then you need make sure you have the Java environment properly installed and your PATH configured.

Assuming that Java is properly installed on your system there are three steps to creating a Java program:

  1. writing the code
  2. compiling the code
  3. running the code
Under Unix, compiling and running the code looks like this:

% javac HelloWorld.java
% java HelloWorld
Hello World
%
Under Windows, it's similar. You just do this in a DOS shell.

C:> javac HelloWorld.java
C:> java HelloWorld
Hello World
C:> 
Notice that you use the .java extension when compiling a file, but you do not use the .class extension when running a file.

On the Mac, you compile files by dragging and dropping them onto the compiler.

For IDEs, consult your product documentation.


Previous | Next | Top
Last Modified September 2, 1997
Copyright 1997 Elliotte Rusty Harold
elharo@metalab.unc.edu