Long is the Object form of long, and Integer is the object form of int.
Integer is a signed 32 bit integer type
- Denoted as Int
- Size = 32 bits (4byte)
- Can hold integers of range -2,147,483,648 to 2,147,483,647
- default value is 0
Long is a signed 64 bit integer type
- Denoted as Long
- Size = 64 bits (8byte)
- Can hold integers of range -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
- default value is 0L
- By default use an int, when holding numbers.
- If the range of int is too small, use a long
- If the range of long is too small, use BigInteger
- If you need to handle your numbers as object (for example when putting them into a Collection, handling null, …) use Integer/Long instead