Static Variable: A static variable is a variable that belongs to the class as a whole, and not just to one object

  • There is only one copy of a static variable per class, unlike instance variables where each object has its own copy
  • A static variable is declared like an instance variable, with the addition of the modifier static
    • private static int myStaticVariable;
  • A static variable should always be defined private, unless it is also a defined constant
    • The value of a static defined constant cannot be altered, therefore it is safe to make it public
    • In addition to static, the declaration for a static defined constant must include the modifier final, which indicates that its value cannot be changed
      • public static final int BIRTH_YEAR = 1954;
  • When referring to such a defined constant outside its class, use the name of its class in place of a calling object
    • int year = MyClass.BIRTH_YEAR;


Equating Strings & Numbers

eg: variableName.equals("String")
eg: variableName.equalsIgnoreCase("String")
eg: variableName == Number