Posts

Showing posts with the label public static void main (String args[])

What is meaning of main() method in Java ? and Why is main() method public static and void in java?

public  – access modifier, meaning global visibility static  – the method can be accessed straight from the class, we don’t have to instantiate an object to have a reference and use it void  – means that this method doesn't return a value main  – the name of the method, that’s the identifier JVM looks for when executing a Java program Why is main method public static and void in Java? Will the program compile, if the main method is not static? Java program's  main  method has to be declared  static  because keyword  static  allows main to be called without creating an object of the class in which the  main  method is defined. If we omit  static  keyword before  main  Java program will successfully compile but it won't execute. For a little detailed description, look at the usual signature of Java's  main  method public static  void main (String args[]) Above code line begins defi...