Gp-Java-Main Method in Java
Gp-Java-Main Method in Java
Before explaining the java main() method, let’s first create a simple program to
print Hello World. After that, we will explain why the main() method in java is
public static void main(String args[]).
● public: the public is an access modifier that can be used to specify who
can access this main() method. It simply defines the visibility of the
method. The JVM calls the main() method outside the class. Therefore
it is necessary to make the java main() method as public.
● void: void is a return type of method. The java main() method doesn’t
return any value. Therefore, it is necessary to have a void return type.