A good answer might be:

Yes—sometimes typing in a program forces you to see details you would otherwise miss. Other times it is a waste of effort. Of course, not running the program at all is a supreme waste of opportunity.

Copying and Pasting

Here is an example Java program. Just for fun, the program is different than the previous examples. The details won't be explained until later chapters.

class HelloPlanets
{
  public static void main ( String[] args )
  {
    String[] planets = {"Mercury", "Venus",  "Earth",   "Mars", "Jupiter", 
                        "Saturn",  "Uranus", "Neptune", "Pluto"};
  
    for ( int j=0; j< planets.length; j++ )
    {
      System.out.println("Hello " + planets[j] +"!" );
    }
  }

}

Here is an outline of how to run the program. You can try this now, or continue reading this chapter (which shows the method step-by-step.)

Windows:

  1. Start Notepad and a DOS window.
  2. In the DOS window, use the CD command to go to a convenient subdirectory.
    • In this example, C:\Temp will be used.
  3. COPY: Copy the program into the clipboard.
    1. In the browser window (this window), put the mouse pointer on the "c" of "class".
    2. Push down on the left mouse button, then drag down until the final "}" of the program is covered.
    3. Lift up on the mouse button.
    4. Click on the "Edit" menu of the browser and then click on "Copy". This makes a copy of the program in the clipboard, a section of the computer's main memory.
  4. PASTE: Click inside the Notepad window to make it active. Go to its "Edit" menu and click on "paste." You should now have have a copy of the program in Notepad.
  5. SAVE: Click on the "File" menu of Notepad and "Save As" HelloPlanets.java.
    • You will have to "navigate" to the same subdirectory as in step 2.
  6. RUN: Run the program:
    1. Click in the DOS window Do a DIR to check that HelloPlanets.java is there.
    2. Compile the program: C:\Temp> javac HelloPlanets.java
    3. Run the program: C:\Temp> java HelloPlanets

Windows 95 Version:

  1. Start Notepad.
  2. COPY: Copy the program into the clipboard.
    1. In the browser window (this window), put the mouse pointer on the "c" of "class".
    2. Push down on the left mouse button, then drag down until the final "}" of the program is covered.
    3. Lift up on the mouse button.
    4. Click on the "Edit" menu of the browser and then click on "Copy". This makes a copy of the program in the clipboard, a section of the computer's main memory.
  3. PASTE: Click inside the Notepad window to make it active. Go to its "Edit" menu and click on "paste." You should now have have a copy of the program in Notepad.
  4. SAVE: Click on the "File" menu of Notepad and "Save As" HelloPlanets.java.
    • You will have to "navigate" to the subdirectory you wish to use.
  5. Start up a DOS window.
  6. In the DOS window, use the CD command to go to the subdirectory that holds the file.
    • In this example, C:\Temp will be used.
  7. RUN: Run the program:
    1. In the DOS window. Do a DIR to check that HelloPlanets.java is there.
    2. Compile the program: C:\Temp> javac HelloPlanets.java
    3. Run the program: C:\Temp> java HelloPlanets
  8. Exit DOS: type "exit" at the DOS prompt.

QUESTION 2:

(Review:) How can Notepad be started?