JVM Architecture is the big process through which java code is run. From start to end, *.java to *.class all the analysis, interpretation, optimization, execution, etc. All these activities come under JVM architecture.
We have three parts which we already know JDK, JRE, JVM. But we discussed JDK and JRE again, then go for JVM in-depth knowledge.
JRE (JAVA RUNTIME ENVIRONMENT):
JRE is required to run java application either on the server or on the local machine (Dev environment). JRE bundles libraries and JVM (Java Virtual Machine). JRE uses java bytecode (*.class) files to run java application but it is not used to develop java applications.
JDK (JAVA DEVELOPMENT KIT):
We need JDK to develop java applications. JDK provides all the tools and APIs like java, javac, javap, Java Visual VM, Security, RMI, etc. to set up a development environment. JDK is a superset of JRE who provide libraries to run java application. So, on installing JDK, we also install JRE and JVM both. We don’t need to install them separately. JDK not just developing java applications, also for debugging and monitoring java applications.
JVM (JAVA VIRTUAL MACHINE):
Virtual Machine is a software (another machine) installed on a physical machine (operating system). It is another machine to run java application using their different components like class loader subsystem, memory area, and execution engine. JVM is platform-dependent, according to the operating system we have different versions of the virtual machines.
JVM is another machine that behaves like another system to execute/run java applications. We have VMWare, Virtual-box, etc for installing another operating system that is virtual and exists on the requirement. Basically we create a logical software simulation.
We categorize the virtual machines, one is application based and the second one is a hardware-based virtual machine. JVM is an application-based virtual machine.
JVM has three components:
- ClassLoader Subsystem;
- Memory Area;
- Execution Engine.
Note: Java class files executes on above given order.
ClassLoader Subsystem:
The classloader subsystem has three major activities: Loading, Linking, and Initialization. Java loads the class file in JVM using the class loader subsystem.
Loading: Read all class files(Binary information) from the application as well as java provided classes and loaded into the JVM method memory area. Information stored is:
- Fully Qualified Name of class;
- Fully Qualified Name of Immediate Parent class;
- Method Information;
- Variable information;
- Constructor Information;
- Modifier Information;
- Constant pool information, etc.
A lot of information other than the above points is store in the method memory area. All the above information is class-specific. JVM immediately creates an object of Class class type in the heap memory area of JVM. Class class is java.lang.Class type, not object type. Both are different from each other.
Classloader subsystem (Loading) has three types:
- Bootstrap class loader
- Extension class loader
- Application class loader
Bootstrap class loader:
This class loader is responsible to load all Core Java API classes. These classes are present in rt.jar. The location of this jar is also considered as a bootstrap class-path (JDK/JRE/lib/rt.jar). It is default available with every JVM. It is implemented in native languages like C/C++ and not implemented in java.
Extension class loader:
It is a child class of Bootstrap class loader. It is responsible to load classes from the Extension classpath (JDK/JRE/lib/ext/*.jar). It is implemented in java only and the corresponding .class file is sun.misc.Launcher$ExtClassLoader.class.
Application class loader:
It is the child class of Extension class Loader. This class Loader is responsible to load classes from applications classPath. It internally uses environment classPath. It is implemented in java and the corresponding .class file name is sun.misc.Launcher$AppClassLoader.class