• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help on main statement  RSS feed

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can anyone explain to me the meaning of String [] args in :

public static void main (String [] args)

Thanks
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The last time I posted anything with args used was ages ago. Must be well over 10 minutes ago here. Look at the post where I was on about < and &g><.

When you start an application from the command line you can pass additional information after the name of the application. In this case you pass java, then options, then the name of the class you wish to run. After that you can write more things (any number of them until you push "enter". The computer will divide them into an array of things written, and split them into individual bits of writing. In the case I quoted, the extra bits of writing were 123 234 345 etc etc at the bottom of the post. The application receives them in its main method as an array of bits of writing. And bits of writing are called Strings. Try it: write an ArgumentsDemo class then:

java ArgumentsDemo Wee Keong Soh "Wee Keong Soh"

and see what happens.
 
Wee Keong Soh
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks !
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome and I presume you have got an example working.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!