Variables

There are four variables that are commonly use in Java - integers, doubles, Strings, and booleans.

Integers

Description:

This data type is used for storing whole numbers. It can be useful for the following:

Keeping a score or tracking points
Representing lives in a video game
Basically anything that does not involve halves or decimal numbers

Integers can also be used in mathmatical operations, like adding, subtracting, multiplication, and division. However, be warned that integers cannot store anything other than a whole number, so if your answer results in a non-whole number value, the decimal will be chopped off and the resulting value will be inaccurate.

Creating Integers:

Integers can be created in Java like this:

int number = 2;

"int" represents the integer variable type. "number" is the name of the variable. It has been set equal to 2.

Doubles

This data type is used for storing decimal numbers. It can be useful for the following:

Calculating precise values
Working with fractions
Representing temperature and measurement.

Strings

This data type is used for storing alphanumeric data such as words, names, and numbers.

Booleans

This data type can only hold one of two values - true or false.