Hello World

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

The keyword public means other program parts can access the class. The keyword class means everything in Java should live inside a class. The word HelloWorld is the class name which must be the same as the filename.

The keyword static means the method can be accessed without a class object. The keyword void means the method returns nothing. The word main is the method name, and every Java program must have a main method declared like this. We are using the println method of System.out object to print a line of text on the console. We could use the message to debug our code.

Last updated