header

Primitive Data Types

Numeric

Numeric data types are used to store numbers. There are four primitive data types that store integer values:

Type Size (in bytes) Minimum Maximum
byte 1 -128 127
short 2 -32,768 32,767
int 4 -2,147,483,648 2,147,483,647
long 8 -9,223,372,036,854,775,808 9,223,372,036,854,775,807

There are two primitive data types that store decimal values (numbers with a fraction part):

Type Size (in bytes) Precision (Decimal Digits)
float 4 Single (about 6)
double 8 Double (about 15)

Character

Character data consists of letters, numerals, punctuation, and some additional characters (such as tab, form feed, new line, and carriage return). There are two character data types:

Type Description
char A primitive data type. Stores a single character.
String A class. Stores a sequence of characters.

While the string data type is included on this page, it is actually far from primitive. The String class has many very useful methods that allow us to manipulate strings of text. It is a primitive data type in the sense that it is already part of the Java language rather than a data structure that we have to devise ourselves.

Logical

The logical data type is named boolean and a logical variable stores the value true or false.

Links to additional information

See also: Programming Overview, Data Declarations

Java Tutorial: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html