Data Types - Java
- If Data Types are not Initialized then by default it will store a Null/Empty value
final dataType var = val
=> Initialize a Constant variable
- Types
- Primitive
- Byte
- Size = 1 byte
- Range = -128 to 127
byte var = 12
- Short
- Size = 2 byte
short var = 123
- Integer
- Size = 4 byte
int var = 1234
- Long
- Size = 8 byte
long var = 123456L
- Float
- Size = 4 byte
- Can store Decimal values
float var = 123.45F
- Double
- Character
- Size = 1 byte
- Can store Characters
char var = '@'
- Boolean
- Size = 1 byte
- true/false
boolean var = true
- Non-Primitive
- Wrapper Class => Provided by
java.lang
- Collections
- Casting
- Implicit
- Casting a Data Type with bigger size/container into a Data Type with smaller size
- Java does it automatically
- Explicit
- Data may get lost
(dataType)val
Integer.parseInt(val)
=> Convert into Integer
Float.parseFloat(val)
Double.parseDouble(val)
Long.parseLong(val)