Home > Articles

  • Print
  • + Share This

Integer Literals

Integer literals are used to represent specific integer values. Because integers can be expressed as decimal (base 10), octal (base 8), or hexadecimal (base 16) numbers in Java, each representation has its own form of literal. In addition, integer literals can also be expressed with an uppercase L ('L') or lowercase L ('l') at the end to instruct the compiler to treat the number as a long (64-bit) integer.

As with C and C++, Java identifies any number that begins with a non-zero digit and does not contain a decimal point as a decimal integer literal (for example, any number between 1 and 9). To specify an octal literal, you must precede the number with a leading 0 (for example, 045 is the octal representation of 37 decimal). As with any octal representation, these literals can only contain the numerals 0 through 7. Hexadecimal integer literals are known by their distinctive 'zero-X' at the beginning of the token.

Note - Tokens are the identifiers, keywords, literals, separators, and operators of Java. In short, they are every element of your source code other than whitespace and comments, which are described later in this chapter. Of the token types, only the separators have not been introduced. As the name implies, these tokens serve the purpose of separating other elements of your code. The separators consist of

( ) { } [ ] ; , .

Hex numbers are composed of the numerals 0 through 9 plus the Latin letters A through F (case is not important).

The following shows the largest and smallest values for integer literals in each of the three supported formats:

Largest 32-bit integer literal






Most negative 32-bit integer literal






Largest 64-bit integer literal






Most negative 64-bit integer literal






Caution - Attempts to represent integers outside the range shown in this table using literals result in compile-time errors.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.