If you write static public void
instead of public static void
then it is perfectly OK. Your Java program will compile and run successfully. It doesn't really make any difference as long as method name comes last and return type of method comes second last.
It is generally a convention to put the access specifier (i.e public
, private
or protected
) in the beginning of the method declaration or definition. You can understand the meaning of public
, static
and void
keywords as follows.
public
: It is an access specifier, which defines who can access this method. public
access means this method can be accessed by any class (if other classes are able to access this class, in which the public
method is defined).
static
: It is a keyword that makes sure that statically declared method is class level. You need not to create an instance of the given class in order to access its static members.
void
: It is used to specify return type of the method. When a method's return type is void
it returns nothing.
main
: It is the name of the method, main
method is searched by JVM as an entry point to start running the program. JVM launches the java program by invoking the main()
method.
Note that main()
is defined static
so that the main()
method can be invoked by JVM without instantiating the class.
Hope you have enjoyed reading differences between public static void main
and static public void main
in Java. Please do write us if you have any suggestion/comment or come across any error on this page. Thanks for reading!
Share this page on WhatsApp