Data Types
In this lesson, we will discuss primitive data types in Java.
Numeric data types
This classification contains all data types that are numeric.
Did you know?
Variable Types are more often referred to as “Data Types”.
Integer
An integer is a whole number; that is, it does not have any decimal places. Examples of an integer include 4, 5, 2000, whereas numbers that are not integers include 4.3, 4.55.
Within integers, there are different data types that are based on the space they take within memory. The types include short
, int
, and long
.
// A short type is a 16 bit signed integershort age; // Stores from +32,767 to -32,768// An int type is a 32 bit signed integerint age; // Stores from +2,147,483,647 to -2,147,483,648// A long type is a 64 bit signed integerlong age; // Stores from +9,223,372,036,854,775,807 to -9,223,372,036,854,775,808
Note: Data types in Java are all signed. This means that they can store positive as well as negative values of integers.
Floating points
This data type stores numbers that ...