“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”
This is the main method signature, and entry point of execution which is searched by JVM when we execute some class. If no such method exits, JVM throws exception, complains “NoMainMethodFound”..
Now If we don’t provide “public” and give “private” as a access specifier, which is accessible within a class itself, then How JVM class loader will find “main” method and execute it..
The above signature is so because, JVM is a program which tries to access your class code. So, your class code has to be marked public.
It is static because your class is the entry point into the execution, that is why its object cannot exist beforehand. Unless the class is marked static, it would’nt be available to another program(JVM) for access.
It is void because JVM is kind of ’silly’ which just knows how to start the execution. It knows nothing about return types and what to do with the return values. Thats why we say that main method does’nt have anything to return to anybody.
The arguments are String array, as String is the highest data type in Java. Anything can be converted into String and anything can be converted from String to the respective data type. The JVM designers want to give the programmer to choose his arguments, that’s why they chose the highest data type.
private keyword are not use because it is not capable to access the function of another class.
“public static void main(String args[])”
This is the main method signature, and entry point of execution which is searched by JVM when we execute some class. If no such method exits, JVM throws exception, complains “NoMainMethodFound”..
Now If we don’t provide “public” and give “private” as a access specifier, which is accessible within a class itself, then How JVM class loader will find “main” method and execute it..
public static void main(String args[]):
The above signature is so because, JVM is a program which tries to access your class code. So, your class code has to be marked public.
It is static because your class is the entry point into the execution, that is why its object cannot exist beforehand. Unless the class is marked static, it would’nt be available to another program(JVM) for access.
It is void because JVM is kind of ’silly’ which just knows how to start the execution. It knows nothing about return types and what to do with the return values. Thats why we say that main method does’nt have anything to return to anybody.
The arguments are String array, as String is the highest data type in Java. Anything can be converted into String and anything can be converted from String to the respective data type. The JVM designers want to give the programmer to choose his arguments, that’s why they chose the highest data type.
Thanks,
Rohit Raman
Leave an Answer/Comment