Java Quick Guide

 
 
This guide contains useful Java information.







Java Command.



Information
Usage to execute a class: java [-options] class [args...]
Usage to execute a jar file: java -jar [-options] jarfile [args...]

The options can be found in the below mentioned table.
Note: Based on java version 1.4.0_03

Options Description
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp -classpath <directories
and zip/jar files separated by ;>
set search path for application classes and resources
-D<name>=<value> set a system property
-verbose[:class|gc|jni] enable verbose output
-version print product version and exit
-showversion print product version and continue
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]

-enableassertions[:<packagename>...|:<classname>]
enable assertions
This will enable all assertions except those in system classes.
Assertions are disabled by default.
The Java assert statement is available only in JDK 1.4 and later versions.

Note:
For compatability reasons, a compiler switch (-source 1.4) is required on the compiler command line for assert statements to be compiled.
For example:
javac -source 1.4 HelloWorld.java
-da[:<packagename>...|:<classname>]

-disableassertions[:<packagename>...|:<classname>]
disable assertions
Classes or packages can be selectively disabled.
The Java assert statement is available only in JDK 1.4 and later versions.

Note:
For compatability reasons, a compiler switch (-source 1.4) is required on the compiler command line for assert statements to be compiled.
For example:
javac -source 1.4 HelloWorld.java
-esa | -enablesystemassertions enable system assertions
This will enable all assertions in system classes.
Assertions are disabled by default.
The Java assert statement is available only in JDK 1.4 and later versions.
-dsa | -disablesystemassertions disable system assertions
System classes or packages can be selectively disabled.
The Java assert statement is available only in JDK 1.4 and later versions.

Example: Execute Test.class

C:\Tools\java\jdk1.3.1_09\bin\java -cp c:/demo/lib/file1.jar;c:/demo/lib/file2.jar;
c:/demo/lib/classes12.zip;c:/demo/bin; com.mobilefish.demo.Test
  • c:/demo/lib
    Contains the libraries such as *.jar, *.zip
  • c:/demo/src
    Contains the source files *.java
  • c:/demo/bin
    Contains the compiled class files *.class from the c:/demo/src directory.
  • c:/demo/properties
    Contains the properties files such as *.properties, *.xml
    Usually when you compile the *.java files all files within the properties directory are automatically placed in the c:/demo/bin directory together with the class files.