Say hello

It is customary to write a small program first, before making larger programs. A small program, with its only task being the display of a text message, saying "Hello, world", is often used. Such a program can be referred to as a Hello world program.

A Hello world program written in Java often starts with a class definition. A class can be thought of as an aggregation of instructions and data, put together for a specific purpose. The instructions inside a class are typically divided into groups, each group in turn having a specific purpose. Such groups are referred to as methods.

The class definition here starts with the line

class Hello

which gives the name Hello to the class. In this example, the class Hello will be the main class used in the program, and the only class created by the programmer. An already defined class, named System, will also be used, for the purpose of getting access to a method called println. This method, which is used in the program as

        System.out.println("Hello, world"); 

makes the string Hello, world appear on the screen of the computer where the program is run. The complete program is shown in Figure 1.

class Hello
{
    public static void main(String[] args)
    {
        System.out.println("Hello, world"); 
    }
}

Figure 1. A hello world program in Java.

This the Java view - other views are C - Python

The program in Figure 1 contains a method named main. The purpose of this method is to define a starting point, so that the operating system knows where to start the program when it is executed.