I am not able to understand the why such output when long variable with leading zero.
public class Test{
public static void main(String[] args) {
long var1=00123l;
long var2=123l;
System.out.println("Variable 1--->"+var1);
System.out.println("Variable 2--->"+var2);
System.out.println(var1==var2);
}
}
output:
Variable 1--->83
Variable 2--->123
false
The leading zero turns
00123linto an octal literal, and 1238=8310.From the JLS:
When you print the value, it gets printed in base-10, so you see
83.