r/learnjava • • Oct 05 '26

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

29 Upvotes

31 comments sorted by

View all comments

41

u/shauntmw2 Oct 05 '26

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 MyJavaApp

The 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.

2

u/cainhurstcat Oct 05 '26

How/where does one learn something like that?

6

u/Significant_Newt8697 Oct 05 '26

Search core java basics youtube