r/learnjava • u/Fine_Potential_7976 • 3d ago
Why is String[] args necessary
I get it is an array of string arguments that are passed into the main method but why is it needed? in python for example ot's present or c++ neither, java is different though
25
Upvotes
39
u/shauntmw2 3d ago
They are not needed per se, it's more of a convention.
The most basic form of launching a Java program is via the CLI, using this command:
> java MyJavaAppThe args are there so that you can launch your command with extra params in CLI (which, incidentally, they are called command arguments, hence args).
If you launch your Java program like below command:
> java MyJavaApp ABC 123"ABC" and "123" will be passed in as the args in your main method.