Primitive Data Ranges and Support Classes
or when is a Long not a long and
a Float not a float.
www-stevemcgarry-com
 
The Java API has classes that support primitives. These classes have the same name or a very close name as the primitive data type names.
 
Primitive  Java API
Data Type  Primitive Support
Name       Classes
---------- -----------------
byte       Byte
short      Short
int        Integer
long       Long 
float      Float
double     Double
char       Character
boolean    Boolean
 
When not to use primitive support classes
We do not use the primitive support classes to represent one value, but we could. The reason is that they represent a lot of memory overhead for just representing a single primitive value. A primitive is much more efficient because it is one value plain and simple.
 
When to use primitive support classes
However, the primitive support classes provide methods and values useful for primitives. For example they provide the minimum and maximum values of a primitive.
 
Primitive dat types demonstrated
Here is a program from the Java web site you can use to see the maximum values for primitives. They use the MAX_VALUE field from the respective classes. As you can see the MAX_VALUE field is the correct primitive data type for each class such that we can assign it to a primitive variable.
 
Also demonstrated is the use of the char and boolean primitives.
 
public class MaxVariablesDemo {
    public static void main(String args[]) {
 
        // integers
        byte   largestByte    = Byte.MAX_VALUE;
        short  largestShort   = Short.MAX_VALUE;
        int    largestInteger = Integer.MAX_VALUE;
        long   largestLong    = Long.MAX_VALUE;
 
        // real numbers
        float  largestFloat   = Float.MAX_VALUE;
        double largestDouble = Double.MAX_VALUE;
 
        // other primitive types
        char    aChar         = 'S';
        boolean aBoolean      = true;
 
        // display them all
        System.out.println("The largest byte value is "    + largestByte);
        System.out.println("The largest short value is "   + largestShort);
        System.out.println("The largest integer value is " + largestInteger);
        System.out.println("The largest long value is "    + largestLong);
 
        System.out.println("The largest float value is "   + largestFloat);
        System.out.println("The largest double value is "  + largestDouble);
 
        if (Character.isUpperCase(aChar)) {
            System.out.println("The character " + aChar + " is upper case.");
        } else {
            System.out.println("The character " + aChar + " is lower case.");
        }
        System.out.println("The value of aBoolean is " + aBoolean);
    }
}
 
I recommend that you compile and run this yourself. Here is the output:
 
The largest byte value is 127
The largest short value is 32767
The largest integer value is 2147483647
The largest long value is 9223372036854775807
The largest float value is 3.4028235E38
The largest double value is 1.7976931348623157E308
The character S is upper case.
The value of aBoolean is true
 
The E in the results means scientific notation. If a positive number follows the E, you move the decimal that many places to the right. If a negative number follows the E, you move the decimal that many places to the left.
 
Try it on your own.
Can you modify this program to show the minimum values. Here is are some hints:
Byte.MIN_VALUE
Long.MIN_VALUE
Next week you learn to use the primitive support class methods that convert a String of numbers to a primitive. For example Long.parseLong() and Integer.parseInt().