Review of Running a Java Program

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.

Answer:

(1) The program must be compiled into bytecode with the Java compiler, then (2) run using the Java interpreter.

Review of Running a Java Program

To run the program, check that the default directory of the command interpreter contains the source file. Do this by using the command DIR *.java to list the files in the subdirectory. One of the files should be Hello.java. To see all the files, just type the command DIR.

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

If you don't see the source file, use the Change Directory command CD to get to the correct subdirectory. To compile the source file (thereby producing a file of bytecodes) enter the command javac Hello.java. Finally, to run it, enter the command java Hello.

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

C:/TEMP>java Hello

Hello World!

C:/TEMP>

QUESTION 5:

  • What is the command that runs the Java compiler?
  • What is the command that runs the Java interpreter?