Simulated 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.
go to previous page   go to home page   hear noise   go to next page

What does the program print on the monitor when it runs?

Answer:

The variable contains: 123

Simulated Java Program

To get the most out of these notes, copy the program to a text editor, save it to a file called Example.java, compile it, and run it. See Chapter 7 on how to do this. For a simulation of running the program, enter an integer in the text box below and click on "Compile", then click on "Run". (Note: if this does not work, your browser does not have JavaScript enabled.)


class Example
{
  public static void main ( String[] args )
  {
    long payAmount = ;    // declaration of a variable

    System.out.println("The variable contains: " + payAmount );
  }
}

Simulated Monitor



This is just a simulation (using JavaScript), so it is not exactly like a compiling and running a real Java program. Don't take it too seriously. Please do the real thing if you can.

QUESTION 4:

Try entering something like "rats" in the declaration. Does the program compile successfully?