go to previous page   go to home page   go to next page        


Compile it into Java bytecodes, then run the bytecode file with the Java interpreter.

Running the Program

To do all that, find the DOS command prompt window you started up a while back. It should still be positioned in the C:/Temp directory (or other directory of your choice). To check that you put the source file Hello.java in this directory, enter the command dir *.java. You should see the source file, as below.

C:/TEMP>dir *.java
 Volume in drive C has no label.
 Volume Serial Number is 7C68-1E55

 Directory of C:/TEMP

 08/23/98  01:07a                   115 Hello.java
               1 File(s)            115 bytes
                          2,448,368,640 bytes free

To compile the source file (thereby producing a file of bytecodes) enter the command javac Hello.java.

C:/TEMP>javac Hello.java
  compiling: Hello.java

Notice that this command is javac, java-with-a-c which invokes the Java compiler. If you see the following

C:/TEMP>javac Hello.java
The name specified is not recognized as an
internal or external command, operable program or batch file.

then the PATH environment variable has not been set correctly. Look at Appendix C for information about this. A temporary alternative is to tell the command promt exactly where to find javac:

C:/Temp> C:/Program Files/Java/jdk1.6.0_07/bin/javac Hello.java

Adjust the above command to match whatever directory your version of Java has been installed in. Finally, to run the program, enter the command java Hello.

C:/TEMP>java Hello

Hello World!


Notice that this command is java, java-without-a-c which invokes the Java interpreter. Again, if PATH is incorrect, you can run java by using the full path name to its location.


After all of this, what did the Java program actually do?