Next: Lab Exercise 3: Generating
Up: In the Laboratory: Editing,
Previous: Lab Exercise 1: Editing,
In this exercise you will make modifications to FirstApplet
which will introduce syntax errors into your
program. The main purpose here is to give you a first look at how your
programming environment reports error messages. You'll also learn some
of the most fundamental rules of Java syntax.
For each of the items below, make the editing change and then
recompile the program. Make note of any error messages that are
generated by the compiler. Try to understand what the message is
telling you, and try to learn from the error, so it will be less
likely to occur next time. After you have finished with that error,
restore the code to its original form and move on to the next item.
- Java Language Rule. Every Java statement must end with a semicolon.
Delete the semicolon at the end of one of the lines in the
program. Repeat this experiment for different lines and note
the error messages. Are they always the same? Sometimes
the compiler can tell that you've forgotten a semicolon,
but sometimes a missing semicolon causes the compiler to
lose its place.
- Java Language Rule. Variables must be declared before they can be used.
Turn the line in which the Button is declared into a comment by
typing double slashes ``//'' at the beginning of the line. The
compiler will now skip that line. Because you haven't removed the
line from the source code, you can easily put it back in the program
by removing the double slashes.
- Java Language Rule. Java names are case sensitive.
Change the spelling of clickMe to ClickMe in the
declaration statement but nowhere else in the program.
Next: Lab Exercise 3: Generating
Up: In the Laboratory: Editing,
Previous: Lab Exercise 1: Editing,
Ralph Morelli {Faculty}
2002-03-02