University of Virginia, Department of Computer Science
CS201J: Engineering Software, Fall 2002

Notes: Tuesday 3 September 2002
Assignments Due

Notes and Questions

How can we increase our confidence that a program works as intended?






For what kinds of programs is exhaustive testing possible?






What is a successful test case?






What is the difference between testing and analysis?






What are the advantages and disadvantages of spending time on analysis instead of testing?






Java Semantics

Excerpts from Java API documentation:

java.lang.String

The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class.

Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings. Because String objects are immutable they can be shared. For example:

     String str = "abc";
 

is equivalent to:

     char data[] = {'a', 'b', 'c'};
     String str = new String(data);
 

public boolean equals(Object anObject)

Compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.
public class Strings {
    public static void main (String [] args) {
        String s = new String ("hello");
        String t = new String ("hello");
        StringBuffer sb = new StringBuffer ("he"); 
        StringBuffer tb = sb;
        String s1 = "hello";
        String t1 = "hello";

        sb.append ("llo");
        tb.append (" goodbye!");

        s.concat (" goodbye!");
        t = s.concat (" goodbye!");
        
        // What are the values of s, t, sb and tb now?
        
        // Which of these are true:
        //    a) s == t
        //    b) s1 == t1
        //    c) s == s1
        //    d) s.equals (t)
        //    e) sb == tb
        //    f) t.equals (tb)
    }
}
Testing can establish the presence of errors, but never their abscence.

Edsger Dijkstra

Is this always true?


CS201J University of Virginia
Department of Computer Science
CS 201J: Engineering Software
Sponsored by the
National Science Foundation
cs201j-staff@cs.virginia.edu