Pages

Wednesday, June 13, 2012

Main


To start some application in Java, you must implement the main method. This method is the one who start your application. You can have many main methods implemented, but when you are going to compile your application you must specified which one of them must be executed. The main method must be static, that means it can not own to any class (it is a little ambiguous, because it must be implement inside a class), and can have many arguments as strings.

Here is an example:
public static void main(String[] args){
if (args.length == 0)
System.out.println("No argument was specified");
else if (args.length == 1)
System.out.println("One argument was specified: "+args[0]);
else
System.out.println("Many arguments were specified!");
}

Those arguments can be used to create internal classes or set variables.

No comments:

Post a Comment