+ 7
Why do we always write String args[] as a parameter in the main() function in Java ?
If I am not wrong in understanding the working of String args[] , it is used to take inputs from command line...so if that is the case then why do we use Scanner or BufferedReader classes to take inputs from the user? Pls, correct me if I'm wrong.
4 ответов
+ 2
You don't have to add it i'm pretty sure, but it is a convention and it is mostly used when running batch files, you can add arguments after running the jar file. It basically gives you an array of the arguments that are inputted after the name of the file.
+ 2
Kindly learn to run your java programs using command prompt to get a better understanding.
+ 2
String[] args stores Java command line arguments and is an array of type java.lang.String class.
String is the object in Java which supports all of the primitive datatypes like int, long, float, double, byte, shot, char. You can easily parse it in any primitive datatype.