An Example to Learn Java short Data Type

The short data type

Java has eight types of primitive data types to store data in the Java programs. The Java short is one of the primitive data types in Java.

The short data type of Java:

  • Takes two bytes OR 16 bits of memory.
  • Is a numeric type.
  • The default value of the short variable is 0.
  • The minimum value of the short type can be –32768.
  • The maximum value of the short type can be 32767.

An example of the short data type

In the following example, we will declare two short Java data type variables. The first short variable is declared and no value is assigned at the time of declaration.

The value is assigned to the other short variable at the time of declaration. In the last line, we printed the second variable by using the System.out.println statement.

See this example online

As you run the code, the output will be:

-1000

Note: The short variable takes half of the memory than the int type variable.