Special Offer - Enroll Now and Get 2 Course at ₹25000/- Only Explore Now!

All Courses
Type Conversion and Casting in Java

Type Conversion and Casting in Java

April 30th, 2019

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:

  1. Implicit conversion it is also known as automatic conversion
  2. 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;