
Type Conversion and Casting in Java
Type Conversion and Casting in Java
Converting a value from one data type to another data type is called type conversion.
There are two types of type conversion available:
- Implicit conversion it is also known as automatic conversion
- Explicit conversion it is also known as type casting
Implicit Conversion are performed automatically by Java for performance reasons.
Example:
int noOne = 4; double noTwo; double Res = noOne / noTwo; //Here noOne is also converted to double |
Casting will be performed by developer manually. In some case, if we want to convert a value which having a type of size less than the destination type size.
Example:
int aVal = 10; byte bVal = (int) aVal; |