JVM or Java Virtual Machine is a program that takes the Java byte code that is with a file.Class and converts the byte code into machine understandable language. Here byte codes indicate, a highly optimized set of instructions designed to be executed by the Java runtime system.
JVM is also a significant part of JRE that is Java Runtime Environment. The other two parts of JRE are core classes and supporting files. We also know the applications of JAVA as WORA, which means the same Java code can run on different systems. Note that WORA means Write Once Run Anywhere. This property of Java is possible because of the JVM.
During the compilation of the .java file, the .class file goes into various steps. The JVM performs the following crucial tasks to run Java applications:
- Code Loading
- Code Verification
- Code Execution
Also Read: Difference between JDK, JRE and JVM
How Many Types of Memory Areas are Allocated by JVM?
To complete the above tasks and process, JVM assigns a particular type of memory structure to a specific duty. The five types of memory it allocates are:
1. The Method or Class Area: This type stores details, that has class level like static variables, class name, methods, constant pool, etc. When JVM starts, it creates the method area. The method or class area size can be constant, or it can also vary. If its memory is not sufficient, JVM throws OutOfMemoryError.
2. The Heap Area: It usually stores the objects instantiated by the application. These objects that are present in the heap can be split between threads. Usually, programmers restrict their size to avoid garbage collection pauses.
3. Stack Area: JVM create one run-time stack for every thread. That is present in the stack area. The stack area is used to store either the data or partial results of the returning value from the methods. Once the thread stops, the run-time stack will get destroyed.
4. Program Counter Register or PCR: Each thread has a separate Program Counter Register or PCR. This type is basically used to store addresses of current execution instruction of a particular thread.
5. The Native Method Stacks: Similar to PCR, separate native method stacks are created for every thread. Its purpose is to store the native method information.