The Java Virtual Machine (JVM) runs your Java programs. Sometimes the default configuration that the JVM comes with may not be as efficient as possible for your program.

In such a case, you need to tune your JVM to improve its performance. You can adjust the default parameters until you achieve the desired performance for your application.

There are three types of command-line options that you can use when tuning your JVM.

Standard Options

Standard options come with every JVM compiler. You can use them to perform actions such as setting the classpath or checking your JRE version. These options start with the dash (-) prefix and end with the option name.

For example, to check your JRE version, enter this command line instruction:

        java -version 
    

Non-Standard Options

Non-standard options are specific to your JVM implementation. The most common implementation is the Hotspot JVM, which you probably have installed on your computer.

Non-standard options start with -X. Unlike the standard options, there's a lot more that you can do with the non-standard options.

These options allow you to set parameters to increase your heap memory, nursery size, or type of garbage collector. This is where most performance tuning happens.

For example, to set the minimum heap memory of your application to 1GB and the maximum to 3GB, use the command below:

        java -Xms1g -Xmx3g JavaClass
    

Advanced Options

You can use advanced options to control actions at the system level. In general, you should not use these options unless you have an in-depth understanding of your system.

It's also worth noting these options can change at any time without prior notice. You can keep track of changes made to the HotSpot JVM via Oracle’s documentation.

Advanced options begin with -XX. Just like the non-standard options, they aren't guaranteed to be available on every JVM implementation. The syntax for these options is similar to that of the non-standard options.

For example, to set a maximum metaspace size of 85004KB, use this instruction:

        java -XX:MaxMetaspaceSize=85004k JavaClass
    

Many Options to Tweak the JVM

You can tune your JVM using several types of options. But there are many options available to control various low-level settings.

You can check the available options by running java -X or you can check the Oracle documentation for further details.