programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Java2 Sun Certified Programmer & Developer by Sierra and Bates

Greenhorn
Posts: 1
Hello all,

Java2 Sun Certified Programmer & Developer by Sierra and Bates (chpt1 p.13).
Describes an octal number can hold 21 digits (not including the leading zero).
And 16 for a hexdecimal number (not including the prefix 0x).

However my attempt at this in practice produced the following compilation error for an Octal literal:

public class IntlitOctalTest {
public static void main(String [] args){
int b = 0111111111111111111111; // IntLitTest.java:7: integer number too large

System.out.println("Octal Numbers: " + b);

And the following for a Hex:

public class IntlitTest {
public static void main(String [] args){

int b = 0x0123456789ABCDeF; //IntLitTest.java:7: integer number too large

System.out.println("Hex Numbers: " + b);

}
}

In light of this can someone explain what is meant by an octal literal having the ability to hold 21 digits, and 16 for a Hexdecimals?

Thank you,
Zee

author and iconoclast
Sheriff
Posts: 24217
38
Very long octal or hexidecimal constants, just like long decimal constants, won't fit in a 32-bit "int"; they can be held in a 64-bit "long", however. You have to append the letter "L" to the constant to make it a long value.

Try

long octal = 0123456789123456789123L;
[ May 07, 2007: Message edited by: Ernest Friedman-Hill ]

Wanderer
Sheriff
Posts: 18671
[EFH]: Try

long octal = 0123456789123456789123L;