The first program

Traditionally the first program people write in a new language is called "hello world" because all it does is display the words "Hello, World." In Java, this program looks like:

class Hello {

    // main: generate some simple output
    public static void main(String[] args) {
      System.out.println("Hello, world.");
  }

}


This program includes features that are hard to explain to beginners, but it provides a preview of topics we will see in detail later.

Java programs are made up of class definitions, which have the form:

class CLASSNAME {
    public static void main (String[] args) {
    STATEMENTS
  }
}

Here CLASSNAME indicates a name chosen by the programmer. The class name in the example is Hello. main is a method, which is a named collection of statements. The name main is special; it marks the place in the program where execution begins. When the program runs, it starts at the first statement in main and ends when it finishes the last statement.

main can have any number of statements, but the example has one. It is a print statement, meaning that it displays a message on the screen. Confusingly, \print" can mean \display something on the screen," or \send something to the printer." The print statement
ends with a semi-colon (;).

System.out.println is a method provided by one of Java's libraries. A library is a collection of class and method definitions.

Java uses squiggly-braces ({ and }) to group things together. The outermost squiggly-braces contain the class definition, and the inner braces contain the definition of main.

// at the beginning of the program means it's a comment, which is a bit of English text that you can put a program, usually to explain what it does. When the compiler sees //, it ignores everything from there until the end of the line.