Java Reference
In-Depth Information
Figure 2.6
The BlueJ Code Pad
Exercise 2.79 Consider the following expressions. Try to predict their results, and then type
them in the Code Pad to check your answers.
99 + 3
"cat" + "fish"
"cat" + 9
9 + 3 + "cat"
"cat" + 3 + 9
"catfish".substring(3,4)
"catfish".substring(3,8)
Did you learn anything you did not expect from the exercise? If so, what was it?
When the result of an expression in the Code Pad is an object (such as a String ), it will be
marked with a small red object symbol. You can double-click this symbol to inspect it or drag it
onto the object bench for further use. You can also declare variables and write complete state-
ments in the Code Pad.
Whenever you encounter new operators and method calls, it is a good idea to try them out here
to get a feel for their behavior.
You can also explore the use of variables in the Code Pad. Try the following:
sum = 99 + 3;
You will see the following error message:
Error: cannot find symbol - variable sum
This is because Java requires that every variable ( sum , in this case) be given a type before it can
be used. Recall that every time a field, parameter, or local variable has been introduced for the
 
Search WWH ::




Custom Search