Java Options
suggest changeThe java command supports a wide range of options:
- All options start with a single hyphen or minus-sign (
\-): the GNU/Linux convention of using--for “long” options is not supported. - Options must appear before the
<classname>or the-jar <jarfile>argument to be recognized. Any arguments after them are passed to the Java application that is being run. - Options that do not start with
-Xor-XXare standard options. You can rely on all Java implementations1 to support any standard option. - Options that start with
-Xare non-standard options, and may be withdrawn from one Java version to the next. - Options that start with
-XXare advanced options, and may also be withdrawn.
Setting system properties with -D
The -D<property>=<value> option is used to set a property in the system Properties object. This parameter can be repeated to set different properties.
Memory, Stack and Garbage Collector options
The main options for controlling the heap and stack sizes are documented in Setting the Heap PermGen and Stack sizes. (Editorial note: Garbage Collector options should be described in the same topic.)
Enabling and disabling assertions
The -ea and -da options respectively enable and disable Java assert checking:
- All assertion checking is disabled by default.
- The
-eaoption enables assertion checking in non-system classes. It does not enable it in system classes. - The
-ea:<packagename>...form enables checking in a package and all subpackages. The...belongs to the package form. - The
-ea:<classname>form enables checking in one class. Do not add...after the class name. - The
-daoption disables assertion checking in non-system classes. - The
-da:<packagename>...form disables checking in a package and all subpackages. - The
-da:<classname>form disables checking in one class. - The
-esaoption enables checking for all system classes. - The
-dsaoption disables checking for all system classes.
The options can be combined. For example:
$ # Enable all assertion checking in non-system classes
$ java -ea -dsa MyApp
$ # Enable assertions for all classes in a package except for one.
$ java -ea:com.wombat.fruitbat... -da:com.wombat.fruitbat.Brickbat MyApp
Note that enabling assertion checking is liable to alter the behavior of a Java program.
- It is liable to make the application slower in general.
- It can cause specific methods to take longer to run, which could change timing of threads in a multi-threaded application.
- It can introduce serendipitous happens-before relations which can cause memory anomalies to disappear.
- An incorrectly implemented
assertstatement could have unwanted side-effects.
Selecting the VM type
The -client and -server options select between two HotSpot VMs when both are present:
- The “client” form is tuned for user applications and offers faster startup.
- The “server” form is tuned for long-running applications. It spends longer collecting statistics during JVM “warm up”, which lets the JIT compiler do a better job of optimizing the native code.
A 64-bit JDK includes only the server VM, and -client is ignored. The data model matches the installed JDK. -d32 and -d64 select a mode only when that VM is installed.
1 - Check the official manual for the java command. Sometimes a standard option is described as “subject to change”.