CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ

Data

Data
Basic skills
Primitive data types

The eight primitive data types

Type Bytes Use
byte 1 Very short integers from -128 to 127.
short 2 Short integers from -32,768 to 32,767.
int 4 Integers from -2,147,483,648 to 2,147,483,647.
long 8 Long integers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
float 4 Single-precision, floating-point numbers from -3.4E38 to 3.4E38 with up to 7 significant digits.
double 8 Double-precision, floating-point numbers from -1.7E308 to 1.7E308 with up to 16 significant digits.
char 2 A single Unicode character that's stored in two bytes.
boolean 1 A true or false value.

An overview of the eight primitive data types

  • A bit is a binary digit that can have a value of one or zero. A byte is a group of 8 bits.
  • Integers are whole numbers.
  • Floating-point numbers provide for very large and very small numbers that require decimal positions, but with a limited number of significant digits.
  • A single-precision number provides for numbers with up to 7 significant digits. A double-precision number provides for numbers with up to 16 significant digits.
  • The Unicode character set provides for over 65,000 characters with two bytes used for each character.
  • The older ASCII character set provides for 256 characters with one byte used for each character.
  • A boolean data type holds a true or false value.
Previous | Primitive data types | Variables | Constants | Assignment statements and arithmetic expressions | Order of preference | Casting | Next