Well Everybody knows that java has grown exponentially .Its been used every where right from the mobile phones to the servers.
It has got the largest set of libraries you can find a library for almost everything.
Every one know what i've just written but very few know why always we need to write the signature of main method as above
public static void main(String []args)
we declare the method public because its been called by someone outside the class.That someone is JVM the java interpreter
It has got the largest set of libraries you can find a library for almost everything.
Every one know what i've just written but very few know why always we need to write the signature of main method as above
public static void main(String []args)
we declare the method public because its been called by someone outside the class.That someone is JVM the java interpreter
- We declare the method as static because JVM has no means no instantiate a class but by the very defination of the static is that there is no need for the instantiation of a class if the class contains static methods.
- For more Info about Pan Card heck Here - know your pan
- for calling static methods there is no need to instantiate the class
- we can call static methods directly by using class_name.method name
- void is the return type of the main method .we know that every method has to have a return type in java and this is it void.
- main is the name of the method .One very important observation is that since java is strongly typed language you can't write Main instead of main .Although it will not give you a compile time error but a run time exception will be invoked when you try to run it .Why?
- jvm call a method with signature :public Static void main(String args[]) nothing else so it gives an exception main method not found.
- and finally string[]args its the parameter to the function what every command line arguments to pass while running the java class will the present in the args array.
- NOTE:the parameter can be either string []args or String ...a anything other than that will compile but again run time exception would come because jvm knows only one signature of the string.
hope that helps!