12. The main() Method

As promised, we will take a look at the main method.

public static void main (String args[])

So what does this mean?

Program Arguments: Arguments can be passed to the program from the command line and can be accessed in the main() method of the class specified on the command line. These arguments are called program arguments.See the below example.

			package javatutorial;

			/**
			 * Example showing the usage of program arguments
			 * 
			 * @author f5java.com
			 */
			public class MainMethod {
				
				// 1. Prints the program arguments on to the console
				public static void main(String[] args) {
					System.out.println("Printing the program arguments 0 " + args[0]);
					System.out.println("Printing the program arguments 1 " + args[1]);
					System.out.println("Printing the program arguments 2 " + args[2]);
					System.out.println("Printing the program arguments 3 " + args[3]);
					System.out.println("Printing the program arguments 4 " + args[4]);
				}

			}