CSCI 162 - Lecture 1

Instructor's Class Notes

  1. Class Essentials
  2. Chapter 1 - The Phases of Software Development
    1. Data Structure - A data structure is a collection of data, organized that items can be stored and retrieved by some fizxed techniques. Example: Java Array class.
    2. The Phases of Software Development
      1. Specification of the task
      2. Design of a solution
      3. Implementation (coding) of the solution
      4. Analysis of the solution
      5. Testing and debugging
      6. Maintenance and evolution of the system
      7. Obsolescence
    3. Java method as a Specification - Section 1.1
      1. Signature of a method:
                                
        // Convert a Celsius temperature c to Fahrenheit degrees
        public static double celsiusToFahrenheit(double c)
                                
                                
      2. Calling the method:
                                
        double fahrenheit = celsiusToFahrenheit(celsius);
                                
                                
      3. A more formal specification:

        celsiusToFahrenheit
        public static double celsiusToFahrenheit(double c)
        Convert a temperature from Celsius degress to Fahrenheit degrees.

        Parameters:
        c - a temperature in Celsius degrees

        Precondition:
        c >= -273.15.

        Returns:
        the temperature c converted to Fahrenheit degrees

        Throws: IllegalArgumentException
        Indicates that c is less than the smallest Celsius temperature (-273.15).

      4. A Method's Precondition and Postcondition:
        1. A precondition is statement giving the condition that is supposed to be true when a method is called. The method is not guaranteed to perform as it should unless the precondition is true.
        2. A postcondition is a statement describing what will be true when the method is correct and the precondition was true when the method was called, then the method will complete, and the postcondition will be true when the method's computation is completed.
      5. Throws List
        1. Throw an Exception to Indicate a Failed Precondition
        2. "Garbage in, garbage out."
      6. Figure 1.1 - Specification and Implementation for the Temperature Conversion Applications
        1. Documentation here.
        2. Source here.
        3. Use JavaDoc to write specifications
        4. Use Final variables to improve clarity
        5. Make Exception messages informative (include variable names, values, use good formatting).
      7. Self-Test Exercises Section 1.1 - Please do on your own, email me questions if needed.
    4. Running Time Analysis - Section 1.2
      1. Read Chapter 1 section 1.2. Covered further in Software Engineering
        1. Big-O Notation - A notation for description run time characteristics
          1. Quadratic Time O(n2) - Doubling the input size makes number of operations increase fourfold (or less).
          2. Linear Time O(n) - Doubling the input size makes number of operations increase twofold (or less).
          3. Logarithmic Time O(log n) - Doubling the input size makes the time increase by no more than a fixed number of new operations (one or two), or a fixed number of new operations, c, where c is a fixed constant.
        2. Worst-Case, Average-Case and Best-Case Analysis - For example, finding s specific item in an array using a for loop - what are the three cases?
    5. Testing and Debugging - Section 1.3
      1. Read Chapter 1 section 1.3.
      2. Choosing good test data
        1. You must know what output a correct program should produce for each test input.
        2. The test inputs should include those inputs that are most likely to cause errors.
      3. Boundary values - An input value that is one step away from a different behavior. For example the minimum and maximum acceptable values of input to a method are boundary values. If supplied the minimum then the method works properly, if supplied one less than the minimum the method fails to work properly.
      4. Fully Exercising Code - Make sure each line of code is executed at least once by some of your test data. Also make sure conditionals and loops are tested in the minority cases, for example, if expecting "false" for a conditional most of the time, make sure to test with data that causes the conditiobnal to initially be true and for for and while loops that never run, not even once.
      5. Avoid Impulsive Changes - When testing your program and you find a defect/failure, don't simply make a quick change to avoid the failed test. Instead, examine the code, understand the root cause of the failure, restructure the code if needed and make only changes that make the code better, more reliable, more readible, and simpler (where possible).
      6. Use the Debugger - The debugger is your friend. Become proficient in using it.
      7. Assert Statements - Assert statements include a boolean expression along with a corresponding output string that will be displayed as part of the throwing of an AssertionError by your program if the expression is false.
        1. Turn assertions on using -ea
          java -ea TemperatureConversion
        2. Avoid Using Assertions to Check Preconditions - Use throw instead.
  3. Programming in the Lab and on your own Computer