Java Data Type Tutorial - Java short Data Type








The short data type is a 16-bit signed Java primitive integer data type. Its range is -32768 to 32767 (or -215 to 215 - 1).

There is no short literal. However, we can assign any int literal that falls in the range of short (-32768 to 32767) to a short variable.

For example,

short s1  = 11111;      // ok 
short s2  = -11111;   // ok

The value of a byte variable can be assigned to a short variable because the range of the byte data type falls within the range of the short data type.

Java has a class called Short, which defines two constants to represent maximum and minimum values of short data type, Short.MAX_VALUE and Short.MIN_VALUE.

short max = Short.MAX_VALUE;
short min = Short.MIN_VALUE;