Home

Casting in java | Java Type Cast Tutorial for beginners

Casting in java: introduction

This tutorial deals with casting in java . If you don’t know how to use java variables, please check our corresponding java variables tutorial.
Casting in java is tightly related to assignement compatibility. So, we will deal with the assignment compatibility in depth in this tutorial before moving to java casting.

2808315407

Assignment types in java

Assignment compatibility = what types can be assigned to other types.

Widening assignment in JAVA:

it deals with numeric types: assigning lower range type to a larger range type.

Obviously we can assign an expression of a type to an lvalue expression of the same type.

A type of a larger range can contain the range of values that can represent a narrow type.

byte < short < (char)< int < long < float < double

The byte, long, float and double are signed.

The char type is unsigned. We cannot assign a byte or a short to a char and vice versa.

You may check the full casting in java tutorial to get more details about this subject.

There are others core java tutorials in that website that are very interesting.

Tags: