As I have seen (String[] args) is used to give inputs through Command Line in JAVA. But why we should write it even we are using an IDE like eclipse?
-
you mean for the main method? even in an IDE you can pass parameters to the main method – XtremeBaumer Mar 20 '18 at 10:57
-
Because JVM is written in C, and thats the callback the JVM gives you. And not everyone uses an IDE, so compiled programs/jars shouldn't conform to IDEs only. – Shark Mar 20 '18 at 10:58
-
It is a way to parametrize your application. Even in the IDE or for a graphical application it makes sense: file to open or such. – Joop Eggen Mar 20 '18 at 10:59
-
Cause you can add argument through eclipse (look [here](https://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.cdt.doc.user%2Ftasks%2Fcdt_t_run_arg.htm)) – vincrichaud Mar 20 '18 at 10:59
-
@Shark - It is nothing to do with the implementation language for the JVM. – Stephen C Mar 20 '18 at 11:45
-
@StephenC yes, I am aware, but I had nothing better to say really; it's a pretty logical extension of `main (int argc, char** argv)` – Shark Mar 20 '18 at 13:42
2 Answers
Because an IDE is not a substitute for the Java language. The language itself expects to take a String[]
for its main
method's arguments. People that are not using an IDE will need this as well in order to make their program work.
PS: Take note that you can input command lines in an IDE when executing a program such as a Java main
program. This how you are supposed to use it, in order to simulate a Java execution from an IDE.

- 1,810
- 1
- 19
- 38
Link to similar question link
So the java compiler javac (after ver 1.7) is designed in a way that
when ever any class is complied in java it first checks the main function with signature
public static void main(String[] args)
If it is found then only the program is going to run otherwise it will show you an error
Giving you a YT video link of Durga Sir explained in detailed manner
Part 1 (8 min) enough for this question
Part 2 (10 min) for some more details
After watching this you will never have any doubt in main method
Because same question I also have why we create String array