Java Reference
In-Depth Information
5.4
T HE J AVA R UNTIME E NGINE
You can download and install just the software required to run Java applications
without the development tools. This is known as the Java 2 Runtime Edition .
5.4.1
You run a Java program by invoking the java command. Usually, the argument
to the command is a class name. That class is loaded, and its main() method
is run.
Remember, this is not a filename, but a class name! The rest of the com-
mand-line arguments that follow the class name are passed as an array of
String s to the main() method of the named class. Example 5.4 demonstrates
running the FetchURL program.
The Basics
Example 5.4 Running a Java program with java
$ java FetchURL http://www.yahoo.com/news
http://www.yahoo.com/news:
<html>
<head><title>Yahoo! Directory News and Media</title>
<script type="text/javascript"
src="http://us.js1.yimg.com/us.yimg.com/lib/common/yg_csstare.js">
</script>
<style>
li { font-size: 12px; margin-bottom: 2px; }
</style>
<base href=http://dir.yahoo.com/News_and_Media/></head>
<body>
...
... etc.
CAUTION
Remember that if you override the classpath, either with the -classpath or
-cp command-line options (detailed below) or with the CLASSPATH environ-
ment variable, you must include the “ . ” directory somewhere in the classpath
if you want Java to include current working directory in the search list. Since “ .
is the default classpath, many people are surprised when they set a classpath
and suddenly can no longer run a .class file in their current directory.
Search WWH ::




Custom Search