开发者

What is the need of String array in the main method of JAVA

What is the need of String array in the main method of JAVA, It is for use of command line argument programming & now a days programming with IDE like eclllipse, netbeans no need to pass any initial arguments.

If this signature of method is r开发者_StackOverflowequired for some purpose, why there is no any main method which is not taking any arguments and JVM invokes it to bootstrap Java program. (If one one dont want to send any initial parameter) ?


Why there is no any main method which is not taking any arguments and JVM invokes it to bootstrap Java program. (If one one don't want to send any initial parameter) ?

  1. Because it is unnecessary. The JVM can trivially (and does) pass a zero length array if there are no arguments.
  2. Because providing multiple entry points doesn't make application command line parsing any easier. Indeed, if there were multiple entry points there would be more scope for platform dependencies, application bugs and/or developer confusion related to which entry point gets called.
  3. Because this is the way that many other languages implement this, and there are advantages in doing things the same way as everyone else (all other factors being equal).


now a days programming with IDE like eclllipse, netbeans no need to pass any initial arguments.

This has absolutely nothing to do with the IDE. How do you think the IDE passes initial arguments? If you don't want to send any arguments, then the array is empty. What's the problem?

Why on earth would you suggest there be 2 entry points to your program?


Think if it this way: the interface for applications/executables is that they take an array of Strings as parameters. If your particular implementation doesn't actually need any parameters fine, but there's no need to complicate the interface by adding another form of main.

And there are many GUI programs that do take parameters. For example, whenever you "Open" a file in Explorer on Windows or a file browser on Linux (and the same may be true of Finder on the Mac but I don't know for sure) the application is executed with the filename as a parameter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜