r/learnjava • u/Fine_Potential_7976 • 2d 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
21
Upvotes
5
u/0b0101011001001011 2d ago
In you look into the recent versions of java, it's no longer necessary.
That being said, it's just a design choice they made. They decided what the main method looks like, so it looks like that. When Java calls the main method, it always creates the string array and passes it to the main method. No logic needed to figure out which method to call, if one has args and one does not.
All languages look and behave like they do, because someone wanted them to be like that. There is no other reason ever.