# Java Object Equivalence

DevFeed: [Java Object Equivalence](<https://devfeed.tech/articles/java-object-equivalence-32234.md>)

Original publisher: [Read original article](<https://bruceeckel.com/2021/02/04/java-object-equivalence/>)

Author: Bruce Eckel

Published: 2021-02-04T00:00:00Z

Content type: tutorial

Language: en

Sources: [Bruce Eckel - Computing Thoughts](<https://devfeed.tech/sources/bruce-eckel-computing-thoughts.md>)

Topics: [Java](<https://devfeed.tech/topics/java.md>), [Testing](<https://devfeed.tech/topics/testing.md>), [Java 9](<https://devfeed.tech/topics/java-9.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [floating-point](<https://devfeed.tech/tags/floating-point.md>), [java](<https://devfeed.tech/tags/java.md>), [java-8](<https://devfeed.tech/tags/java-8.md>), [java-9](<https://devfeed.tech/tags/java-9.md>), [object](<https://devfeed.tech/tags/object.md>), [testing](<https://devfeed.tech/tags/testing.md>), [time](<https://devfeed.tech/tags/time.md>)

## AI overview

An update to the "Testing Object Equivalence" subsection in On Java 8 explains how Java's == and != operators compare object references, why boxed integer comparisons can vary by value range and object creation method, and why equals() should be used for object value comparisons. It also discusses related issues with floating-point comparisons and notes the deprecation of Integer(int) in Java 9 and later.

## Source excerpt

This is an update to the subsection "Testing Object Equivalence" in the "Operators" chapter of On Java 8. This will appear in the book in its next update. The relational operators == and != work with all objects, but their results can be confusing: // operators/Equivalence.java public class Equivalence { static void show(String desc, Integer n1, Integer n2) { System.out.println(desc + ":"); System.out.printf( "%d==%d %b %b%n", n1, n2, n1 == n2, n1.