Literals: Assigning Values

When you learned about assigning a literal value to a boolean variable, there were only two possibilities: the reserved words true and false. For integers, the values are nearly endless. In addition, there are many ways an integer value can be represented using literals.

The easiest way to assign a value to an integer value is by specifying a traditional numeral:

int j = 3;

However, what happens when you want to assign a number that is represented in a different form, such as hexadecimal? To tell the computer that you are giving it a hexadecimal number, you need to use a hexadecimal integer literal. For a number such as 3, this doesn't make much difference—the value is the same in decimal as it is in hexadecimal—but ...

Get Special Edition Using Java 2 Standard Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.