10

I am using quartz for schedulling.

TriggerUtils.getDateOf(0,40,18,09,06);

it accept 5 parameter. (seconds, minutes, hours, daysOfMonth, month).

When i pass fourth parameter as "09". Eclipse give me error "The literal Octal 09 (digit 9) of type int is out of range ".

But when i pass the fourth parameter as "9" instead of "09", it works.

Can anyone explain me this error?

Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
Shashi
  • 12,487
  • 17
  • 65
  • 111
  • 1
    You realize that the integers 06 and 6 are the same thing, right? – matt b Jun 09 '09 at 13:24
  • 4
    @matt: He's passing a date into the function, and not realizing that a preceding 0 turns it to an octal number. – Eric Jun 09 '09 at 13:25
  • if i can pass 25, then why not 09. – Shashi Jun 09 '09 at 13:32
  • I think we've all been bitten by that one once or twice. I think in 30 years of programming I've intentionally used octal once (and binary and hexadecimal countless times). Octal's favored states is truly a throwback. – Nosredna Jun 09 '09 at 13:33
  • 2
    @Shashi: 25 is a number. 0 before a number signals that you want to use octal, so you're going into a different numbering system. Only applies to 0 because you normally drop the 0. – Will Eddins Jun 09 '09 at 13:37

5 Answers5

34

In java, if you are defining an integer, a leading '0' will denote that you are defining a number in octal

int i = 07; //integer defined as octal
int i = 7; // integer defined as base 10
int i = 0x07; // integer defined as hex
int i = 0b0111; // integer defined as binary (Java 7+)
James Van Huis
  • 5,481
  • 1
  • 26
  • 25
20

There is no 9 in Octal (what you get with a preceding 0). 0-7, only.

Eric
  • 92,005
  • 12
  • 114
  • 115
13

When you precede a number with 0 ("09" rather than "9"), then Java (and C and many other languages) interpret the number to be in octal - base-8.

"09" is not a valid number in octal - any single digit can be a maximum of "7" (since in octal, numbers go from 0..7).

poundifdef
  • 18,726
  • 23
  • 95
  • 134
11

Numbers that begin with the zero digit are treated as octal (base 8) literals, and 9 is not a valid octal digit.

3

10 is how many digits you have, whereas 010 is is what you get if you don't count your thumbs.

JustJeff
  • 12,640
  • 5
  • 49
  • 63