This page describes how to declare variables in Java.

We'll start out with variable data types of "String" and "int". We'll be introducing many more as we go...

Four common types are described here.

More information on boolean can be found here.

NOTE WELL -- Java is case sensitive. In other words Java expects "String" and not "string", and "int" and not "INT", etc.
Here we declare six variables.

We'll break this down in the following steps.
String firstName;
int width;
int treeDiameter;
String description;
boolean isLarge;
double diagonalLength;
See the highlighted line.

  • The first token (String) is the data type.
  • The second token (firstName) is the name of the variable
  • The first token (String) must be spelled to exactly match the actual data type
  • The second (firstName) is the variable name (coder's choice -- as long as it has a valid name)
  • The other lines are declared similarily (data type followed by variable name)
String firstName;
int width;
int treeDiameter;
String description;
boolean isLarge;
double diagonalLength;
See the highlighted line.

  • The first token (boolean) is the data type.
  • The second token (isLarge) is the name of the variable
  • The first token (boolean) must be spelled to exactly match the actual data type
  • The second token (isLarge) is the variable name (coder's choice -- as long as it has a valid name)
  • The other lines are declared similarily (data type followed by variable name)
String firstName;
int width;
int treeDiameter;
String description;
boolean isLarge;
double diagonalLength;