Java Reference
In-Depth Information
Q: So how do you use a reference to access the data in an object?
A: That is a question I will answer in great detail in Chapter 4,
“Classes and Objects.”
Constants
The final keyword is used in Java to declare a variable as a constant. A final in
Java cannot be changed after it is assigned a value. Consider the following
statements, some of which compile and some of which don't.
final double pi = 3.14159;
pi = -5.0; //Does not compile!
final int x //A blank final
x = 12; //ok
x = 100 //Does not compile!
The variable pi is declared final and initialized to 3.14159, so attempting to
change it to -5.0 is not valid.
The variable x is declared final, but is not initialized. This can be done in
Java, and x is referred to as a blank final. Assigning it to 12 at a later time is
valid, but it cannot be changed after it is assigned. Trying to change it to 100 is
invalid and causes a compiler error.
Java Operators
Table 2.4 shows the various operators in Java. The operators are listed in the
precedence that they are evaluated, with the pre- and postincrement/decre-
ment operators having the highest precedence.
Table 2.4
Java Operators and Precedence
OPERATOR
SYNTAX
Pre- and postincrement/decrement
++, - -
Unary operators
+, -, ~, !, (cast)
Multiplication/division/modulus
*, /, %
Addition/subtraction/concatenation
+, -, +
Shift Operators
<<, >>, >>>
Comparison
<, <=, >, > =, instanceof
(continued)
Search WWH ::




Custom Search