Archive‎ > ‎Fall 2009‎ > ‎2009‎ > ‎Exam Information‎ > ‎

Sample Exam Questions

The following questions are meant to give you a feel for the types of questions you can expect on the exam. Do not be surprised if one or more of these questions actually appear on the exam, in this same form, or slightly modified. When there is a multiple-choice question, one or more answers are correct, unless it is explicitly specified that exactly one should be chosen.  Some of these questions come from last year's exam. The exam will be designed such that you have sufficient time to answer the questions if you know the answer; in other words, it will not test your speed.

If you have any further questions about the exam, please do no hesitate to email the staff.

1. Is there a notion of object address in the specification of the Java language?

(a) Yes
(b) No
(c) Address of object x is given by System.identityHashCode(x).
(d) Address of object x is given by x.hashCode().

2. The main difference(s) between unit tests and system tests is/are:

(a) Unit tests are black-box tests, as opposed to system tests, which are clear-box (white-box).
(b) Unit tests are clear-box, as opposed to system tests that are black-box.
(c) Unit tests exercise the functionality of a single component, whereas system tests exercise the entire system.
(d) Unit tests often require stub interfaces of other components, whereas system tests typically do not.

3. What does the following snippet of Java 1.5 code print out?

   String a = "exam";
   String b = "exam";
   String c = "Exam";
   String d = null;

   if ( a==b && b==c ) {
      System.out.println( "X" + d );
   } else if ( a==b && b!=c ) {
      System.out.println( "Y" + d );
   } else {
      System.out.println( "Z" + d );

(a) Will not print anything, but instead throw java.lang.NullPointerException.
(b) Xnull
(c) Ynull
(d) Z

4. Say you use a static analysis tool on a program and find fifteen bugs, and then you fix them all. After that, your program ends up crashing more often than before. Which is/are plausible reason(s)?

(a) One or more of the fixes changes slightly the timing in the program, thus exercising a data race bug that was previously not manifesting; this leads to frequent crashes.
(b) The bugs you fixed were on execution paths that are not encountered during normal runs, so the effect of the fixes is nil; moreover, with some of the fixes you introduced new bugs.
(c) Right after the patch, you upgraded some of the third party libraries used by the program, and this causes it to crash more frequently.
(d) Most of the bugs reported by the static analysis tool were actually false positives.

5. Which of the following is/are advantage(s) of an iterative development style, compared to the classic approach based on rigid specifications and regimented development?

(a) Can accommodate changes to the product specification/requirements more easily.
(b) Can cope with new, inexperienced developers more easily.
(c) Ensures that design mistakes are discovered early.
(d) The cost of development can be more easily estimated upfront.

6. Assume you are working on a code base with L lines of code, which result in P possible execution paths through the code. In general, the complexity of testing is directly proportional to P. If this code base doubles over the course of time from L to 2L, then we would expect the number of possible code paths to increase approximately to:

(a) log2P
(b) 2P
(c) 2L
(d) P2

7. Write an interface for a simple event-logging system. Your interface should allow the user of the interface to:
  • log events one at a time in an append-only fashion; an event can have one of three priorities (severities)
  • specify the filename to which the stream of events should be logged
  • specify a criterion by which the logging system can select and archive log events that are no longer necessary
Your interface definition should be entirely self-explanatory and unambiguous; do not include any comments. Follow the coding guidelines taught in class.

8. Consider the following fragments of an interface and implementation:

  interface Party {
     String partyAddress() ;
     Set<Guest> participants() ;

  class BirthdayParty implements Party {
     String partyAddress() {
        return street_ + " " + houseNumber_ + ", " + city_ + ", Switzerland" ;
     Set<Guest> participants() {
        Set<Guest> participantList = new HashSet<Guest>();
        for( int i=0 ; i < inviteeList_.size() ; ++i ) {
           if( inviteeList_[i].confirmed() )
              participantList.add( new Guest(inviteeList_[i].name()) );
        return partList;
     void newInvitee( Friend f ) {
        if( f.ageInYears >= 18 )
           inviteeList_.add( f );
           throw new UnderageException() ;

     private Vector<Friend> inviteeList_ ;
     private String street_ ;
     private String houseNumber_ ;
     private String city_ ;

Describe the abstract representation, concrete representation, rep invariant, and abstraction function as reflected solely in the given code.  You need not speculate about the missing code.

9. Write in Java an int abs(int n) function that computes the mathematical absolute value of its parameter n correctly.

10. Write a boolean function boolean equalFloats(double a, double b) that compares two floating point parameters a and b; it should return true if the values of a and b are equal and false otherwise.

11. The textbook advocates the use of test record keeping as a way to improve the development and testing process. Name five important aspects to record about the various defects encountered during testing and post-deployment. Name three metrics you can use to track the evolution of the quality of your testing and development process.

12. Identify six problems in the design of the following method:

  void HandleStuff( CORP_DATA inputRec, int crntQtr, EMP_DATA empRec,
     double estimRevenue, double ytdRevenue, int screenX, int screenY,
     COLOR_TYPE newColor, COLOR_TYPE prevColor, StatusType status,
     int expenseType )
     int i;
     for( i = 0; i < 100; i++ ) {
        inputRec.revenue[i] = 0;
        inputRec.expense[i] = corpExpense[ crntQtr ][ i ];
     UpdateCorpDatabase( empRec );
     estimRevenue = ytdRevenue * 4.0 / crntQtr;
     newColor = prevColor;
     status = SUCCESS;
     if( expenseType == 1 ) {
        for( i=0 ; i < 12 ; i++ )
           profit[i] = revenue[i] - expense.type1[i];
     } else if( expenseType == 2 ) {
        profit[i] = revenue[i] - expense.type2[i];
     } else if( expenseType == 3 ) {
        profit[i] = revenue[i] - expense.type3[i];

13. Write an iterative (non-recursive) function that returns, for all values of n, the same result as the following code:
  long fibonacci( int n )
if( n <= 1 ) {
return n;
} else {
return fibonacci(n-1) + fibonacci(n-2);

14. Write a more efficient (but still recursive) version of the following code:
  long fibonacci( int n )
if( n <= 1 ) {
return n;
} else {
return fibonacci(n-1) + fibonacci(n-2);

15. The following code contains a bug that would have been avoided if the programmer had followed the advice taught in the course. Which is the bug and how will it manifest?
  long fibonacci( int n )
if( n <= 1 ) {
return n;
} else {
return fibonacci(n-1) + fibonacci(n-2);

16. In "The Deadline", Belinda Binda offers Mr. Tompkins several precious lessons on how to interview programmers. Describe one of these lessons, along with an example.

17. "The Deadline" presents the Battle Command as a metaphor for project management. In doing so, the author uses a scene from the movie Patton. Describe briefly this metaphor and explain what it teaches us about project management.