Ask your own question, for FREE!
Computer Science 10 Online
OpenStudy (javk):

What are Command Line Arguments? (Java)

OpenStudy (javk):

@woodrow73 @theEric

OpenStudy (e.mccormick):

Same as in any language. A command line is a type of interface. An argument comes from mathematics and is an input to a function.

OpenStudy (rsmith6559):

The tricky part is: all command line arguments are characters or strings, you have to convert any numbers in your program. Java is queer in it's handling of arguments. The array of arguments, Java frequently calls this args other languages call it argv, most languages have the command that invoked the program as the 0th arg. Java doesn't, so it seems to be off by one.

OpenStudy (javk):

I'm sorry I still don't quite get it. What is it doing?

OpenStudy (e.mccormick):

When you run any program, you can send options to the program. This is most evident in command line programs. For example: If I do the dos command dir, I get a direcory listing with all sorts of things on it. But if I just want the program names, nothing else, then I need to add a command line argument: dir /b The /b means bare, as in without all the other stuff. Interestingly, this is basically reversed in *nix systems. The directory listing there is ls for LiSting. By default, it kjust lists the names of files and directories. If I want all the details, I have to add a command line argument: ls -l The -l is for long listing. In any program you can build in the ability to take in these sorts of arguments. They help tell the program what to do when run.

OpenStudy (rsmith6559):

In days of old, before objects became all the rage, everything was a function. The shell is the same. You run a program the same as you run a function in a program: name arg1 arg2 argN name is the program name. If it begins with a slash, it's an absolute path and is launched. If it isn't an absolute path, the shell checks to see if name exists, if it does, it's launched. If it doesn't, the paths in the PATH environmental variable are prepended, in turn, until the executable is found, then it's launched. If nothing has been found by now, an error is returned. Whenever the executable is launched, it is given the command line arguments, which can be treated as positional arguments, or decoded to mean certain things to the program. Positional parameters start counting at zero, zero being the program as called. Any more arguments are 1, 2, 3....N. Java's arg0 is everyone else's arg1. Other than that, it's pretty normal passing parameters. This is a main function that takes an a number and calls another function called count: public static void main( String[] argv ) { count( Integer.parseInt( argv[ 0 ] ) ); }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!