5/31/2021 Type Casting in Java - Javatpoint
Type Casting in Java
In Java, type casting is a method or process that converts a data type into another data type in
both ways manually and automatically. The automatic conversion is done by the compiler and
manual conversion performed by the programmer. In this section, we will discuss type casting
and its types with proper examples.
Type casting
Convert a value from one data type to another data type is known as type casting.
Types of Type Casting
There are two types of type casting:
Widening Type Casting
Narrowing Type Casting
Widening Type Casting
Converting a lower data type into a higher one is called widening type casting. It is also known
as implicit conversion or casting down. It is done automatically. It is safe because there is no
chance to lose data. It takes place when:
Both data types must be compatible with each other.
The target type must be larger than the source type.
byte -> short -> char -> int -> long -> float -> double
⇧
https://www.javatpoint.com/type-casting-in-java 2/8
Type Casting in Java
In Java, type casting is a method or process that converts a data type into another data type in
both ways manually and automatically. The automatic conversion is done by the compiler and
manual conversion performed by the programmer. In this section, we will discuss type casting
and its types with proper examples.
Type casting
Convert a value from one data type to another data type is known as type casting.
Types of Type Casting
There are two types of type casting:
Widening Type Casting
Narrowing Type Casting
Widening Type Casting
Converting a lower data type into a higher one is called widening type casting. It is also known
as implicit conversion or casting down. It is done automatically. It is safe because there is no
chance to lose data. It takes place when:
Both data types must be compatible with each other.
The target type must be larger than the source type.
byte -> short -> char -> int -> long -> float -> double
⇧
https://www.javatpoint.com/type-casting-in-java 2/8