To prepare the program text we have to write a file containing the program. For a Java program, the name of the file has to be
ClassName.java
where ClassName is the name of the class defined in the program. E.g., First.java
The program can be written with any program that allows one to write a text file (editor). E.g., NotePad, Emacs, ...
Example:
The compilation of the program is necessary to translate the program into a sequence of commands that can be directly executed by the computer. The standard Java compiler, which is part of the Java Standard Development Kit (Java SDK), is javac. To use it, you have to execute the command:
javac ClassName.java
The compilation produces as a result a file called ClassName.class, which contains the command that can be directly executed by the computer. For example:
creates the file First.class.javac First.java
A program can be executed only after it has been compiled, i.e., when we have the file ClassName.class.
In Java the execution of a program is done through the command
(without .class). For example, the commandjava ClassName
java First
causes the execution of the program First (or, more precisely, of the main method of the class First), and hence prints on the screen:
This is my first Java program.
There are applications called programming environments, that allow one to carry out the various steps of program writing, compilation, and execution in an integrated way. Examples of Java programming environments are: JavaONE, JBuilder, JCreator, ecc. The following picture shows a screen-shot of BlueJ, a programming environment developed for teaching purposes by the Monash University, Australia, e by the University of Southern Denmark.