Java Keyword Short

The reserved keyword short is used to define a variable as a numeric data type. The short data type is a 16 bit signed two’s complement integer. It has a minimum value of -32,768 (negative) and a maximum value of 32,767 (positive).

Let’s define a short variable and initialize it with a value. If you need to hold a numeric value greater than 32767, you will need to use an int instead.

//JavaCodeDepot Sample 

short jcdShort = 23500;


You can also use the short keyword when you define a function or method that returns a short data type.

//JavaCodeDepot.com Sample

public short javaCodeDepotRetShort() {

    short jcdShort = 27777;

    //Do some awesome actions....
    
    return jcdShort;

}


The short is one of the eight primitive data types defined by Java.

The complete list of Java reserved keywords contains a total of 50 keywords and 3 literal words that are unable to be used as variable names.

Add a Comment

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