Question: In Java, when two objects are compared using ==, their references are also compared. But what happens when they are compared using other relational operators? For instance:

```
 Integer a = new Integer(10);
 Integer b = new Integer(9);
 if (a >= b) {
  System.out.println("A is greater");
 }

```

When I run this, I get output as A is greater, why so? Do references not get compared or they do and it's just a coincidence?

Also, if one of the arguments is primitive, does the non-primitive one get unwrapped to primitive for such comparisons?

Answer: 
In your example, the `Integer`(s) are [unboxed](https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html) to primitive `int`(s). There is no `<=` (or `>=`) comparison for reference types (without `Comparable`, `Comparator` or similar).
In addition to @Elliott Frisch 's answer, if the object cannot be unboxed (like instances of `BigInteger`, `BigDecimal`, `String`, or anything non-numeric), the `compareTo` method of the `Comparable` interface is used, the the result is compared to `0` using relational operators:

```
var a = new BigInteger("10");
var b = new BigInteger("9");
System.out.println(a.compareTo(b) < 0); // prints true, because a < b
System.out.println(a.compareTo(b) > 0); // prints false

```

Comparing non-number objects might be crazy:

```
String x = "abcd";
String y = "defg";
System.out.println(x.compareTo(y) < 0); // prints false, because 'a' < 'd'

```

With this, remember to implement [`Comparable`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Comparable.html) when you need to compare classes you defined.