A Simple Java Application

The following program is a simple Java Application:

public class HelloWorldApp {
	public static void main(String args[]) {
		System.out.println("Hello World!");
	}
}
The program consists of a public class definition. The class contains a method or procedure named main(), which is where the interpreter starts executing the program. The body of main() consists of only a single line, which prints out the message "Hello World!" to the console. The keyword public is required and means that anyone (namely the interpreter) can access this method. The keyword static means that this method can apply only to this instance of this class and no other.

IMPORTANT NOTE: the program must be saved in a file with the same name as the public class plus a .java extension.

To compile this program, type:

	javac HelloWorldApp.java

To run with the interpreter, type:

	java HelloWorldApp


Back to Lecture1