Take the 2-minute tour ×

Possible Duplicate:
09 is not recognized where as 9 is recognized

Just wondering, when I declare the following:

public static final long __VERSIONCODE = 0L;
public static final long __VERSIONCODE = 9L;

that will work, but whenever I try this:

public static final long __VERSIONCODE = 09L;
public static final long __VERSIONCODE = 08235L;

i get an error (in eclipse): "The literal 09L of type long is out of range."

So i thought that was because it started with a zero.

but then I tried with the second digit lower as eight:

public static final long __VERSIONCODE = 07235L;

which gives me NO error.


public static final long __VERSIONCODE = 07239L;

gives me also an error too.

So I really don't get the point of which values I can assign to a long and which I can't. Why do I get this errors? (It's actually just that I'm curious, I can also just use a String for my version code). Thanks!

Also, i forgot to mention that this behaves exactly the same using doubles instead of longs.

share|improve this question
add comment

marked as duplicate by Steve Kuo, Xavi López, Neolisk, Draco Ater, Romain Francois Jan 28 '13 at 19:43


2 Answers

up vote 14 down vote accepted

When you put a 0 in front of an integer-type literal, it will interpret it as representing an octal number. Since "9" isn't a valid digit for octal numbers, that might be what's going on. Try printing out the (decimal) value of "010L" and see whether is says "8" to confirm.

Note: not sure if Java does this, or if this is purely an artifact of Eclipse. If the latter, printing out 010L would show 10. If the former, you'd see 8. If it's just an artifact of Eclipse, you can confirm by trying 01L, 02L, ..., 07L, which should all work, and 08L and 09L which would fail.

share|improve this answer
Most probably it will be that, thank you! –  Twinone Devs Jan 28 '13 at 16:57
+1 Nice Answer. –  Subhrajyoti Majumder Jan 28 '13 at 16:57
Especially 07235 < 7235. –  Joop Eggen Jan 28 '13 at 16:57
Yup, it sees it as Octal. So, 8 and 9 are not valid digits: stackoverflow.com/questions/7218760/… –  Darius X. Jan 28 '13 at 17:03
But somehow "X" must be less than 8, because when I write int value = 0X1234; the compiler takes it. (;)) –  Hot Licks Jan 28 '13 at 17:06
show 1 more comment

using leading zeroes for constants is indicating the octal notation, by which only digits 0..7 are allowed. so if you use leading zeroes for making number pretty print, that is a bad idea as the value it represents is different.

See http://docs.oracle.com/javase/specs/jls/se5.0/html/lexical.html#3.10.1 and watch out for "OctalNumeral".

share|improve this answer
add comment
