Search code examples
javajvmjvm-crash

what are the functions of JVM, What JVM does when we run “java A” , A is class


Interview question : What JVM does when we run “java A” , A is java class.

I explained like : JVM creates memory, try to find out the A java class using Java reflection API.

JVM loads the java.lang packages.

Any one please explain what are end to end functionalities of JVM!


Solution

  • JVM is too complex to describe here. There is an excellent resource written by one of it's creator in order to you can master JVM. The Java Virtual Machine

    In your case, When you type "java A", a new JVM is started and the "bootstrap class loader" is responsible for loading key Java classes like java.lang.Object and other runtime code into memory first. The runtime classes are packaged inside of the JRE/lib/rt.jar file. In a JVM, each and every class is loaded by some instance of a java.lang.ClassLoader. The ClassLoader class is located in the java.lang package and we are free to subclass it to add their own functionality to class loading.

    Learn more about class loaders from here: The basics of Java class loaders