Running a Java Program
To see whether the Splash program does what you want, run the class with the JVM, the interpreter that runs all Java code. In NetBeans, select the menu command Run, Run File. An Output pane opens below the source code editor. In this pane, if there are no errors, the program displays the output, as shown in Figure 4.4.
FIGURE 4.4 Running the Splash Java program.
If you see the text Blue warrior shot the food!, you have written, compiled, and run the Java program successfully.
Blank Spaces and Whitespace in a Java Program
As you typed in the Splash program in Listing 4.1, taking care to get the right number of spaces before each statement to make sure it all lined up properly, you might have asked yourself whether that’s important.
Blank spaces and whitespace are completely unimportant as far as the computer is concerned. Spacing is strictly for the benefit of people looking at a computer program—the Java compiler doesn’t care. You could have written the Splash program without using blank spaces or used the Tab key to indent lines, and it would compile successfully.
Although the number of spaces in front of lines isn’t important, you should use consistent spacing and indentation in your Java programs. Why? Because spacing makes it easier for you to see how a program is organized and to which programming block a statement belongs.
The programs you write must be understandable to other programmers, including yourself when you look at the code weeks or months later to fix a bug or make an enhancement. Consistency in spacing and indentation are part of what’s called a programming style. Good programmers adopt a style and practice it in all their work.