Java Tutorial - lesson one


Lesson One: The first programme that does absolutely nothing at all.

previous lesson - back to tutorial index - next lesson


Copy the next code and past it in your text editor. Save it under the name Main.java (mind the capital M).

//---------------------------------------------
// Class
//---------------------------------------------
public class Main {
//---------------------------------------------
// Methods
//---------------------------------------------
    public static void main(String args[]) {
        System.out.println("Starting the calculator...");
    }
}

Compile this programme by executing ´javac Main.java´ in your DOS/UNIX window and execute it in the same window with ´java Main´.

This programme does nothing but display a text string in your DOS/UNIX window. It seems little, but this piece of code will serve as a tree trunc to which we can attach everything else.

Reviewing the code:
In a line, text after // is not regarded by the compiler, and this can be used to comment your code. ´public class Main {´ defines this class. By convention, names of a class start with a capital. A class is a piece of java code that can be re-used as a building block somewhere else. Because this is the starting class, the function main is defined. This allows the programme to be started by executing ´java Main´ in your DOS/UNIX window. In the main function, a text string is printed to this window.

previous lesson - back to tutorial index - next lesson