Search code examples
javahexcase-sensitivecase-insensitive

Why hexadecimal is not case sensitive in Java?


If Java is a case-sensitive language then why are hexadecimal values not case-sensitive?

int x = 0x21af3;
int y = 0X21AF3;

System.out.println(x==y);

It returns true. Can anyone explain why hexadecimal is not case-sensitive?


Solution

  • Because the Java Language Specification says it isn't case-sensitive.

    Under 3.10.1. Integer Literals:

    A hexadecimal numeral consists of the leading ASCII characters 0x or 0X followed by one or more ASCII hexadecimal digits interspersed with underscores, and can represent a positive, zero, or negative integer.

    Hexadecimal digits with values 10 through 15 are represented by the ASCII letters a through f or A through F, respectively; each letter used as a hexadecimal digit may be uppercase or lowercase.