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

前端 未结 17 1494
有刺的猬
有刺的猬 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:01

    I would break up

    public static void main(String args[])
    

    in parts.

    "public" means that main() can be called from anywhere.

    "static" means that main() doesn't belong to a specific object

    "void" means that main() returns no value

    "main" is the name of a function. main() is special because it is the start of the program.

    "String[]" means an array of String.

    "args" is the name of the String[] (within the body of main()). "args" is not special; you could name it anything else and the program would work the same.

    • String[] args is a collection of Strings, separated by a space, which can be typed into the program on the terminal. More times than not, the beginner isn't going to use this variable, but it's always there just in case.

提交回复
热议问题