Running Code: In-depth
While Java provides some advanced command-line options to optimize the source-code compilation, it does no less for running the codes (programs). Just as ‘javac’ is the tool for compiling Java programs, the ‘java’ or ‘javaw’ tool is used for running the programs. The ‘java’ and ‘javaw’ tool are basically the same and accepts a similar set of options. However, there is a slight difference in their execution procedure. Whenever we run a Java Applet or any stand-alone GUI application with Java JFC/Swing or AWT, a console window remains associated with the application window and waits for the application to terminate. This is often quite irritating. In such cases the ‘javaw’ tool can be used which does not associate the console window with the application and leaves both of them independent.
Using the 'javaw' tool. Note that the prompt reappears after the application has started. |
Using the 'java' tool. After executing the application, the command-prompt waits for the app to exit. |
This is how you use the ‘java’ and ‘javaw’ tool:
java [options] class [arguments . . . ]
java [options] –jar file.jar [arguments . . . ]
javaw [options] class [arguments . . .]
javaw [options] –jar file.jar [arguments . . . ]
Here’s a complete list of the available command-line options of the afore-mentioned tools.
Options
|
Description
|
-classpath
|
It specifies or defines the directories or .jar (Java Archive) files to look for the source class files. The CLASSPATH environment variable is generally overridden when this option is used. Multiple directories can be referred by separating them by a semi-colon (;). Note that, if this option is not used, the user class path is limited to the current directory.
|
-Dproperty=value
|
It is used to set a system property value. For example, if do not want to use the default JIT (Just In Time) compiler for executing your class files, you can use the option –Djava.compiler=NONE
|
-jar
|
Used to specify the .jar file which contains the classes you want to execute. The argument passed to the –jar option should be the name of the .jar file and not the class.
|
-verbose
|
It displays detailed information about each of the classes that are loaded.
|
-verbose:gc
|
It reports on every event of Garbage Collection.
|
-verbose:jni
|
It informs about any native or platform-specific method or about any other Java Native Interface activity in a program.
|
-version
|
It only displays the version information and exists.
|
-? or –help
|
It displays any help information associated with the tool and exists.
|
-X
|
It displays information about all the non-standard options and then terminates.
Note that all the options preceded by ‘-X’ are non-standard, which means they might not be supported in the future.
|
-Xbootclasspath:bootclasspath
|
It specifies the directories, .jar files or, zip files to search for the boot class files. Multiple sources can be separated by a semi-colon (;). Remember, if you use this option, the given class files override the class files provided as default by Java.
|
-Xdebug
|
It launches the program with debugger enabled.
|
-Xnoclassgc
|
It disables class garbage collection.
|
-Xms
|
It defines the startup memory pool size of the JVM. The value must be greater than a Kilobyte. It generally accepts values in bytes. So, to indicate memory size in Kilobytes, append ‘k’ to the amount. Similarly, append ‘m’ to indicate size in Megabytes.
Example: -Xms5 (5 bytes)
-Xms5k (5 Kilobytes)
-Xms20m (20 Mb)
|
-Xmx
|
It specifies the maximum memory pool size or the heap size for the JVM. The default value is 64m (64 Mb). Often while working with too many images in a Java application, the 64mb limit is not enough. You could then override this option to meet your needs. Append ‘k’ for Kilobytes and ‘m’ for Megabytes.
|
-Xrs
|
It reduces the usage of Operating System signals.
|
-Xcheck:jni
|
It performs additional checks for Java Native Interface methods.
|
-Xfuture
|
It strictly checks for class file formats.
|
-Xrunhprof [:help] [:
|
It enables profiling of the CPU or memory used by the program.
|
See also: Compiling code: In-depth
this is quite interesting info.
ReplyDeleteWeb design company India