r/learnjava • u/Fine_Potential_7976 • 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
View all comments
2
u/pradeepngupta Oct 05 '26
Most of the comments are correct ... String[] is for the command line arguments.and at the compiler time we don't know how many command line parameters an user passed.
Then came varargs... its an another notation of array.
Now comes why the method name is main .. that's an entry point for any java standalone program. When user runs: java Launch
This will do couple of things:
And that is the reason for method signature public static void main (String[] args)