1 JAVA The JAVA command invokes an interpreter that executes Java bytecodes. It executes Java class files created by a Java compiler, such as JAVAC. This reference page describes the JAVA command only. If the JDK documentation was installed on your OpenVMS system, you can view documentation on the JDK tools (commands) and other Java reference material by pointing your browser to the following location: SYS$COMMON:[SYSHLP.JAVA]INDEX.HTML Format JAVA "classname" args 2 Parameters "classname" The name of the class to be executed, enclosed in quotation marks. The classname parameter must be fully qualified by including its package in the name, for example: $ JAVA "java.lang.String" In this example, JAVA interprets the directory path to be [JAVA.LANG], and the file name of the class to be STRING.CLASS. args Arguments that are passed to the main method of the class. 2 Description Java expects the binary representation of the class to be in a file called file-name.CLASS, which is generated by compiling the corresponding source file with the JAVAC compiler. All Java class files end with the file name extension .CLASS, which the compiler automatically adds when the class is compiled. The class to be executed must contain a main method defined as follows: class Aclass { public static void main(String argv[]){ . . . } } The Java interpreter executes the main method and then exits, unless main creates one or more threads. If any threads are created by main, then the JAVA command does not exit until the last thread exits. When you define your own classes, you need to specify their location. Use the logicals CLASSPATH (for a UNIX style directory path) or JAVA$CLASSPATH (for an OpenVMS style directory path) to do this. The CLASSPATH logical consists of a colon-separated list of directories that specifies the path. For example: .:/home/xyz/classes:/usr/local/java/classes Also, unlike on UNIX systems, you must also explicitly specify the system classes on CLASSPATH. For example: $ define/nolog CLASSPATH "/sys$common/java/lib/JDK116_CLASSES.ZIP:." The JAVA$CLASSPATH logical lets you define a classpath using OpenVMS filespecs. The following two sample statements accomplish the same result: $ DEF JAVA$CLASSPATH USER1$:[SMITH.KIT]JDK115_CLASSES.ZIP,[] $ DEF CLASSPATH "/user1$/smith/kit/jdk115_class.zip:." Note that: o JAVA$CLASSPATH is a comma-separated list not enclosed in quotation marks. o JAVA$CLASSPATH overrides CLASSPATH if CLASSPATH is defined. NOTE All Java files that are to be read by any of the Java tools or that serve as input class libraries (listed in CLASSPATH) must be in Stream_LF format. To determine the record format of your file, do the following: $ DIR/FULL MyFile.java And observe the line: Record format By default, a file initially created on an OpenVMS system, with a text editor for example, will have variable-length record format. Although, for example, a *.JAVA file with variable-length record format compiles correctly if it is error-free, the compiler does not produce proper diagnostic outputs if a compilation error occurs. To get a file into Stream_LF record format, do the following: $ CONVERT/FDL=SYS$INPUT input_file-name output_file-name FILE ALLOCATION 4 BEST_TRY_CONTIGUOUS yes EXTENSION 0 ORGANIZATION sequential RECORD BLOCK_SPAN yes CARRIAGE_CONTROL carriage_return FORMAT stream_LF SIZE 0 If you use a non-Stream_LF formatted file in a CLASSPATH, errors like this result: Unable to initialize threads: cannot find class java/lang/Thread 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 /CHECKSOURCE qualifier 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 was 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 that prior to their execution, class files do not violate any language constraints. You can specify the qualifiers for this command as one of the following: o OpenVMS DCL style qualifiers o Tru64 UNIX style switches To use the DCL style: $ DEFINE JAVA$USE_DCL 1 $ @SYS$MANAGER:JAVA$SETUP To use the Tru64 UNIX style: $ DEASSIGN JAVA$USE_DCL $ @SYS$MANAGER:JAVA$SETUP Both styles are documented. 2 Qualifiers /CHECKSOURCE /CHECKSOURCE -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 was modified more recently, it is recompiled and the new class file is loaded. /CLASSPATH /CLASSPATH=path -classpath path Specifies the path that the JAVA command uses to look up classes. Overrides the default or the CLASSPATH environment variable if it is set. Directories are separated by colons. Whether you use /CLASSPATH or -classpath, the general format for path is: .:{your_path} For example: .:/home/xyz/classes:/usr/local/java/classes /JIT /JIT /NOJIT -jit -nojit The Just-in-Time compiler (JIT) runs by default when you enter the Java command. To run the Java command with the interpreter instead of the JIT, use: $ JAVA /NOJIT ... The Java debugger runs the interpreter by default. To run the Java debugger with the JIT compiler, the /JIT qualifier must be explicitly specified. The JIT runs by default when you run appletviewer. To run appletviewer with the interpreter, use: $ APPLETVIEWER /PARAMETERS="-nojit" /MAXHEAP /MAXHEAP=x -mx x Sets the maximum size of the memory allocation pool (the garbage collected heap) to x. The default is 6 megabytes of memory. The value of x must be greater than or equal to 1000 bytes. 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. /INITHEAP /INITHEAP=x -ms x Sets the startup size of the memory allocation pool (the garbage collected heap) to x. The default is 6 megabytes of memory. The value of x must be greater than or equal to 1000 bytes. 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 /NOASYNCGC -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 /NOCLASSGC -noclassgc Turns off garbage collection of Java classes. By default, the Java interpreter reclaims space for unused Java classes during garbage collection. /PROFILE /PROFILE[=file-name] -prof[: file-name] This option works only with JAVA_G. It starts the Java Runtime with Java profiling enabled. If no file name is specified, the profile results are placed in the file []JAVA.PROF. Otherwise, the profile results are placed in the specified file. /LOGLEVEL /LOGLEVEL -l Sets the logging level (JAVA_G only). /VERSION /VERSION -version Prints the build version information. /HELP /HELP -help Prints a usage message. /MAXCSTACK /MAXCSTACK=x -ss x Each Java thread has two stacks: one for Java code and one for C code. The /MAXCSTACK option sets the maximum stack size that can be used by C code in a thread to x. Every thread 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 (/MAXCSTACK=128k). /MAXJSTACK /MAXJSTACK=x -oss x Each Java thread has two stacks: one for Java code and one for C code. The /MAXJSTACK option sets the maximum stack size that can be used by Java code in a thread to x. Every thread 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 (/MAXJSTACK=400k). /TRACE /TRACE -t Prints a trace of the instructions executed (JAVA_G only). /COMMAND_LINE /COMMAND_LINE=file-name -V file-name Takes command-line options and arguments from the indicated file; causes other command-line options and arguments to be ignored. This qualifier is supported on OpenVMS systems only. /VERBOSE /VERBOSE -v -verbose Causes JAVA to print a message to stdout each time a class file is loaded. /VERBOSEGC /VERBOSEGC -verbosegc Causes the garbage collector to print out messages whenever it frees memory. /VERIFY /VERIFY /NOVERIFY -verify -noverify Performs byte-code verification on the class file. Be aware 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 on to certify class files unless all code paths in the class file are actually run. The /NOVERIFY qualifier (-noverify option) turns verification off. /VERIFYREMOTE /VERIFYREMOTE -verifyremote Runs the verifier on all code that is loaded into the system through a classloader. The default is /VERIFYREMOTE. /SYSTEM_PROPERTY /SYSTEM_PROPERTY="propertyName=newValue" -D propertyName=newValue Redefines a property value. The propertyName is the name of the property whose value you want to change and newValue is the value to change it to. For example, the following command line sets the value of the property awt.button.color to "green". % java -Dawt.button.color=green ... The JAVA command accepts any number of /SYSTEM_PROPERTY qualifiers on the command line. 2 Example $ JAVA /CLASSPATH=(USER1$:[mydir1],[.mydir2],[.mydir3]myzip.zip,[])- /INITHEAP="10m"/MAXHEAP="20m"- /SYSTEM_PROPERTY="XXX=ZZZ" "MyTestProgram" This example executes the Java runtime interpreter on the file MyTestProgram.class. The search path USER1$:[mydir1],[.mydir2],[.mydir3]myzip.zip,[] is used to override the current setting of the CLASSPATH logical. For the duration of this execution, the system property XXX is set to ZZZ. The interpreter is run with an initial heap size of 10 megabytes. Notice that the name of the class file "MyTestProgram" must be in quotation marks to preserve the case of the spelling. Without the quotation marks, OpenVMS changes the entire string to uppercase, and the class name will not match what is in the source file.