Understanding Casting

In this section, we’ll learn how to convert a value from one type to another type.

There are times when you need to convert a value of one type to another. In such cases, you use type casting. Converting a value from one type to another type is known as type casting. For example, you can convert a decimal value to an integer value, or vice versa.

There are two types of casting in Java.

  • Implicit Casting
  • Explicit Casting

In some cases, values are automatically converted for you. Such conversions are known as implicit casting. In other cases, you have to convert the values. Such conversions are known as explicit casting.