Sunday, July 3, 2011

WHAT IS THE MEANING OF public static void main(String args[])

Some one explain what is means of static and (String arg[]) use in java.
public static void main (String arg[])
Why this term is used in java program?
this is command line argument ..
when we define any fun by static then we this is call automatically

public-----bcz main() is called by jvm which is totally an external code......
static------bcz main function should be one unique function in memory......
void----main() in java is not supposed to return ant status message to OS like C,C++....so return type is void.....
String args[]-------to accept command line arguements.....

public means our program is available to JVM to execute. Because JVM is also another program.If main method is not declared as public then JVM fails to execute main method


static means without creating object execute that method.To create object main has to execute.Without object it is not possible to execute main method.To avoid this problem static keyword is used that means main method is executed without object.
void means it doesn't return any value
String args[] used for taking command line arguments.
static public void main(String args[])....Valid
public static void main(String x[])....These are also valid in java

static is used to avoid any chance of multiple main threads....just to avoid object creation,static is nowhere used...Even As a programmer,we think of using static only when we want only one copy of dat variable or method in memory....