Some Common Errors of First Time Java Programmers

  1. Error #1: forget to create an object...


    class myProgram { public static void main(String args[]) { BankAccount harrysChecking; ... harrysChecking.deposit(500.0); // the object was not created } }
  2. Error #2: try to "reset" an object by calling constructors...


    class myProgram { public static void main(String args[]) { BankAccount harrysChecking = new BankAccount(1000.0); ... harrysChecking.BankAccount(500.0); // reset balance to 500.0 ??? } }
  3. Error #3: invoking an instance method without an object...


    class myProgram { public static void main(String args[]) { BankAccount harrysChecking = new BankAccount(1000.0); ... deposit(500.0); // forget to specify an object } }