variable_type variable_name = variable_value;

String: store text and are enclose by double quotes

String fruit = "Apple";

Int: stores whole numbers (integers) without decimals

int x = 5;

float: stores decimal numbers (floating points) such as 5.6, 12.2

float myFloat = 12.2;

char: stores single upper-case or lower-case characters such as 'A' or 'b'. the characters

char myChar = 'A';

boolean: stores values with two states, true or false

boolean isRaining = true;
boolean notRaining = false;

Picking the name for a variable

  • Cannot user special characters such as % $ # ? or space.
  • You cannot use reserved words like double or class.
  • Names are case sensitive.
  • Variable names must start with a letter or underscore (_) character, and the remaining characters must be letters, numbers, or underscores.
  • Use Camel case. It uses uppercase letters to denote word boundaries, as in isRaining from the example above.

Names by Java convention:

  • Variable names start with a lowercase letter.
  • Class names start with an uppercase letter.