This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes -descending Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "-descending" Watch "-descending" New topic
Author

-descending

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i was reading sun java tutorial and found this:
public static void main(String[] args)

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


getting curious about it, i wrote this:

i wsnt expecting this:
C:\javas>java TesteOrdenar -descending
a
b
c

How, in the end, does it works?

TiA


java amateur
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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[0], 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
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
never mind: i was thiking of it as a sort of reserved or keyword, like when we type java -version at command line
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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

Right.

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.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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.

Layne


Java API Documentation
The Java Tutorial
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i guess this is what was expected:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: -descending
 
Similar Threads
How to compare ArrayList of objects and get the count?
Sort Arraylist by passing runtime parameter
Development
why no error
Collection program not working as expected