Find out the min value, max value and size of Short types

Short class defines the following constants to hold the maximum value, minimum value and size.

static short MAX_VALUE
A constant holding the maximum value a short can have, 215-1.
static short MIN_VALUE
A constant holding the minimum value a short can have, -215.
static int SIZE
The number of bits used to represent a short value in two's complement binary form.
static Class TYPE
The Class instance representing the primitive type short.

public class Main {

  public static void main(String args[]) {
    System.out.println("Max value from Short class:"+Short.MAX_VALUE);
    System.out.println("Min value from Short class:"+Short.MIN_VALUE);
  }
}

The output:


Max value from Short class:32767
Min value from Short class:-32768

To get the size of a short value, just call its static constant SIZE as the follows:


public class Main {

  public static void main(String args[]) {
    System.out.println("Size of a Short:"+Short.SIZE);
  }
}

The code above outputs:


Size of a Short:16
Home 
  Java Book 
    Essential Classes  

Short:
  1. Short class
  2. Find out the min value, max value and size of Short types
  3. Create Short object with its constructor
  4. Convert Short to byte, double, float, int, long and short
  5. Decode a string to short value
  6. Convert string to a short value
  7. Reverse the bytes in a short
  8. Convert short value to string
  9. Compare two short values