Example 3-1 is the source of an application that displays "Hello World" on stdout. The method accepts arguments in the invocation, but does nothing with them.
// // HelloWorld Application // class HelloWorldApp{ public static void main (String args[]) { System.out.println ("Hello World"); } } |
Note that, as in 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
To compile the application, enter
$ javac HelloWorldApp.java |
It is run by
$ java HelloWorldApp arg1 arg2 ... |