Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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 required 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) ?

like image 294
Sanjay Jain Avatar asked Dec 22 '10 06:12

Sanjay Jain


2 Answers

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).
like image 184
Stephen C Avatar answered Nov 15 '22 06:11

Stephen C


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?

like image 26
Falmarri Avatar answered Nov 15 '22 06:11

Falmarri