What is “String args[]”? parameter in main method Java

前端 未结 17 1651
有刺的猬
有刺的猬 2020-11-21 23:58

I\'m just beginning to write programs in Java. What does the following Java code mean?

public static void main(String[] args)
  • What

17条回答
  •  野的像风
    2020-11-22 00:13

    When a java class is executed from the console, the main method is what is called. In order for this to happen, the definition of this main method must be

    public static void main(String [])
    

    The fact that this string array is called args is a standard convention, but not strictly required. You would populate this array at the command line when you invoke your program

    java MyClass a b c
    

    These are commonly used to define options of your program, for example files to write to or read from.

提交回复
热议问题