Small Java Programs

This chapter discusses naming and coding conventions as well as reserved words in Java. When you go through this chapter, you'll get some hands-on experience with writing in Java.

6. Running a Java Program (Review)


public    static void main(String[]  args   )

The Java compiler would accept the line. But it looks sloppy to human eyes.

Running a Java Program (Review)

If you are running Java programs using BlueJ or some other environment, or using an OS other than Windows, skip this page.

Copy and paste the example program into a text editor (like Notepad or Notepad++), and then save it to a file called  in the current directory. (Microsoft calls "directories" by the name "folders".)

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 directory. One of the files should be To see all the files, just type the command DIR .

C:\JavaSource>DIR *.java
 Volume in drive C has no label.
 Volume Serial Number is 7C68-1E55

 Directory of C:\JavaSource

 08/23/98  01:07a                   115
               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 Finally, to run it, enter the command java Hello.


C:\JavaSource>java Hello

Hello World!


Question 6:

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