Java main method is the most crucial method in Java programing language. It is by far the only standard method used by JVM to execute a Java program.
Public Static Void main(String[ ] args)
- Java main method is never checked by the compiler however the execution always starts from main method only.
- Except for the main method, all other methods are checked during compilation.
- Public static void main is a predefined prototype of main with a user-defined verdict.
- The main method is called by the kernel, a system software.
- The main is user-defined method having a predefined signature.
Java Virtual Machine (JVM)
A JVM is a computing machine that enables computers to run Java program. It analyses and executes Java bytecode.
Did you know?
As JVM is platform dependent and able to execute the bytecode/class, JVM makes Java platform independent.
Tasks of JVM
The primary job of JVM is to execute the .class file.
The secondary job of the JVM includes:
- Automatic memory management.
- Device driver management.
- Input-output management.
- File management.
- Garbage management.
- Network and socket management.
Why is main method Static in Java?
As the JVM calls the main method by class name and there is no object that exists for the class being called hence the main has to be a static method to allow invocation from outside class. If JVM could create an object for every class then we could have said main as a non-static method.
Why is main method void in Java?
The main method of Java cannot return any value and moreover if main had returned any value then the value would have different meanings between different platforms as Java is a platform independent language. Hence main is void in java.
Why is main method public in Java?
JVM which is present in a different package calls the main method, so, the called method should be designed with the Public keyword or else the caller cannot access/call from outside package. Thus the main method is public in Java.
How things work internally