Short min/max value and size
In this chapter you will learn:
min value, max value and size of Short types
Short class defines the three constants to hold the maximum value, minimum value and size.
static short MAX_VALUE
is a constant holding the maximum value a short can have, 215-1.static short MIN_VALUE
is a constant holding the minimum value a short can have, -215.static int SIZE
stores the number of bits used to represent a short value in two's complement binary form.
The code below checks the min and max value for short
type.
public class Main {
/*j a v a 2 s .c o m*/
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:
To get the size of a short value, just call its static constant SIZE
as the follows:
public class Main {
//ja v a 2s .co m
public static void main(String args[]) {
System.out.println("Size of a Short:"+Short.SIZE);
}
}
The code above outputs:
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » Primitive Data Types