Skip to main content

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.

The > (greater than) operator is a binary relational operator that compares two numeric operands. It evaluates to a boolean value, returning true if the left-hand operand is strictly greater in mathematical value than the right-hand operand, and false otherwise.
operand1 > operand2

Operand Compatibility

The > operator is strictly limited to numeric types. It cannot be applied to boolean primitives, String objects, or standard object references.
  • Primitive Numerics: Compatible with byte, short, char, int, long, float, and double. When applied to char, Java evaluates the underlying 16-bit unsigned integer (UTF-16 code point) of the character.
  • Wrapper Classes: Compatible with numeric wrapper classes (e.g., Integer, Double, Character). The Java compiler applies auto-unboxing to extract the underlying primitive values before performing the comparison. If the wrapper object reference is null, attempting to evaluate it with the > operator will throw a NullPointerException at runtime during the unboxing process.

Type Promotion

If the two operands are of different numeric types, or if they are sub-integer types, Java applies binary numeric promotion according to the Java Language Specification before evaluating the expression:
  1. If either operand is of type double, the other is promoted to double.
  2. Otherwise, if either operand is float, the other is promoted to float.
  3. Otherwise, if either operand is long, the other is promoted to long.
  4. Otherwise, both operands are automatically promoted to int.
This means if you compare a byte and a short, both are promoted to int prior to comparison; the byte is not simply widened to match the short.
int a = 5;
double b = 4.5;
boolean result1 = a > b; // 'a' is promoted to 5.0 before comparison. Evaluates to true.

byte c = 10;
short d = 5;
boolean result2 = c > d; // Both 'c' and 'd' are promoted to int before comparison.

Floating-Point Mechanics (IEEE 754)

When evaluating floating-point numbers (float and double), the > operator adheres to IEEE 754 standards, which introduces specific behavioral rules:
  • NaN (Not a Number): If either or both operands are NaN (e.g., Double.NaN), the > operator strictly evaluates to false.
  • Infinity: POSITIVE_INFINITY is considered greater than any finite number and NEGATIVE_INFINITY.
  • Signed Zeros: Positive zero (0.0) and negative zero (-0.0) are considered mathematically equal. Therefore, 0.0 > -0.0 evaluates to false.

Syntax Visualization

// Standard primitive comparison
boolean check1 = 10 > 5;           // true

// Character comparison (evaluates ASCII/UTF-16 integer values: 98 > 97)
boolean check2 = 'b' > 'a';        // true

// Auto-unboxing evaluation
Integer objVal = 50;
boolean check3 = objVal > 25;      // true (objVal is unboxed to int 50)

// NullPointerException during auto-unboxing
Integer nullVal = null;
// boolean check4 = nullVal > 0;   // Throws NullPointerException at runtime

// Floating-point edge cases
boolean check5 = 5.0 > Double.NaN; // false
boolean check6 = 0.0 > -0.0;       // false
Master Java with Deep Grasping Methodology!Learn More