Java Reference
In-Depth Information
Next, consider the following statements:
String str3 =
new
String("Hello");
String str4 =
new
String("Hello");
When the first statement executes, a
String
object with the value
"Hello"
is created
and its address is assigned to
str3
. When the second statement executes, another
String
object with the value
"Hello"
is created and its address is assigned to
str4
(see Figure 4-8).
str3
Hello
str4
Hello
FIGURE 4-8
Variables
str3
,
str4
, and the objects to which they point
It follows that the expression
(str3 == str4)
evaluates to
false
. However, the
expression
str3.equals(str4)
evaluates to
true
.
The program
StringObjectsAndTheOprNew.java
, which shows the effect of
the preceding statements, can be found in the Additional Student Files folder at
www.cengagebrain.com.
QUICK REVIEW
1
.
Control structures alter the sequential flow of control.
2
.
The two most common activities provided by control structures are selection
and repetition.
3
.
Selection structures incorporate decisions in a program.
4
.
The Java relational operators are
==
(equality),
!=
(not equal to),
<
(less
than),
<=
(less than or equal to),
>
(greater than), and
>=
(greater than or
equal to).
5
.
Including a space within the relational operators
==
,
<=
,
>=
, and
!=
creates
a syntax error. (For example,
= =
will create a syntax error.)
6
.
Characters are compared using the collating sequence of the Unicode
character set.
7
.
Logical (boolean) expressions evaluate to
true
or
false
.
8
.
In Java,
boolean
variables are used to store the value of a logical expression.
Search WWH ::
Custom Search