Even the simplest java program requires quite a lot of syntactic elements:
1 public class Hello 2 { 3 public static void main(String[] args) 4 { 5 System.out.println("Hello, world!"); 6 } 7 }
-
Line 1:
All java code must be inside a class.
A file that contains the public class Hello should be named Hello.java
-
Line 3:
Every java program executed by the java virtual machine must have a method ( = function ) called main.
The return type of main must be void
main must be qualified to be public and static
The single parameter must be of type an array of Strings.
Note: The name of the parameter to main is typically chosen to be args, but can be any programmer chosen name.