The usual comparison operators: ==, <, <=, >=, != used to compare basic numeric types would compare addresses if used for Class types.
Every class type has a method for equality testing:
public boolean equals(Object x)
For some class types, the idea of an ordering makes no sense. E.g., what would it mean for one Scanner instance to be less than another Scanner instance.
So the operators <, <=, >, >= only make sense for class with an ordering.
For every class type for which there is a natural ordering, the class will have a method:
public int compareTo(Object x)
For example, strings are ordered in the usual alphabetic (lexicographic) ordering:
- "car" comes before "cat"
- "cat" comes before "catch"
So the String class has the compareTo method in addition to the equals method.