Java Language Java Options


Example

The 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 will be treated as arguments to be passed to Java app that is being run.

  • Options that do not start with -X or -XX are standard options. You can rely on all Java implementations1 to support any standard option.

  • Options that start with -X are non-standard options, and may be withdrawn from one Java version to the next.

  • Options that start with -XX are 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 -ea option enables checking of all assertions
  • The -ea:<packagename>... enables checking of assertions in a package and all subpackages.
  • The -ea:<classname>... enables checking of assertions in a class.
  • The -da option disables checking of all assertions
  • The -da:<packagename>... disables checking of assertions in a package and all subpackages.
  • The -da:<classname>... disables checking of assertions in a class.
  • The -esa option enables checking for all system classes.
  • The -dsa option 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 to assertion checking is liable to alter the behavior of a Java programming.

  • It is liable 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 assert statement could have unwanted side-effects.

Selecting the VM type

The -client and -server options allow you to select between two different forms of the HotSpot VM:

  • The "client" form is tuned for user applications and offers faster startup.
  • The "server" form is tuned for long running applications. It takes longer capturing statistic during JVM "warm up" which allows the JIT compiler to do a better of job of optimizing the native code.

By default, the JVM will run in 64bit mode if possible, depending on the capabilities of the platform. The -d32 and -d64 options allow you to select the mode explicitly.


1 - Check the official manual for the java command. Sometimes a standard option is described as "subject to change".