Java Reference
In-Depth Information
abstract concept in the language, so the language's dot-notation becomes appropriate.
Keep this distinction in mind to help yourself remember when to use which notation.
How It Works
The first two solution steps are housekeeping steps. You must have the Java compiler
and the virtual machine in your execution path. It's also necessary for any classes used
by your program to be found somewhere along what is termed the
class path
. One way
to specify the class path is through the
CLASSPATH
environment variable.
The command
java
with no
c
at the end is for executing compiled code. Pass as a
parameter the qualified name of the class containing your
main
method. The JVM will
interpret and execute the byte-code within that class, beginning from the
main
meth-
od. The JVM will search along the class path for any additionally required classes such
as
HelloMessage
.
The compiler's default behavior is to place each generated class file into the same
directory as holds the corresponding source file. You can override that behavior
through the
-d
option. For example:
javac -d "<specify-different-location>" "<path-to-project>
\Java8Recipes\src\org\java8recipes\chapter1\recipe1_02\HelloWorld.java"
The
-d
option in this command specifies the same directory as NetBeans is using
in our own environment as the target for holding generated class files. The command
also specifies the full path and file name of the source file. Thus, the command can be
executed with the same result regardless of the current working directory.
Tip
Configure your system so that your command-line environment has the execu-
tion path and class path set correctly by default. The typical approach in Linux is to put
appropriate commands into your
.profile
or
.bash_profile
files. Under Win-
dows you can specify environment variable defaults from the Control Panel applet
named System, by clicking on the Advanced system settings link, and then on the Envir-
onment Variables button.
There may be times when you need to specify a custom class path for a specific ex-
ecution of the JVM. You can do that through the
-cp
parameter, as follows: