Skip to main content
The short data type in Java is a 16-bit signed two’s complement integer primitive. It occupies 2 bytes of memory and provides a numerically constrained alternative to the standard 32-bit int primitive.

Technical Specifications

  • Size: 16 bits (2 bytes)
  • Minimum Value: -32,768 (215-2^{15})
  • Maximum Value: 32,767 (21512^{15} - 1)
  • Default Value: 0 (when declared as a class or instance variable)
  • Wrapper Class: java.lang.Short

Syntax and Initialization

Integer literals in Java are of type int by default. The Java compiler performs implicit narrowing conversion from an int literal to a short variable, provided the literal is a compile-time constant and falls within the valid 16-bit range.

Type Promotion and Arithmetic

A critical language mechanic regarding short is numeric promotion. When applying arithmetic operators (+, -, *, /, %) or bitwise operators to short variables, the Java Virtual Machine (JVM) automatically promotes the operands to int before evaluating the expression. Consequently, the result of the operation is an int, requiring an explicit downcast to assign it back to a short variable.
Compound assignment operators (e.g., +=, -=) handle this casting implicitly:

Casting Rules

  • Widening (Implicit): A short can be implicitly cast to a larger or floating-point primitive (int, long, float, double) without data loss.
  • Narrowing (Explicit): Casting a larger primitive down to a short requires an explicit cast. If the value exceeds the 16-bit capacity, the higher-order bits are discarded, resulting in a truncated, potentially altered value (underflow/overflow).
Tired of Poor Java Skills? Fix That With Deep Grasping!Learn More