This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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 ]
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.