Previous | Next | Trail Map | Writing Java Programs | The Anatomy of a Java Application


Saving, Compiling and Running an Application

Follow the steps outlined below to save, compile, and run your Java program. These instructions give only the minimum information that you need to compile and run the example program for this lesson. For more information about the compiler, the interpreter, and structuring and managing your programming environment, see the appropriate lesson in The Java Development Environment .

Saving a Java Program

You can use any editor or word processing program to create and edit a Java program, as long as it can save files in ASCII format. Java programs must be saved in a file whose name ends with the .java extension, so using your favorite ASCII editor, enter the program exactly as it appears on the first page of this lesson and save the program to a file named DateApp.java.

Compiling a Java Program

Having created your Java program, you must compile your program using the Java compiler before can you run it. If you have any problems, see Troubleshooting Compiler Problems .

The Java compiler translates Java source code into Java bytecodes which are components of a machine-level language for the Java virtual machine. Java bytecodes are interpreted and executed by the Java interpreter.

When you compile a Java source file, the compiler creates a file with the .class extension in the same folder as the source file. The compiler names the resulting .class file after the class defined in the source file. For example, when you compile the DateApp class you created above, the compiler names the resulting class file DateApp.class after the class, regardless of the name of the source file. Even if you were to save the DateApp class to a source file named Wow.java, the compiler would still create a file named DateApp.class. By convention, to alleviate confusion, Java source files are named for the class defined within.

Running a Java Application

Now, you can run your application using the Java interpreter. The program should display the current date and time. If you have any problems, see Troubleshooting Interpreter Problems .

See Also

Compiler Man Page
Interpreter Man Page


Previous | Next | Trail Map | Writing Java Programs | The Anatomy of a Java Application