TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
< (less than) operator is a binary relational operator that compares the values of two numeric operands. It evaluates to the boolean value true if the left-hand operand is strictly lesser in mathematical value than the right-hand operand, and false otherwise.
Operand Compatibility
The< operator strictly requires operands that can be resolved to numeric types.
- Supported Primitives:
byte,short,char,int,long,float, anddouble. - Unsupported Types:
boolean,String, and all object references (with the exception of numeric wrapper classes).
Binary Numeric Promotion
Before performing the comparison, Java applies binary numeric promotion to the operands according to the Java Language Specification. This promotion occurs for all numeric comparisons based on the following strict hierarchy:- If either operand is of type
double, the other is promoted todouble. - Otherwise, if either operand is of type
float, the other is promoted tofloat. - Otherwise, if either operand is of type
long, the other is promoted tolong. - Otherwise, both operands are promoted to
int.
int (byte, short, and char) are always widened to int prior to comparison, even if both operands are of the exact same type or if the broadest type between the two is smaller than int.
Auto-Unboxing
If either operand is a numeric wrapper class (e.g.,Integer, Double, Character), Java automatically unboxes the object into its corresponding primitive type before applying binary numeric promotion and evaluating the relational expression.
null, the unboxing attempt will throw a NullPointerException.
Floating-Point Specifics
When evaluatingfloat or double operands, the < operator adheres to IEEE 754 standards for floating-point arithmetic:
- NaN (Not a Number): If either operand is
NaN, the<operator always evaluates tofalse. - Infinity: Negative infinity (
-Infinity) is considered strictly less than any finite value and positive infinity (+Infinity). - Signed Zeros: Positive zero (
0.0) and negative zero (-0.0) are considered equal. Therefore,-0.0 < 0.0evaluates tofalse.
Character Comparison
When applied tochar operands, the < operator compares their 16-bit Unicode (UTF-16) integer values.
Master Java with Deep Grasping Methodology!Learn More





