Java Reference
In-Depth Information
System.out.println("Line 6: The value of "
+ "num1 == num2 is "
+ (num1 == num2));
//Line 6
}
}
Sample Run:
Line 4: num1 = 2567.58, num2 = 2567.58
Line 5: The value of num1.equals(num2) is true
Line 6: The value of num1 == num2 is false
In the preceding program, the statements in Lines 2 and 3 create two objects, each with the
value
2567.58
and make
num1
and
num2
, respectively, point to these objects. The expres-
sion
num1.equals(num2)
, in Line 5, compares the values stored in the objects to which
num1
and
num2
point. Because both objects contain the same value, this expression evaluates
to
true
; see the output of the statement in Line 5. On the other hand, the expression
num1
¼¼
num2
, in Line 6, determines whether
num1
and
num2
point to the same object.
6
Note that the program in Example 6-5 also illustrates that when you create a
Double
object using the assignment operator without explicitly using the operator
new
, the system
always creates a different
Double
object even if one with a given value already exists. For
example, see the statements in Lines 2 and 3, and the output of the statement in Line 6.
QUICK REVIEW
1
.
GUI stands for graphical user interface.
2
.
Every GUI program requires a window.
3
.
Various components are added to the content pane of the window and not
to the window itself.
4
.
You must create a layout before you can add a component to the content pane.
5
.
Pixel stands for picture element. Windows are measured in pixels of height
and width.
6
.
JFrame
is a class and the GUI component
window
can be created as an
instance of
JFrame
.
7
.
JLabel
is used to label other GUI components and to display information
to the user.
8
.
A
JTextField
can be used for both input and output.
9
.
A
JButton
generates an event.
10
.
An event handler is a Java method that determines the action to be
performed as the event happens.
11
.
When you click a button, an action event is created and sent to another
object known as an action listener.
Search WWH ::
Custom Search