A JVM or Java Virtual Machine is a software implementation of a physical machine, or we can say it is an abstract machine. Java was designed with the concept of WORA (Write Once Run Anywhere), which runs on a VM. It is a specification that gives a runtime environment during which java bytecode is often executed. The compiler compiles the Java file into a Java .class file, then that .class file is input into the JVM, which loads and executes the class file.
JVM is constructed with three basic subunits
- ClassLoader Subsystem
- Runtime Data Area
- Execution Engine
Now let’s discuss the most frequently used JVM Parameters which are 3 namely as follows:
- Java Heap Size
- Garbage Collector
- Print GC
Parameter 1: Java Heap Size
The following three JVM options specify initial and max heap size and thread stack size while running Java programs:
-Xms - set initial Java heap size -Xmx - set maximum Java heap size -Xss - set java thread stack size
Parameter 2: Garbage Collector
Garbage Collection algorithms are used to attain better stability of the application. Garbage Collection tracks each and each object available within the JVM heap space and removes unused ones.
Java provides us with 4 ways to implement garbage collection namely below:
Test example garbage collection Test example garbage collection
Parameter 3: Print GC
These JVM options enable rubbish collection logging, which is very effective for the latency-sensitive operation.
Using the following parameters, we can log the GC activity:
-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=< number of log files > -XX:GCLogFileSize=< file size >[ unit ] -Xloggc:/path/to/gc.log
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.