Main method of java under the hood?
Whenever i am trying to execute my java.exe by specifying the class name (java Test.java where test is the name of class) then it request for some memory from the operating system. In case , if the requested memory isn’t available then JVM will not be started and the error message will be displayed on the screen as “ OutOfMemoryError”.But if the memory is available then JVM will be started and do the tasks as mention below :-
- It creates thread groups like system thread group, main thread group and many more .
- it creates some thread like finalizer and add to corresponding thread groups. Finalizer thread will added to system thread group.
After the steps properly applied now its time for the big thing known as main thread. JVM starts the main thread and allows it to do the following tasks : -
- Main thread checks whether the specified class files are available or not , if it is not available, throws an error but if is available then it verifies the class file format using the byte code verify.
- Now there must be the two probabilities , first class path format is valid ,second class path format is invalid. if it is invalid then jvm again throws an error.
- If class path format is valid then, class must be loaded and initialized using class loader and standard main method which is “public static void main(String [] args)” will be verified and loaded in class file.
- Now here comes the main method who performs the whole execution of your code’s logic. It collects the command line args and creates string of array object which stores all the command line arguments into the string array.
- Invokes the main method with the class name by passing the string array as parameter and executes the whole code written in the method. After the whole execution main method will be destroyed.