Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 What does (String args []) mean?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
SJ




PostPosted: 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,
Sponsor
Sponsor
Sponsor
sponsor
OneOffDriveByPoster




PostPosted: 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".
Epic Tissue




PostPosted: 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.
rizzix




PostPosted: 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.
DemonWasp




PostPosted: 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:

code:
ps -ef


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).
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: