There are two main categories of variables: primitive types and objects. We’re going to wait on discussing exactly what objects are. For now, think of them as more complicated, customizable variables with special features. There are exactly eight primitive types.
Name Description Size
byte Stores very small integers 8 bit
short Stores small integers 16 bit
int Stores normal integers 32 bit
long Stores big integers 64 bit
float Stores less precise decimal values 32 bit
double Stores more precise decimal values 64 bit
boolean Stores a true or false value 1 bit*
char Stores a single character 16 bit
In this course, you’ll be using the following types most commonly:
An int can store any integer value between -231 and 231 -1
A double can store non-integer values with up to 15 decimal places of precision.
A boolean can hold two values: true or false.
A char stores a single character like ‘a’, ‘Z’, or ‘$.’
double tacoPrice = 1.95;
int numTacos = 3;
char firstLetter = ‘t’;
boolean isHungry = true;
*A boolean actually takes up one byte of memory in Java, despite only representing 1 bit of memory. This is because memory is addressed in 1-byte chunks.