Primitive types
| Name | Bytes | Type | Range | Literal samples |
|---|---|---|---|---|
byte |
1 | Signed integer | No byte
literal in Java™ |
|
short |
2 | Signed integer | No short
literal in Java™ |
|
int |
4 | Signed integer |
|
|
long |
8 | Signed integer |
|
| Literal | Discriminator | Type | Value |
|---|---|---|---|
| 29 |
base 10 |
Decimal | |
| 0b11101 | 0b, base 2 | Binary |
|
| 0x1D | 0x, base 16 | Hexadecimal | |
| 035 | 0, base 8 | Octal |
| Name | Bytes | Type | Range | Literal representation samples |
|---|---|---|---|---|
char |
2 | Unsigned integer |
|
|
float |
4 | Floating point | to |
|
double |
8 | Floating point | to |
|
boolean |
? | Logical value | not applicable | true,
false |
No. 6
Literal samples
|
Q: |
Create code printing an example for each type of literal in all its different representations.
Assign each literal sample to a variable of corresponding type. Your code may read: Due to the above table's combinations your code will have 2 x 4 + 1 x 2 + 2 x 2 + 1 x 1 + 1 x 2 = 17 variable declarations. Tip
|
||||||||||||
|
A: |
|
No. 7
Literals of type int
|
Q: |
Both
|
||||||||||||||||||||
|
A: |
|
No. 8
Integer overflow
|
Q: |
Try executing: Whats wrong here? How can we achieve the desired output? TipConsider |
|
A: |
The code snippet fails with an »Integer number too large« error. In Java™ 3123424234 claims to be a
literal of type System.out.println(3123424234L); |
No. 9
Strange sum result
|
Q: |
Execute the following code:
|
||||
|
A: |
|
