A First Program: Hello World!





The simplest version of this program consists of a single statement:


print("Hello world!")







The PVM simply executes this statement.


Another version embeds this statement in a main function which is called at the end of the module:


def main():

    print("Hello world!")




The PVM executes the function definition and then calls the function.



The simplest version of this program defines a main method within a class:



public class HelloWorld{


    static public void main(String[] args){

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




The source code defines but does not call this method.  At program startup, the compiled class HelloWorld is loaded into the JVM.  The JVM then calls main, which is a class method in HelloWorld.


A Java application must include at least one class that defines a main method.  The byte code file for this class is the entry point for program execution.