stcho
stcho

Reputation: 2159

Is 00 an integer or octal in Java?

Is

00, 000, or 000...

an integer in Java? Or is it an octal? If is it an octal is

001 or 0005

an octal?

Upvotes: 5

Views: 5266

Answers (3)

Christian Tapia
Christian Tapia

Reputation: 34186

All are integers, but...

1  is decimal
0  is decimal
01 is octal
00 is octal

From Java Language Specification (emphasis mine):

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.

Upvotes: 7

Suresh Atta
Suresh Atta

Reputation: 122026

Directly from specification

An octal numeral consists of an ASCII digit 0 followed by one or more of the ASCII digits 0 through 7 and can represent a positive, zero, or negative integer.

You can check 0 though 7

Upvotes: 1

Juvanis
Juvanis

Reputation: 25950

Number literal representation examples in Java will give you the answer:

int decimal = 100;
int octal = 0144;
int hex = 0x64;
int binary = 0b1100100;

So 00, 000 and 0000 are all octal(base-8) integers.

Upvotes: 4

Related Questions