From the article:
Originally Posted by
Common Java Mistakes
The equals operator is used exclusively to compare the value of primitives, or to compare the references (memory addresses) of objects.
The equals() method is used to define when two object values are equal. They do not necessarily have to be the same object (though, if they are they should return true for equals() as well as ==).
To add a little more to this, most objects in Java are referenced by their memory address. When you use the == operator, you're comparing the addresses of two objects. So if you have two distinct object which
happen to have the same value, would still have different memory addresses, and == would return false. If you want to test if two objects just happen to have the same value, you use the .equals() method.
Note that for primitives (int, boolean, byte, float, etc.) there's no need for a .equals() method because these don't contain a reference to the value, but rather contain the value itself. However, if you're using wrapper classes (Integer, Float, Boolean, etc.), you must use the .equals() method because now you're holding references to the wrapper object, not the direct value.
.equals() is used because Java doesn't have operator overloading. Python does, so you could overload == to do what the .equals() method does in Java. To allow Python users to still compare memory addresses, Python has the
is keyword, which is analogous to Java's == operator.
I've never used
VB, so I couldn't say what the equivalent
VB code would be