Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

-descending

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i guess this is what was expected:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic