站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JDK 5 Documentation v1.1.8, Java 2 SDK 英文文档

java - The Java Application Launcher - JDK 5 Documentation v1.1.8, Java 2 SDK 英文文档

java - The Java Application Launcher

java launches a Java application.

SYNOPSIS

java [ options ] classname <args>
java_g [ options ] classname <args>

DESCRIPTION

The java program launches a Java application. It does this by starting a Java runtime environment, loading a specified class, and invoking that class's main method. The java program executes Java .class files created by a Java compiler, for instance, javac.

The classname argument is the name of the class to be executed. classname must be fully qualified by including its package in the name, for example:

   % java java.lang.String
Note that any arguments that appear after classname on the command line are passed to the main method of the class.

java expects the binary representation of the class to be in a file named after the class. Thus, class String would be in String.class which is generated by compiling the corresponding String.java source file with javac. All Java class files end with the filename extension .class which the compiler automatically adds when the class is compiled. The class must contain a main method defined as follows:

   class Aclass {
       public static void main(String argv[]){ 
           . . .
       }
   }
java executes the main method and then exits unless main creates one or more threads. If any threads are created by main then java doesn't exit until the last thread exits.

When you define your own classes you need to specify their location. Use CLASSPATH to do this. CLASSPATH consists of a colon separated list of directories that specifies the path. For example:

   .:/home/xyz/classes
Note that the system always appends the location of the system classes onto the end of the class path unless you use the -classpath option to specify a path.

Ordinarily, you compile source files with javac then run the program using java. However, java can be used to compile and run programs when the -cs option is used. As each class file is loaded its modification date is compared to the modification date of the class source file. If the source has been modified more recently, it is recompiled and the new class file is loaded. java repeats this procedure until all the classes are correctly compiled and loaded.

The interpreter can determine whether a class is legitimate through the mechanism of verification. Verification ensures prior to their execution that class files do not violate any language constraints.

java_g is a non-optimized version of java suitable for use with debuggers like jdb. When using java_g to run a program that loads a shared library, you must supply a debug version of the library. You can create a debug version of a library by simply appending "_g" to the file's name. For example, if the library was libhello.so, you would need to change the name to libhello_g.so.

OPTIONS

-debug
Allows the Java debugger, jdb, to attach itself to this java session. When -debug is specified on the command line java displays a password which must be used when starting the debugging session.
-cs,   -checksource
When a compiled class is loaded, this option causes the modification time of the class bytecode file to be compared to that of the class source file. If the source has been modified more recently, it is recompiled and the new class file is loaded.

-classpath   path
Specifies the path java uses to look up classes. Overrides the default or the CLASSPATH environment variable if it is set. Directories are separated by colons. Thus the general format for path is:
   .:<your_path>
For example:
   .:/home/xyz/classes:/usr/local/java/classes

-mxx
Sets the maximum size of the memory allocation pool (the garbage collected heap) to x. The default is 16 megabytes of memory. x must be greater than or equal to 1000 bytes. The maximum memory size must be greater than or equal to the startup memory size (specified with the -ms option, default 16 megabytes).

By default, x is measured in bytes. You can specify x in either kilobytes or megabytes by appending the letter "k" for kilobytes or the letter "m" for megabytes.

-msx
Sets the startup size of the memory allocation pool (the garbage collected heap) to x. The default is 1 megabyte of memory. x must be > 1000 bytes. The startup memory size must be less than or equal to the maximum memory size (specified with the -mx option, default 16 megabytes).

By default, x is measured in bytes. You can specify x in either kilobytes or megabytes by appending the letter "k" for kilobytes or the letter "m" for megabytes.

-noasyncgc
Turns off asynchronous garbage collection. When activated no garbage collection takes place unless it is explicitly called or the program runs out of memory. Normally garbage collection runs as an asynchronous thread in parallel with other threads.

-noclassgc
Turns off garbage collection of Java classes. By default, the Java interpreter reclaims space for unused Java classes during garbage collection.

-prof
Starts the Java Runtime with Java profiling enabled. By default, this puts profile results in the file ./java.prof. This option works only with java_g.

-prof:file
Starts the Java Runtime with Java profiling enabled. This form of the flag allows the user to specify a different output file for the profile information. For example, the flag -prof:myprog.prof enables profiling and puts the profile results in the file myprog.prof rather than in the default file ./java.prof. This option works only with java_g.

-version
Print the build version information.

-help
Print a usage message.

-ssx
Each Java thread has two stacks: one for Java code and one for C code. The -ss option sets the maximum stack size that can be used by C code in a thread to x. Every thread that is spawned during the execution of the program passed to java has x as its C stack size. The default units for x are bytes. The value of x must be greater than or equal to 1000 bytes.

You can modify the meaning of x by appending either the letter "k" for kilobytes or the letter "m" for megabytes. The default stack size is 128 kilobytes ("-ss128k").

-ossx
Each Java thread has two stacks: one for Java code and one for C code. The -oss option sets the maximum stack size that can be used by Java code in a thread to x. Every thread that is spawned during the execution of the program passed to java has x as its Java stack size. The default units for x are bytes. The value of x must be greater than or equal to 1000 bytes.

You can modify the meaning of x by appending either the letter "k" for kilobytes or the letter "m" for megabytes. The default stack size is 400 kilobytes ("-oss400k").

-t
Prints a trace of the instructions executed (java_g only).

-v,   -verbose
Causes java to print a message to stdout each time a class file is loaded.

-verify
Performs byte-code verification on the class file. Beware however, that java -verify does not perform a full verification in all situations. Any code path that is not actually executed by the interpreter is not verified. Therefore, java -verify cannot be relied upon to certify class files unless all code paths in the class file are actually run.

-verifyremote
Runs the verifier on all code that is loaded into the system via a classloader. verifyremote is the default for the interpreter.

-noverify
Turns verification off.

-verbosegc
Causes the garbage collector to print out messages whenever it frees memory.

-DpropertyName=newValue
Redefines a property value. propertyName is the name of the property whose value you want to change and newValue is the value to change it to. For example, this command line
   % java -Dawt.button.color=green ...
sets the value of the property awt.button.color to "green". java accepts any number of -D options on the command line.

Options for Control of Heap Expansion and Shrinkage

The following options, introduced in version 1.1.8 of the Java Development Kit, allow for user control of garbage-collected heap expansion and shrinkage. The default settings of the heap expansion and shrinkage parameters are appropriate for the majority of applications, so these options are not needed in most computing situations. You should not use them unless you understand the effect they will have on your application. Randomly setting these options is as likely to decrease the performance of your system as improve it. The effect of these options will be greatest if a JIT compiler is not being used. See also the heap shrinkage limitations below.
-maxesize
Sets the maximum size of each expansion of the heap when more memory is required. By default, size is measured in bytes. To specify size in either kilobytes or megabytes, append "k" for kilobytes or "m" for megabytes. The default value for the setting of maxe is 2 megabyte of memory. Example:
java -maxe2097152 MyClass

-minesize
Sets the minimum size of each expansion of the heap. Also sets the minimum size of free object space in the heap. The heap will be returned to the OS only when the amount of free object space in the heap space is more than the setting of mine. By default, size is measured in bytes. To specify size in either kilobytes or megabytes, append "k" for kilobytes or "m" for megabytes. The default value for mine is 1 megabyte of memory. Example:
java -mine1048576 MyClass

-maxffloat
Sets the approximate percentage of maximum free heap. If the percentage of free object space in the heap is more than the setting of maxf and the amount of free object space in the heap is more than the setting of mine, and free object space is located at the top of the heap, the garbage collector will attempt to shrink the heap by returning a portion of free object space back to the OS. The heap size will not shrink below its initial size. The default value for maxf is 1.00; by default no heap is returned back to the OS. Example:
java -maxf0.60 MyClass

-minffloat
Sets the approximate percentage of minimum free space in the heap to give control over the rate of preallocation performed when heap space is expanded. After expansion, approximately minf percent of the heap should be free. The actual amount of free space in the space after expansion is dependent on the value of minf and fragmentation of free spaces within the heap. The default value for minf is 0.25. Example:
java -minf0.35 MyClass

Heap Shrinkage Limitations: The amount heap shrinkage relies on using heap compaction to free up space at the end of the heap which is then de-committed to return it to the OS. The Java garbage collector is implemented using a compacting, mark-sweep collector with some conservative scanning. A gc is conservative if it does not collect memory that looks as if it might be in use on the stack or in registers.

The mark-sweep and conservative scanning phase of the garbage collector marks objects as being free, used and un-movable (pinned), or used and movable. After the objects have been marked, free space is garbage collected. The compacting phase of the garbage collector attempts to coalesce the movable objects to the low end of object space to reduce heap fragmentation.

If an object is un-movable (pinned), it cannot be moved during the compaction phase. If one of the pinned objects is near the top of the heap, and much of the free space is below it, the free space below the pinned object cannot be returned to the OS. If either the JIT compiler is enabled, or the Java Native Interface (JNI) API or native method interface is used to make C calls, the conservative scan phase of the garbage collector may see a value in memory created by the C code that looks like a pointer to an object and mark the object in the heap as "pinned" because it appears to be pointed to directly by native code.

ENVIRONMENT VARIABLES

CLASSPATH
Used to provide the system a path to user-defined classes. Directories are separated by colons, for example,
   .:/home/xyz/classes:/usr/local/java/classes

SEE ALSO

javac, jdb, javah, javap, javadoc, CLASSPATH