All Courses
Type Conversion and Casting

Type Conversion and Casting in Java

April 30th, 2019 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:

  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;

Social Share:

0 responses on "Type Conversion and Casting in Java"

Leave a Message

Your email address will not be published. Required fields are marked *