byte to long Java

byte to long Java

After knowing primitive data types and Java rules of Data Type Casting (Type Conversion), let us cast byte to long as an example.

The byte takes 1 byte of memory and long takes 8 bytes of memory. Assignment 1 byte value to 8 bytes is done implicitly by the JVM.

byte –> short –> int –> long –> float –> double

The left-side value can be assigned to any right-side value and is done implicitly. The reverse requires explicit casting.

Examples:

Following program on byte to long Java explains implicit casting. Observe, the Java syntax.


byte to long
Output screenshot of byte to long Java

1 byte value b1 is assigned to 8 bytes l1 and is type casted implicitly. This is known as widening conversion where automatic promotion takes place. This conversion does not need any extra overhead to JVM. It is so simple where a smaller bottle water is poured in a bigger bottle.

View all for 65 types of Conversions

Leave a Reply

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