aspose file tools*
The moose likes Beginning Java and the fly likes total newbie to arrays: don't really understand main(String[] args) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "total newbie to arrays: don Watch "total newbie to arrays: don New topic
Author

total newbie to arrays: don't really understand main(String[] args)

Fendel Coulptz
Greenhorn

Joined: Sep 23, 2004
Posts: 24
why "String[] args" in main(String[] args)?
i dun get it... why do we use it for all tha main() methods and how does it work?

thanks in advance...
Jason Fox
Ranch Hand

Joined: Jan 22, 2004
Posts: 114
Real quick, the String[] args part of main means to pass in an 'array of strings'. See About's Java Array Tutorial for a better explanation of arrays than I could give. Read the tutorial (it is vital to understand arrays in Java), then come back to this post.

By allowing an array of strings to be passed from the commandline, Java allows for 'arguments' to be passed. For example:
java MyArgumentExample jason fox

passes the Strings "jason" and "fox" to my java program, to do with as I please. Quick example in action:


If run with the command ' java Example word' will print 'word', or whatever else you pass as an argument.
[ September 28, 2004: Message edited by: Jason Fox ]
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
In java when an application in interpreted by the JVM it starts by calling, that classes 'main' method. The main method excepts an array of the type String as an argument.
Each String in this array is known as a 'command line argument' and through these arguments the runtime system can pass information into your application. A common usage of this feature would be to tell the application the position of a policy or properties file on a particular system. It should also be noted that these command line arguments are non-persistent, for example One could use a command line argument to turn logging on or off so depending on the argument passed to 'main', the application will behave differently.
Fendel Coulptz
Greenhorn

Joined: Sep 23, 2004
Posts: 24
thanks jason n nigel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: total newbie to arrays: don't really understand main(String[] args)
 
Similar Threads
program
java
What is the main usage of "String[] args" in public static void main(String[] args)?
Main method question
Signature of main() method