| We provide some additional information here about integers, as 
              well as stressing again some points made previously. This continues 
              the discussion of integers in Chapter 
              2: Java : Primitive data types Java offers 5 types of integer:  
              byte 
                - 8-bit, signedshort 
                - 16-bit, signedint 
                - 32-bit, signedlong 
                - 64-bit, signedchar 
                - 16-bit, can be treated as unsigned integer in some situations The table 
              showed the ranges of values of each type. The pages Chapter 
              2: Java : Casting & Mixing and Chapter 
              2: Tech : More Casting & Mixing discuss how the types can 
              be converted from one to another. Here are some other aspects of using integers: 
              No overflow and underflow warnings 
                - unlike the case for the floating point types, there are no special 
                values for the integer types that indicate that the maximum 
                value has been exceeded or that a value has gone below the negative 
                minimum values. Exceeding the maximum value will flip the value 
                into the negative range while continuing past the minimum negative 
                value will flip the value into the positive range.
 
Maximum and minimum values constants 
                - the wrapper 
                classes (to be discussed later) 
                provide constants that give the maximum and minimum values for 
                each type. These can can be useful for testing for overflows/underflows 
                since, as discussed above, no exceptions are thrown in such cases.
 
 
                  byte 
                     
                    
                      Byte.MIN_VALUE 
                         -27 
                        = -128Byte.MAX_VALUE 
                         27-1 
                        = 127short 
                     
                    
                      short.MIN_VALUE 
                         -215 
                        = -32768Short.MAX_VALUE 
                         215-1 
                        = 32767int 
                    
                      Integer.MIN_VALUE 
                         -231 
                        = -2147483648Integer.MAX_VALUE 
                         231-1 
                        = 2147483647long 
                    
                      Long.MIN_VALUE  
                        -263 
                        = -9223372036854775808lLong.MAX_VALUE 
                         263-1 
                        = 9223372036854775807l
 
Divide by zero errors - 
                unlike the floating point types ( float 
                and double), 
                integer divide by zero leads to a run time exception 
                that will stop the processing unless caught as discussed later.   References & Web Resources   Latest update: Oct. 15, 2004 |