Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Literals:
- • int x = 10;
- § Int is both the datatype and keyword.
- § X is the name of the variable or the identifier.
- § 10 is considered the constant value or the literal.
- □ Note: A constant value which can be assigned to a variable is called a literal.
- • There are four integral data types.
- § List: byte, short, int, and long
- • There are two forms of literal representation. These are decimal and octal.
- § Decimal literals (base-10)
- □ Range: 0 to 9
- □ Int x = 10; <-- decimal form
- § Octal literals (base-8) can handle
- □ Range: [0 to 7]
- □ int x = 010;
- □ Side note:
- □ The JVM reads literals by default in decimal form.
- □ One can force a literal to be treated as an octal literal by prefixing the literal with the number 0.
- § Hexadecimal form (base-16)
- □ Range: [0 to 9] and [a to f] -
- □ We can use both lowercase and uppercase characters.
- ◊ IMPORTANT: This is one of very few areas where java is not case sensitive.
- □ Int x = 0x10;
- □ Side note:
- □ The JVM reads literals by default in decimal form.
- □ Once can force a literal to be treated as a hexadecimal literal by prefixing it with 0X (the x can be lowercase or uppercase).
- § Examples: int x = 10; <-- valid || int x = 0786; <-- CE: integer number too large || int x = 0777; <-- valid || int x = 0XFace; <-- valid || int x = 0XBeef; <-- valid || int x = 0XBeer; <-- CE: error: ';' expected
- § Detailed Example 1: class test { public static void main(String[] args) { int x = 10; int y = 010; int z = 0X10; System.out.print(z + "..." + y + "…" + z); } } //prints 10 8 16 in this order
- § NOTE: JVM only prints values in decimal form.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement