Java Reference
In-Depth Information
Some arguments used with the kit modify how a tool functions. These arguments are pre-
ceded by a hyphen character and are called options .
The following command shows the use of an option:
java -version
This command tells the Java interpreter to display its version number rather than trying
to run a class file. It's a good way to find out whether the kit is correctly configured to
run Java programs on your system. Here's an example of the output run on a system
equipped with JDK 6:
B
java version “1.6.0”
Java(TM) 2 Runtime Environment, Standard Edition (build1.6.0)
Java HotSpot(TM) Client VM (build 1.6.0, mixed mode)
The version reflects Sun's internal number for JDK 6, which is 1.6.
In some instances, you can combine options with other arguments. For example, if you
compile a Java class that uses deprecated methods, you can see more information on
these methods by compiling the class with a -deprecation option, as in the following:
javac -deprecation OldVideoBook.java
The java Interpreter
java , the Java interpreter, is used to run Java applications from the command line. It
takes as an argument the name of a class file to run, as in the following example:
java BidMonitor
Although Java class files end with the .class extension, this extension will not be speci-
fied when using the interpreter.
The class loaded by the Java interpreter must contain a class method called main() that
takes the following form:
public static void main(String[] arguments) {
// Method here
}
Some simple Java programs might consist of only one class—the one containing the
main() method. In more complex programs that make use of other classes, the interpreter
automatically loads any other classes that are needed.
 
Search WWH ::




Custom Search