Longer Example 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. Will this program compile without syntax errors?
    • Yes.
  2. Will this program run?
    • Yes.
  3. Does the program meet the assignment?
    • No—it has a bug.

Longer Example Program

Usually bugs are much more difficult to find than the one in this program. The longer a program is, the more bugs it is likely to have, and the more difficult it is to find them. It is a good idea to practice with short programs where syntax errors and bugs are more easily seen before moving on to longer programs.

Here is a somewhat longer example program:

class Emily
{
  public static void main ( String[] args )
  {
    System.out.println("A bird came down the walk:");
    System.out.println("He did not know I saw;");
    System.out.println("He bit an angle-worm in halves");
    System.out.println("And ate the fellow, raw.");
  }
}

This program should be saved in a file called Emily.java and with it the compiler will create a bytecode file called Emily.class.

QUESTION 10:

What will this program write to the monitor when it is run?