Thursday, November 18, 2010

Java main method

Java programming language , every application have must contain a main method , which signature is :

public static void main(String[] args)

The modifier public static can written either (static public) or (public static) but convention is follows public static as shown above.

We can pass parameter String[] args or String[] argv or anything, but convention is args.

The main method is similar to c and c++ main function, It is entry point of application and invoke all other method.

The main method take single argument String array only

public static void main(String[] args)

If we want to pass parameter throw command line argument.

Java HelloJava This is Ram

Here HelloJava is a java class and This is Ram

String array pass to main method.

Length of String[] args = {“This”,”is”,”Ram”}

If I want to print args[0] : This

args[1] = is

args[2] = Ram

If I want print args[args.length]

No comments:

Post a Comment