Integer Literas

An Integer literal can be expressed in decimal (base 10) or hexadecimal (base 16):


IntegerLiteral:
	DecimalIntegerLiteral
	HexIntegerLiteral			

DecimalIntegerLiteral:
	DecimalNumeral IntegerTypeSuffixopt

HexIntegerLiteral:
	HexNumeral IntegerTypeSuffixopt

IntegerTypeSuffix: one of
	i I l L ib IB

An Integer literal is of type BigInteger if it is suffixed with the ASCII letters IB or ib, long if it is suffixed with an ASCII letter L or l (ell); otherwise it is of type int. The suffix L is preferred, because the letter l (ell) is often hard to distinguish from the digit 1 (one).

A decimal numeral is either the single ASCII character 0, representing the Integer zero, or consists of an ASCII digit from 1 to 9, optionally followed by one or more ASCII digits from 0 to 9, representing a positive Integer:


DecimalNumeral:
	0
	NonZeroDigit Digitsopt

Digits:
	Digit
	Digits Digit

Digit:
	0
	NonZeroDigit

NonZeroDigit: one of
	1 2 3 4 5 6 7 8 9

A hexadecimal numeral consists of the leading ASCII characters 0x or 0X followed by one or more ASCII hexadecimal digits and can represent a positive, zero, or negative Integer. Hexadecimal digits with values 10 through 15 are represented by the ASCII letters a through f or A through F, respectively; each letter used as a hexadecimal digit may be uppercase or lowercase.


HexNumeral:
	0 x HexDigits
	0 X HexDigits

HexDigits:
	HexDigit
	HexDigit HexDigits

HexDigit: one of
	0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F
The largest decimal literal of type int is 2147483648 (
231). All decimal literals from 0 to 2147483647 may appear anywhere an int literal may appear, but the literal 2147483648
may appear only as the operand of the unary negation operator -.
The largest positive hexadecimal literal of type int is 0x7fffffff, respectively, which equals 2147483647 (231-1). The most negative hexadecimal literal of type int is 0x80000000 which represents the decimal value
-2147483648 (-231). The hexadecimal literal 0xffffffff
represents the decimal value -1.
If a decimal literal of type int is larger than
2147483648 (231), or if the literal2147483648 appears anywhere other than as the operand of the unary - operator, or if a hexadecimal int literal does not fit in 32 bits, the value is represented as a decimal literal of type long
.

Example int Literals:

0	2i	0372	0xDadaCafe		1996I	0x00FF00FF
The largest decimal literal of type long is 9223372036854775808L (
2
63). All decimal literals from
0L to 9223372036854775807L may appear anywhere a long literal may appear, but the literal 9223372036854775808L
may appear only as the operand of the unary negation operator -.
The largest positive hexadecimal literal of type long is 0x7fffffffffffffffL, which equals
9223372036854775807L(2
63
-1). The literal 0x8000000000000000L is the most negative long hexadecimal literal which has the decimal value -9223372036854775808L (-2
63). The hexadecimal literal
0xffffffffffffffffL, represents the decimal value -1L
.
If a decimal literal of type long is larger than 9223372036854775808L (
2
63), or if the literal
9223372036854775808L
appears anywhere other than as the operand of the unary - operator, or if a hexadecimal or octal long literal does not fit in 64 bits, the value is represented as a decimal literal of type BigInteger.

Example Long Literals:

0l	0777L	0x100000000L		2147483648L		   0xC0B0L

Literals of type BigInteger have no maximum and minimum. Any value can be represented using the BigInteger type.

Example BigInteger literals:

0ib	0777IB	0x100000000000000000000IB				21474836482147483648IB

Each int, long, and BigInteger literal is a reference to an instance of class Integer, Long and BigInteger respectively. These objects have a constant value. The Integer and Long objects can be used interchangeably with their counter part Java primitive data types when calling methods that expect the primitive types or when accessing Java attributes declared using the Java primitive data type.