Why does Java main() method accept an array of String args?

前端 未结 8 1334
情深已故
情深已故 2021-01-14 06:20

Since its possibly one of the most widely used methods of the Java language, why does it have to accept an array of Strings and doesn\'t work without it? For example, I coul

相关标签:
8条回答
  • 2021-01-14 07:17

    I guess it's because many Java programs will take at least some parameters. Like C (a syntactical inspiration of Java if nothing else), Java considers the best way to provide these as parameters to main.

    Even a GUI program will often take command line parameters. Just because the shell it's launched from typically doesn't ask for these parameters (by default), doesn't mean they're not supported.

    0 讨论(0)
  • 2021-01-14 07:19

    What "vast-majority" of programs do does not really make much difference in terms of what is needed to be done. There are still lots of command line programs that are driven by command line args.

    0 讨论(0)
提交回复
热议问题