i just wonder why it is necessary to have String args[] in main method.
i know it is used for the command line argument, BUT everytime we are running our program, the command line is not necessary.
thanks in advance for answers.
i just wonder why it is necessary to have String args[] in main method.
i know it is used for the command line argument, BUT everytime we are running our program, the command line is not necessary.
thanks in advance for answers.
This is specified in the Java specification.
The method main must be declared public, static, and void. It must specify a formal parameter (§8.4.1) whose declared type is array of String. Therefore, either of the following declarations is acceptable:
public static void main(String[] args)
public static void main(String... args)
If no arguments are given then the array is empty.
You use it for command line arguments as per Java specs. You can also use:
public static void main(String... args)
It is called the vararg notation and means that there can be zero or more arguments.