Variables are a fundamental part of any programming language, including Java. Variables are used to store pieces of data and give them a name. When we want to use these variables in some way, we can refer to them by their name.
Primitive Variable Types
Let's explore the primitive types of data that variables can hold.
String: a string of characters, also known as text
byte: a number between -128 and 127
short: a number between -32,768 and 32,767
int: a number between -2,147,483,648 and 2,147,483,647
long: a number between -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float: a floating point number, a number with decimals
double: a floating point number but with more precision
char: a single character
boolean: a binary value, true or false
Now that we know the primitive types supported in Java, let's declare our variables.
Declaring
Declaring a variable is how you create them. Here's an example featuring all of the primitive data types: