Java Command parameter description

Source: Internet
Author: User
Tags bootstrap classes class definition

When Java runs a compiled class, it is loaded and executed by a Java virtual machine, and the Java Virtual machine is started by the operating system command Java_home "Bin" java–option,-option is the virtual machine parameter, Java_home is the JDK installation path, These parameters can be used to adjust the running state of the virtual machine, and to grasp the meaning of the parameters can have a deeper understanding of the operation mode of the virtual machine.
First, view the parameter list:

Virtual machine parameters are divided into basic and extended two categories, the command line input java_home "bin" Java to get the basic parameter list,

A list of extended parameters can be obtained by entering Java_home "bin" at the command line java–x.
Second, the basic parameter description:

1.-client,-server

These two parameters are used to set what mode of operation the virtual machine uses, and client mode is faster to start, but run-time performance and memory management are less efficient than server mode and are typically used for client applications. In contrast, the server mode starts slower than the client, but it can achieve higher operational performance.

On Windows, the default virtual machine type is client mode, and if you want to use server mode, you need to add the-server parameter to get higher performance on server-side applications, especially for multiple CPUs, when you start the virtual machines. Server mode is used by default on Linux,solaris.

2.-hotspot

The meaning is the same as the client, jdk1.4 previously used parameters, jdk1.4 began to no longer use, replaced by the client.

3.-CLASSPATH,-CP

When a virtual machine runs a class, it needs to be loaded into memory, and the virtual machine searches for the class in the following way and order:

Bootstrap classes,extension classes,user classes.

The path in Bootstrap is the jar or zip file that the virtual machine comes with, the virtual machine searches for these package files first, and the System.getproperty ("Sun.boot.class.path") to obtain the package name of the virtual machine search.

Extension is a jar file located in the "Lib" ext directory of the JRE, and the virtual machine searches for the jar file under this directory after searching for bootstrap. With System. GetProperty ("Java.ext.dirs") can get the virtual machine to use the extension search path.

The User classes Search order is the current directory, environment variable CLASSPATH,-classpath.

4.-classpath

Tells the virtual machine to search directory names, jar document names, zip document names, separated by semicolons;

For example, when you develop a public class yourself and wrap it in a Common.jar package, you need to use-classpath Common.jar when using classes in Common.jar. Tells the virtual machine to look for the class from Common.jar, or the virtual machine throws a Java.lang.NoClassDefFoundError exception indicating that the class definition was not found.

System.getproperty ("Java.class.path") is available at run time to obtain the path to the virtual machine lookup class.

After using-classpath, the virtual machine will no longer use the class search path in Classpath, and if neither-classpath nor Classpath are set, the virtual machine uses the current path (.). As a class search path.

It is recommended to use-classpath to define the classpath of a virtual confidential search, instead of using the search path of the environment variable CLASSPATH to reduce the potential conflicts that exist when multiple projects are using classpath at the same time. For example, apply 1 to use Class G in A1.0.jar, apply 2 to use Class G in A2.0.jar, A2.0.jar is the A1.0.jar upgrade package, when the A1.0.jar,a2.0.jar in Classpath, the virtual machine search to the first packet of Class G when the search stopped, if the application 1 app 2 of virtual machines are searched from the classpath, there will be an application does not get the correct version of the class G.

5.-d<propertyname>=value

Set the property name/value pair in the system properties of the virtual machine, and the application running on top of this virtual machine can get the value of System.getproperty ("PropertyName").

If there are spaces in value, you need to enclose the value in double quotation marks, such as-dname= "space string".

This parameter is typically used to set system-level global variable values, such as configuration file paths, which should be accessible anywhere in the program.

6.-verbose[:class|gc|jni]

Displays the virtual machine run information on the output device.

Verbose and verbose:class mean the same, output the information of the class that the virtual machine loads, and the information format is as follows:

[Loaded java.io.filepermission$1 from shared objects file]

This parameter can be used to diagnose when the virtual machine reports that the class cannot find or class conflicts when the virtual machine is loaded from the class.

7.-VERBOSE:GC

Displays information in the output device when a memory collection occurs on the virtual machine, in the following format:

[Full GC 268k->168k (1984K), 0.0187390 secs]

This parameter is used to monitor the virtual machine memory recycling situation.

8.-verbose:jni

The output device displays information when the virtual machine calls the native method, in the following format:

[dynamic-linking Native Method Hellonative.sum ... JNI]

This parameter is used to monitor how the virtual machine calls the local method, which facilitates diagnostics in the event of a JNI error.

9.-version

Displays the virtual machine version information that can be run and then exits. When a different version of the JDK is installed on a single machine

10.-showversion

Displays version information and help information.

11.-ea[:<packagename>...|:<classname>]

12.-enableassertions[:<packagename>...|:<classname>]

Starting with JDK1.4, Java can support the assertion mechanism for diagnosing run-time problems. The assertion is usually valid during the test phase and does not need to be run when the assertion is formally run. The value of the asserted expression is a logical value, true when the assertion does not run, false when the assertion runs, and a java.lang.AssertionError error is thrown.

The above parameters are used to set whether the virtual machine initiates the assertion mechanism, by default the virtual authority closes the assertion mechanism, with-EA to open the assertion mechanism, run all the assertions in the package and class without <packagename> and classname, and if you want to run only assertions in certain packages or classes, The package name or class name can be added after-ea. For example, to start an assertion in package com.foo.util, use the command –ea:com.foo.util.

13.-da[:<packagename>...|:<classname>]

14.-disableassertions[:<packagename>...|:<classname>]

Used to set the virtual machine closed assertion processing, packagename and classname use the same method and-ea.

15.-esa | -enablesystemassertions

Sets the assertion for the virtual machine display system class.

16.-DSA | -disablesystemassertions

Sets the assertion of the virtual institution's closed system class.

17.-agentlib:<libname>[=<options>]

This parameter is a newly introduced JDK5 for the virtual machine to mount the local agent library.

Libname is the local agent library file name, the search path for the virtual machine is the path in the environment variable path, and options is passed to the local library when the parameter is started, and multiple parameters are separated by commas. On the Windows platform, the virtual machine searches for files with local libraries named Libname.dll, the virtual machine on UNIX searches for files with local libraries named libname.so, the search Path environment variables differ on different systems, and the Linux, SunOS, Irix are ld_ Library_path,aix on the Libpath,hp-ux for the Shlib_path.

For example, you can use-agentlib:hprof to get the running of a virtual machine, including the running data of CPU, memory, thread, etc., and output to the specified file, and use-agentlib:hprof=help to get the Help list. The Hprof.dll file can be found in the JRE bin directory.

-agentpath:<pathname>[=<options>]

Set the virtual machine to load the local library by full path, no longer searching for paths in path. Other features are the same as agentlib.

19.-javaagent:<jarpath>[=<options>]

The virtual machine starts to fashion into the Java language device proxy. The Mainfest file in the Jarpath file must have the Agent-class attribute. The proxy class wants to implement public static void Premain (String Agentargs, Instrumentation Inst) methods. When the virtual machine is initialized, the Premain method is called in the order in which the proxy class is described.

Java Command parameter description

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.