System Interface Guide

An Application

Example 2-1 is the source of an application that simply displays "Hello World" on stdout. The method accepts arguments in the invocation, but does nothing with them.


Example 2-1 A Java Application

//
// HelloWorld Application
//
class HelloWorldApp{
	public static void main (String args[]) {
		System.out.println ("Hello World");
	}
}

Note that, like C, the method, or function, to be initially executed is identified as main. The keyword public lets the method be run by anyone; static makes main refer to the class HelloWorldApp and no other instance of the class; void says that main returns nothing; and args[] declares an array of type String.

The application is compiled by

$ javac HelloWorldApp.java

It is run by

$ java HelloWorldApp arg1 arg2 ...