Currently Being Moderated
Welcome to the forum!
>
when we store value like
int i = 010;
it will display the output of i as 8.
Why is it so??
>
It isn't just 'stored' as an 8 it IS an 8. It is displayed as decimal so, as an 8 it displays as decimal 8.
Your question is really why is 010 stored as an 8. The answer to that can be found in The Java Language Specification
http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.10.1
Section 3.10.1 Integer Literals has your answer. You should read then entire section but this is the spec that applies
>
An octal numeral consists of an ASCII digit 0 followed by one or more of the ASCII digits 0 through 7 interspersed with underscores, and can represent a positive, zero, or negative integer.
OctalNumeral:
0 OctalDigits
0 Underscores OctalDigits
OctalDigits:
OctalDigit
OctalDigit OctalDigitsAndUnderscoresopt OctalDigit
OctalDigit: one of
0 1 2 3 4 5 6 7
OctalDigitsAndUnderscores:
OctalDigitOrUnderscore
OctalDigitsAndUnderscores OctalDigitOrUnderscore
OctalDigitOrUnderscore:
OctalDigit
_
Note that octal numerals always consist of two or more digits; 0 is always considered to be a decimal numeral - not that it matters much in practice, for the numerals 0, 00, and 0x0 all represent exactly the same integer value.
>
Then, as TPD showed, octal 010 is decimal 8.