Java Reference
In-Depth Information
ample, issue the following command to compile the HelloWorld class from Recipe
1-2.
Windows:
javac
org\java8recipes\chapter01\recipe1_02\HelloWorld.java
OS X:
javac org/java8recipes/chapter01/recipe1_02/
HelloWorld.java
You should now have a .class file in the same directory as your .java file. For
example:
dir org\java8recipes\chapter01\recipe1_02 /B
HelloMessage.class
HelloWorld.class
HelloWorld.java
Compilation produces two files. One is for HelloMessage , and the other is for
the class named HelloWorld implementing the main() method.
Execute the main() method by issuing the java command to invoke the Java
Virtual Machine (JVM). Pass the fully-qualified class name as a parameter to the com-
mand. Qualify the class name by prepending the package name, but this time use the
same dot-notation as used in your source file. For example:
java org.java8recipes.chapter1.recipe1_02.HelloWorld
Do not specify .class at the end of the command. You are referencing Hel-
loWorld now as a class name, and not as a file name. You should see the same output
as from Recipe 1-2.
Tip One compiles source code. Source code is kept in files, so your operating-sys-
tem's file and directory-path notation is appropriate. One executes a class. A class is an
Search WWH ::




Custom Search