short to double Java

short to double Java

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

The short takes 2 byte of memory and double takes 8 bytes of memory. Assignment 2 bytes of memory to 8 byte of memory is done by JVM implicitly and is known as widening conversion.

See the data types order to know the brief rules of casting.

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

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

Examples of implicit casting

short x = 10;
int y = x;

byte x = 10;
short y = x;

Following program on short to double explains the Java syntax of implict casting where a short value is assigned to a double value.

short to double
Output screenshot of short to double Java

double d1 = s1;

The short s1 is assigned to double d1. This is done automatically by JVM.

View all for 65 types of Conversions

Leave a Reply

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