Forums Register Login

-descending

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
never mind: i was thiking of it as a sort of reserved or keyword, like when we type java -version at command line
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
i guess this is what was expected:
Normally trees don't drive trucks. Does this tiny ad have a license?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 713 times.
Similar Threads
Collection program not working as expected
Sort Arraylist by passing runtime parameter
How to compare ArrayList of objects and get the count?
Development
why no error
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:13:38.