• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Need help on main statement

 
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: 64710
226
  • 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: 64710
226
  • 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!