CIT-73 Home http://www.c-jump.com/CIT73/CIT73syllabus.htm

Chapter 3, Advanced Concepts: Constructors, Overloading, Exceptions


  1. Week 5, Chapter 3, Advanced Concepts: Constructors, 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
  17. Week 5 Reading: pages 43-53

1. Week 5, Chapter 3, Advanced Concepts: Constructors, 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:\CIT73
    
  2. Download file Banking.zip into that folder.

  3. Unzip downloaded file.

  4. The resulting folder structure should be:

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

    "C:\Program Files\Java\jdk1.6.0_06\bin\javac.exe" C:\CIT73\Banking\*.java
    "C:\Program Files\Java\jdk1.6.0_06\bin\java.exe" -classpath "C:\CIT73\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

17. Week 5 Reading: pages 43-53