-
Notifications
You must be signed in to change notification settings - Fork 0
primitives
Keyhan Hadjari edited this page Sep 7, 2016
·
4 revisions
- The range of short primitive type is -32768 to 32767.
- Java does not allow casts between boolean values and any numeric types.
- Assigning double to a float requires an explicit cast.
- The width in bits of float primitive type in Java is 32.
- byte 8 bits, short 16 bits, int 32 bits, float 32 bits, long 64 bits, double 64 bits
- 2.23 is double
- 2.23f is float
- byte range is from -128 to 127
- Setting a value to a long for numbers exceeding int limit is like this (L suffix):
- long foo = 3333333333L;
- Use '0' prefix for octal digits, for example 010 = 8
- Use '0X' or '0x' prefix for hexadecimal digits, for example 0x10 = 16
- Use '0B' or '0b' prefix for binary digits, for example 0b10 = 2
- From Java 7, you can have underscores to make digits easy to read for example "int a =1_000_000" or "float b=12_544.10", for float and double the "_" should not be around or after "." sign.
- In Java there is no connection between false and 0 or true and 1
| Keyword | Type | Example |
|---|---|---|
| boolean | true or false | true |
| byte | 8-bit integral value | 123 |
| short | 16-bit integral | 123 |
| int | 32-bit integral | 123 |
| long | 64-bit integral | 123 |
| float | 32-bit floating-point value | 123.45f |
| double | 64-bit floating-point value | 123.45 |
| char | 16-bit Unicode value | 'a' |