java data type casting

View All Java Casting Operations

A) Introduction Data Type Casting (Type Conversion) byte TO short int long float double char boolean short TO byte int long float double char boolean int TO byte short long float double char boolean float TO byte short int long double char boolean double TO byte short int long float…

Do you want to know?

1. Rules of Access Specifiers in Method Overriding 2. Rules of Exceptions in Method Overriding 3. Java Casting Operations – Data type casting and Object casting 4. Getting objects of Abstract classes – Factory methods 5. Getting objects of Interfaces – Through Object Casting

byte to float Java

After knowing primitive data types and Java rules of Data Type Casting (Type Conversion), let us cast byte to float. The byte data type takes one byte of memory and float takes 4 bytes. Assigning 1 byte memory value to 4 bytes memory goes implicitly in Java. This is also…

long to short java

After knowing primitive data types and Java rules of Data Type Casting (Type Conversion), let us cast long to short as an example. The long takes 8 bytes of memory and short takes 2 bytes of memory. Assigning 8 bytes of memory to 2 bytes of memory requires explicit casting.…

short to float Java

After knowing primitive data types and Java rules of Data Type Casting (Type Conversion), let us cast short to float. The short takes 2 byte of memory and float takes 4 bytes of memory. Assignment 2 bytes of memory to 4 byte of memory is done implicitly by JVM. This…

float to long Java

After knowing Java rules of Data Type Casting (Type Conversion), let us cast float to long. By memory-wise, float takes 4 bytes of memory and long takes 8 bytes of memory. Even then, a float value cannot be assigned to a long (here, rules of casting do not work) as…

long to int Java

After knowing primitive data types and Java rules of Data Type Casting (Type Conversion), let us cast long to int. The long takes 8 bytes of memory and int take 4 bytes of memory. Assigning 8 bytes of memory to 4 bytes of memory requires explicit casting. byte –> short…