What does (String args []) mean?
Author |
Message |
SJ
|
Posted: Fri Jun 13, 2008 9:10 pm Post subject: What does (String args []) mean? |
|
|
so I see/use this all the time, but don't really get what its function is..
public static void main (String args [])
what is the args array and what is it used for? What kind of parameters are actually passed into it? Is it useful for anything in practice?
thanks, |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
OneOffDriveByPoster
|
Posted: Fri Jun 13, 2008 9:19 pm Post subject: Re: What does (String args []) mean? |
|
|
args[] is for passing arguments to your program. For those familiar with command line interfaces, args[] is for passing options/arguments.
If you run code: | java ProgName some string |
you will find args[] to have "some", "string". |
|
|
|
|
![](images/spacer.gif) |
Epic Tissue
|
Posted: Sat Jun 14, 2008 4:57 am Post subject: Re: What does (String args []) mean? |
|
|
It's a static method called main. The parameter is (and must be) an array of String objects. It is referenced as args, by convention, although any other legal identifier name can be used. |
|
|
|
|
![](images/spacer.gif) |
rizzix
|
Posted: Sat Jun 14, 2008 4:15 pm Post subject: RE:What does (String args []) mean? |
|
|
The main method is the entry point into your program. |
|
|
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: Mon Jun 16, 2008 8:16 am Post subject: RE:What does (String args []) mean? |
|
|
In practice, passing arguments is used when the program is executed from a command-line environment. In some cases, you also pass arguments with a shortcut (an icon that you'd double-click). Those arguments tell the program how to behave.
If you've ever used the command-line (cmd.exe in Windows, or the Terminal anywhere else), then you may have noticed that you'll type things like:
So ps would get a String[] that contained "-ef" as its only element. That tells it exactly what it should display (in this case, the full listing of every process running). |
|
|
|
|
![](images/spacer.gif) |
|
|