More about Objects and Classes
The relational operations on primitive data are ==, >=, <=, >, <, and !=. They compare two data values, when those values' type has an ordering. For example, integers are ordered by size or magnitude. The result of a relational operation is a boolean value: either True or False. The relational operators on objects like Strings are different, and they are expressed as methods. Pay special attention to the equality method, equals().
The following table is a summary. There are four rows, one for each choice of true and false. The last row shows a choice that is not possible. If
== is true, there is only one object, which must be
equals to itself.
|code section||pointA == pointB||pointA.equals( pointB )|
Point pointA = new Point( 21, 17 ); Point pointB = pointA;
Point pointA = new Point( 21, 17 ); Point pointB = new Point( -99, 86 );
Point pointA = new Point( 21, 17 ); Point pointB = new Point( 21, 17 );
pointA.equals(pointB)return the same true/false value as
pointA == pointBreturn the same true/false value as
pointB == pointA?