CIS-260 Home http://www.c-jump.com/bcc/

Class Constructors, Java Method Overloading, Exceptions


  1. Class Constructors, Java Method Overloading, Exceptions
  2. Object Constructors
  3. When is constructor called ?
  4. The new keyword in Java
  5. Inside a Constructor
  6. Default constructor
  7. Multiple Constructors
  8. Method overloading (Java)
  9. Using UML to Model classes
  10. How the super class is constructed
  11. Error handling: Java Exceptions
  12. What is an exception?
  13. Exception Object
  14. try and catch
  15. Exception Demo
  16. Exception UML diagrams

1. Class Constructors, Java Method Overloading, Exceptions


2. Object Constructors


3. When is constructor called ?


4. The new keyword in Java


5. Inside a Constructor


6. Default constructor


7. Multiple Constructors


8. Method overloading (Java)


  • Method overloading means that the same method name is used over and over again,
    but method signature is different every time.

  • Method signature consists method name and a parameter list.

  • Method signature does not include the return type.

  • Java method signature components are as follows:

      Java method signature components

9. Using UML to Model classes


  • DataBaseReader class diagram lists two constructors.

  • Without the parameter list, there is no way to know which constructor is which:

    
    public class DataBaseReader {
        String dbName;
        int startPosition;
        // initialize just the name
        public DataBaseReader (String name){
            dbName = name;
            startPosition = 0;
        }
        // initialize the name and the position
        public DataBaseReader (String name, int pos){
            dbName = name;
            startPosition = pos;
        }
        .. // rest of class
    }
    
    
  • Class diagram for the DataBaseReader class:

      DataBaseReader class diagram

10. How the super class is constructed


11. Error handling: Java Exceptions


12. What is an exception?


13. Exception Object


14. try and catch


15. Exception Demo


  1. Create folder

        C:\CIS123
    
  2. Download file Banking.zip into that folder.

  3. Unzip downloaded file.

  4. The resulting folder structure should be:

        C:\CIS123\Banking
    
  5. Execute commands found in file commands.txt:

    "C:\Program Files\Java\jdk1.6.0_06\bin\javac.exe" C:\CIS123\Banking\*.java
    "C:\Program Files\Java\jdk1.6.0_06\bin\java.exe" -classpath "C:\CIS123\Banking" BankingMain
    

    Note: you may need to adjust the path

        C:\Program Files\Java\jdk1.6.0_06
    

    to point to the correct version of Java utilities installed on your system.

     

16. Exception UML diagrams

  • Exception raised by activity:

      Exception raised by activity

  • Exception handler on activity:

      Exception handler on activity

  • Exception handlers on computation example:

      Exception handlers on computation example