> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Java Inequality

The `!=` (inequality) operator is a binary relational operator that evaluates whether two operands are not equal. It returns a `boolean` value: `true` if the operands differ in value or reference, and `false` if they are identical. A notable exception to this rule involves floating-point `NaN` (Not-a-Number) values; in accordance with IEEE 754 standards, `Float.NaN != Float.NaN` and `Double.NaN != Double.NaN` evaluate to `true`.

```java theme={"dark"}
operand1 != operand2
```

## Primitive Type Evaluation

When applied to primitive data types (`byte`, `short`, `int`, `long`, `float`, `double`, `char`, `boolean`), the `!=` operator compares the actual literal values stored in memory.

If the operands are of different numeric types, Java applies **binary numeric promotion** before comparison. The narrower type is implicitly widened to match the broader type.

```java theme={"dark"}
int a = 5;
double b = 5.0;
boolean result = (a != b); // Evaluates to false. 'a' is promoted to 5.0 before comparison.

char c = 'A';
int d = 65;
boolean charResult = (c != d); // Evaluates to false. 'A' is promoted to its ASCII integer value 65.
```

## Reference Type Evaluation

When applied to reference types (objects, arrays, strings), the `!=` operator evaluates **reference inequality**. It checks whether the two operands point to different memory addresses (object identities) on the heap. It does not evaluate the internal state or content of the objects.

```java theme={"dark"}
String str1 = new String("Java");
String str2 = new String("Java");
boolean result = (str1 != str2); // Evaluates to true. They hold the same string, but occupy different memory addresses.
```

## Null Evaluation

When comparing reference types, the `!=` operator is null-safe. It can evaluate whether a reference variable points to a memory location other than the `null` literal without throwing an exception.

```java theme={"dark"}
Object obj = null;
boolean result = (obj != null); // Evaluates to false.
```

## Autounboxing Mechanics

When evaluating inequality between a primitive type and its corresponding wrapper class (e.g., `int` and `Integer`), Java performs **autounboxing**. The wrapper object is converted to its primitive value before the comparison occurs.

However, this operation is not null-safe. If the wrapper object is `null` and is compared to a primitive type using `!=`, Java's attempt to unbox the `null` reference will throw a `NullPointerException`.

If *both* operands are wrapper objects, no unboxing occurs. The operator defaults back to reference inequality.

```java theme={"dark"}
Integer wrapper1 = 1000; // Autoboxed value outside the -128 to 127 cache
int primitive = 1000;
boolean result1 = (wrapper1 != primitive); // Evaluates to false (value comparison via autounboxing).

Integer wrapper2 = 1000;
boolean result2 = (wrapper1 != wrapper2); // Evaluates to true (reference comparison, no unboxing).

Integer nullWrapper = null;
// boolean result3 = (nullWrapper != primitive); // Throws NullPointerException during autounboxing.
```

## Operator Precedence

The `!=` operator shares the same precedence level as the equality operator (`==`). It has lower precedence than relational magnitude operators (`<`, `>`, `<=`, `>=`) but higher precedence than logical operators (`&&`, `||`). It evaluates from left to right.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Java Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
