As mentioned above, 010 is a Octal integer literal . A leading 0 indicates that it is an octal representation. Actual value will be:
1 * 8 ^ 1 + 0 * 8 ^ 0 = 8 (decimal) = 1000 (only the last 4 digits)
Now back to SOP:
System.out.println(010|4);
Using bitwise OR on 010 and 4 (taking into account only the last 4 digits) =>
1000 | 0100
= 1100
= 1 * 2 ^ 3 + 1 * 2 ^ 2 + 0 * 2 ^ 1 + 0 * 2 ^ 0
= 8 + 4 + 0 + 0
= 12 (decimal)
source share