In Java, the long data type stores integer on 64 bit while the integer data type stores integer on 32bit.
The primitive wrapper Long is a subclass of Number in java
Long is an integer that is encoded with 64 bit but you have also int on 32 bit.
Primitive Type | Primitive Wrapper | Stored in a word of | min | max |
---|---|---|---|---|
int | Integer | 32 bits | <math>-2^{31}</math>
-2,147,483,648 | <math>+2^{31}-1</math>
-2,147,483,647 |
long | Long | 64 bits | <math>-2^{63}</math>
-9,223,372,036,854,775,807 | <math>+2^{63-1}</math>
4.611.686.018.427.387.904 |
long = 1.073.741.824L;
long = (long)a;
Long i = theinteger.longValue()
Long i = Long.valueOf(3);
Number - (Arithmetical | Numerical | Mathematical) Operators on long
The operations are done in the largest data type required to handle all of the current values.
For the below mathematics Operations | The operation is a |
---|---|
int (operator) int | integer operation |
int (operator) long | long operation |
Example:
long i = (int)1 * (long)2
long i = (int)1 * (int)2
Long theLong;
Integer i = theLong.intValue()
Math.toIntExact(long)
new Long[]{long1, long2, ...};