Primitive types |
| BASIC |
There are eight primitive types in Java. These are the fundamental "atoms" from which all other types are constructed.
Type What it means Example literals Range Comments byteAn eight-bit integer -5,0,5-128 to 127 Seldom used shortA two-byte integer -5,0,5,200-32768 to 32767 Seldom used intA four-byte integer -5,0,5,200,50000Negative to positive two billion Typically used for integers longAn eight-byte integer -5L,0L,5L,999999999999L-9 * 1018 to 9*1018 Used only when very large integers are needed charA single character (usually two bytes)
'a','A','5','+',' ','\n','\'','\\'Most of the world's characters, including Chinese, Arabic, etc. Can be treated as integers; some characters cannot be typed as single characters floatA four-byte decimal number 5.23F,-123.45678F1.4*10-45 to 3.4*1038 Seldom used doubleAn eight-byte decimal number 5.23,-123.456784.9*10-324 to 1.8*10308 Typically used for decimal ("floating point") numbers booleanA logical value (one byte long) true,falseOnly the two values trueandfalseUsed mostly for remembering the results of tests
In addition, Java defines literally thousands of object types (which you can explore at http://java.sun.com/j2se/1.5.0/docs/api/index.html), and every program you write has additional programmer-defined object types of its own.
| INTERMEDIATE |
Any primitive type (except boolean) can be cast to any other primitive type
(except boolean).