_JAVA_OPTIONS Environment Variable in Java
- Types of Java Options
-
_JAVA_OPTIONS
Environment Variable in Java -
JAVA_TOOL_OPTIONS
Environment Variable in Java -
Difference Between
JAVA_TOOL_OPTIONS
andJDK_JAVA_OPTIONS
in Java - Conclusion

The _JAVA_OPTIONS
is an environment variable that you can use to pass the Java options to a JVM process. The passed Java options are treated similarly to the command line arguments by the Java Virtual Machine.
In this article, we will understand different types of Java options. We will also see the _JAVA_OPTIONS
and the JAVA_TOOL_OPTIONS
, the difference between the JDK_JAVA_OPTIONS
and JAVA_TOOL_OPTIONS
environment variables.
Types of Java Options
Java defines three different types of options. Java differentiates between options based on their support in different Java versions and their usage.
Let us understand each of these options’ categories.
- Standard Options - Java guarantees that all Java versions support standard options. Java enables the use of these options for common actions such as:
- Setting the
classpath
variable. - Checking the version of Java Runtime Environment (JRE).
- Toggling the verbose output, etc.
- Setting the
- Extra Options - Java does not guarantee the support of these types of options in all versions. These options are specifically related to JavaHotSpot Virtual Machine and can change.
Java uses these options to set specific variables. - Advanced Options - Java provides advanced options for developers. Developers can use these options to tune JVM, JRE, JIT, and Garbage Collector.
There are four different types of advanced options. These are given as follows.
- Runtime Options - Developers can use these options to tune the run time of JVM.
- JIT Compiler Options - Developers can use these options to control the Just In Time (JIT) Java compiler.
- Serviceability Options - Java defines these options for debugging and gathering system information.
- Garbage Collection Options - Developers can control the garbage collection mechanism of Java using these options.
_JAVA_OPTIONS
Environment Variable in Java
Java defines several environment variables to pass the Java options to the JVM during the execution of a process. The _JAVA_OPTIONS
is one such environment variable.
Java treats the arguments you pass using this environment variable similar to the command line arguments.
In fact, as per the documentation of Java by Oracle, Java provides these options so that command-line arguments can be passed to programs in those execution environments where a direct command line is not available.
You can pass multiple arguments where each argument is separated by white space. If your argument contains white space, you should enclose it within quotes.
You should be careful while using the _JAVA_OPTIONS
because the program’s execution will fail if the arguments are invalid.
Let us see an example of passing the variable’s option to enable the log tracing.
export _JAVA_OPTIONS='-Dsun.java2d.trace=log'
JAVA_TOOL_OPTIONS
Environment Variable in Java
The JAVA_TOOL_OPTIONS
is the successor of the _JAVA_OPTIONS
. The _JAVA_OPTIONS
environment variable is not standardized in the JVM specification. Therefore, different vendors have their names for this variable.
However, the JAVA_TOOL_OPTIONS
variable is standardized in the JVM specification. You should always prefer it over the _JAVA_OPTIONS
.
This is because it handles the white space issues and quotations better.
Difference Between JAVA_TOOL_OPTIONS
and JDK_JAVA_OPTIONS
in Java
The JAVA_TOOL_OPTIONS
and the JDK_JAVA_OPTIONS
are very similar as Java enables using both of the environment variables to pass the Java options to JVM.
As we have already seen, all the rules and methods of passing arguments using JAVA_TOOL_OPTIONS
apply to JDK_JAVA_OPTIONS
as well.
However, the main difference between these variables is as given below.
-
Java launcher reads the arguments passed using
JDK_JAVA_OPTIONS
. Therefore, we can not pass options that cause the launcher to exit and specify JAR or the main class.Therefore, we can use this variable to pass options used during the run time at the launcher level.
-
The Java compiler and JAR also read the
JAVA_TOOL_OPTIONS
. Therefore, we can use this variable to set options to tune the execution.For example, we can set flags using this variable.
Conclusion
This article has discussed Java’s JAVA_TOOL_OPTIONS
, JDK_JAVA_OPTIONS
, and _JAVA_OPTIONS
environment variables. We have also discussed the differences between the use of these environment variables.