Wednesday, 6 May 2015

public static void main (String args[]) Explanation

Internally JVM (Java Virtual Machine )  has implemented a method called as public static void main(String[] args)


public static void main(String[] args){
}


public- public means JVM has to find the method form anywhere because of this reason method  declared as public so  JVM can access form anywhere.
 static -  static means without creating instance of the class JVM calls the method main(...). It means that at the time of loading class this method should be in JVM memory and internally it calls the method by CLASSNAME.main(String args[]);.
void- void means main method doesn't return anything.
main( ) - main() means  I can say that it was created by JVM API and JVM implementers followed the same because its a standard.
 String[] args- arguments to main() method of an Array of String type. Objects of type String store character strings. In this case, args receives any command-line arguments present when the program is executed.

JAVA: What if the main() method is declared as private or no main() in a class ?

No comments:

Post a Comment