Java Data Types
Java is case sensitive so upper and lower case characters are important.
Java has many data types built into it, and you (as a programmer) can create as many more as you want. However, all data in Java falls into one of two categories: primitive data and objects. There are only the eight primitive data types (see chart below). The only type of data a programmer can define/create/invent is an object data type (a class). A (crude) analogy is that a primitive data value is like a nut or a bolt, but an object is like a whole machine.
There are types of data that are so fundamental that ways to represent them are built into Java. These are the primitive data types. In the phrase primitive data type the word primitive means "a fundamental piece that is used to create other, larger parts." To solve a large problem, you look for the primitive operations that are needed, then use them to build the solution.
The eight primitive data types are:
|
Numeric - Integer Primitive Data Types
Integers (whole numbers) have no fractional part, no decimal points and no commas
both positive and negative, zero is a positive number |
| | typeName | Size | Range | |
| 1 | byte | 8 bits | -128 to +127 -27 ... 27-1 | |
| 2 | short | 16 bits | -32,768 to +32,767 -215 ... 215-1 | |
| 3 | int | 32 bits | -2 billion to +2 billion -231 ... 231-1 | Usually you should use int or double for your numeric data. Without any letter at the end, a 32 bit int literal will be assumed. |
| 4 | long | 64 bits | -10E18 to +10E18 -263 ... 263-1 | A 64 bit long literal has a upper case 'L' at the end. Don't use lower case 'l', it can be confused with numeric '1'. |
Numeric - Floating Point Primitive Data Types
floating point types have a fractional part, a decimal point and no commas both positive and negative |
| 5 | float | 32 bits | -3.4E+38 to +3.4E+38 | A 32 bit float has a lower case 'f' or upper case 'F' at the end. float is sometimes called "single-precision floating point", it should be used only for special circumstances. It has about 7 significant decimal digits. |
| 6 | double | 64 bits | -1.7E+308 to 1.7E+308 | To explicitly ask for a double-precision double literal by putting a lower case 'd' or upper case 'D' at the end. Without any letter at the end, a floating point literal will automatically be of type double. double is sometimes called "double-precision floating point". It has about 15 significant decimal digits. |
| Non-Numeric - Primitive Data Types |
| 7 | char | 16 bits | | char represents a SINGLE character, from human languages more than just English. The method used is called Unicode. Upper and lower case characters are represented by different patterns. As are punctuation and special characters, like the "space" character that separates words. Control characters are bit patterns that show the end of a line or where to start pages. Other control characters represent the mechanical activities of old communications equipment (such as teletypes) that are rarely used, but need to be kept.
|
| 8 | boolean | 1 bit | true -or- false | In a Java program, the words true and false always mean these boolean values. Often used to make comparisons between numbers. |
"E" means "times 10 to the power of" for scientific notation (1.23E+02 or 3.81E-06)
The "E" says in which direction and for how many places to shift the decimal point. Positive integers mean right shifts; negative integers mean left shifts. |
|
For each primitive data type, there is a corresponding wrapper class. A wrapper class can be used to convert a primitive data value into an object, and some type of objects into primitive data. To convert to a corresponding wrapper class, merely capitalize the name of the primitive data type such as "byte" to "Byte".
|
| Non - Primitive Data... "Objects" |
| typeName | Size | Range | |
| InputStreamReader | | | a class that is part of the java.io package |
| String | | | a class that is defined in Java |
|
See
Java Links for more info,
Object & Classes ,
Data Types ,
Operators ,
Conditionals ,
Definitions ,
Keywords ,
File Structure ,
Code Examples ,
Class Skeleton ,
Java Notes
Return to Top of Page
