When the operating system starts your program, it calls a static method called main. (Note that the method must have exactly that name. The operating system will not call a method called Main or MAIN.) You must indicate that main is public to allow the operating system to use it.
The heading for main must be as follows.
public static void main(String[] args)For example, here is a complete Java program that just writes Hello.
public class Hello { public static void main(String[] args) { System.out.println("Hello"); } }
Parameter args is an array of strings and is information passed to your Java program by the operating system. The contents of the args array depends on the command that is used. The system breaks down the command into pieces, normally by breaking it at spaces (or sequences of spaces and tabs). For example, if you perform command
java jump -r data.txtthen array args holds the following
args[0] = "-r" args[1] = "data.txt"
If you put quotes around something in a command, it is made into one thing in the argv array. For example, when command
jump -r -a "some data"is performed, program jump is passed
args[0] = "-r" args[1] = "-a" args[2] = "some data"