Java Reference
In-Depth Information
The Java interpreter runs bytecode—the compiled instructions that are executed by a
Java virtual machine. After a Java program is saved in bytecode as a
.class
file, it can
be run by different interpreters without modification. If you have compiled a Java pro-
gram, it will be compatible with any interpreter that fully supports Java.
Interestingly enough, Java is not the only language that you can
use to create Java bytecode. NetRexx, JPython, JRuby, JudoScript,
and several dozen other languages will compile into
.class
files of
executable bytecode through the use of compilers specific to
those languages. Robert Tolksdorf maintains a comprehensive list
of these languages that is currently available from the web page
NOTE
You can specify the class file that will be run by the Java interpreter in two different
ways. If the class is not part of any package, you can run it by specifying the name of the
class, as in the preceding
java BidMonitor
example. If the class is part of a package,
you must specify the class by using its full package and class name.
For example, consider a
SellItem
class that is part of the
org.cadenhead.auction
pack-
age. To run this application, the following command would be used:
java org.cadenhead.auction.SellItem
Each element of the package name corresponds to its own subfolder The Java interpreter
will look for the
SellItem.class
file in several different places:
The
org\cadenhead\auction
subfolder of the folder where the
java
command
was entered (if the command was made from the
C:\J21work
folder, for example,
the
SellItem.class
file can be run successfully if it was in the
C:\J21work\org\
cadenhead\auction
folder)
n
The
org\cadenhead\auction
subfolder of any folder in your
Classpath
setting
n
If you're creating your own packages, an easy way to manage them is to add a folder to
your
Classpath
that's the root folder for any packages you create, such as
C:\javapack-
ages
or something similar. After creating subfolders that correspond to the name of a
package, place the package's class files in the correct subfolder.
Java supports assertions, a debugging feature that only works when requested as a com-
mand-line option. To run a program using the Java interpreter and make use of any asser-
tions that it contains, use the command line
-ea
, as in the following example:
java -ea Outline