This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
This array is the mechanism through which the runtime system passes information to your application. Each String in the array is called a command-line argument. Command-line arguments let users affect the operation of the application without recompiling it. For example, a sorting program might allow the user to specify that the data be sorted in descending order with this command-line argument: -descending
For example, a sorting program might allow the user to specify that the data be sorted in descending order with this command-line argument: -descending
...if you write a sorting program that takes a command-line argument and knows what to do with it. This is simply a suggestion of how you might decide to implement a command-line argument.
In your code, the String "-descending" is simply being assigned to args, but never used. The elements of the ArrayList are being printed in the order they were added. See what happens when you enter "j", "a", "v", "a" as elements.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Feb 08, 2004
never mind: i was thiking of it as a sort of reserved or keyword, like when we type java -version at command line
Originally posted by miguel lisboa: never mind: i was thiking of it as a sort of reserved or keyword, like when we type java -version at command line
Note that these hyphenated options are immediately after the "java" command before any file name; whereas arguments are after a file name. You can see a list of options by simply typing java and pressing enter.
Also note that whomever wrote the code for java.exe had to add the code that knows how to deal with the -version option (as well as all the rest it can use). Likewise, if you want to allow users to give command-line options to the programs you write, you have to deal with them explicitly.