CSC 8310 Midterm Exam
Fall 2000, Villanova University
David Matuszek
Name ____________________________________

Please keep all answers short and to the point, and don't provide any information that wasn't asked for. There are no essay questions on this exam.

Prolog

  1. (20 points) Unification is an essential operation in Prolog. For each of the following, tell (1) whether the two expressions can be unified, and (2) if so, what is the value of each variable after unification.

    1. Jack = john


    2. Mary = mother(Bill)


    3. '+'(5, 3) = '+'(5, 3)


    4. loves(Bill, Sally) = loves(Sally, Bill)


    5. spouse(John, Mary) = spouse(Mary, John)


    6. loves(john, mary) = loves(john, mother(Bill))


    7. child(Mary, mother(Bill)) = child(child(John), Sally)


    8. child(Mary, mother(Bill)) = child(child(John), Mary)


    9. Jack = father(Jack)


    10. loves(john, mary) = loves(_, _)



  2. (15 points) Assume you have a Prolog database consisting of a large number of clauses of the following three predicates (and no other predicates):

       male(X)        /* Examples: male(john). male(bill). Etc. */
       female(X)
       child(X, Y, Z) /* X is the child of Y and Z */

    Write the following predicates. Each predicate should require not more than three clauses. You may use the three predicates above plus any others you write in response to this question.

    mother(X, Y)






    mate(X, Y) /* X and Y are parents of some child */






    childless(X) /* X has no children */






    different(X, Y) /* X and Y are not the same */






    siblings(X, Y) /* X and Y are different people with the same parents */







Java

  1. (6 points) In the following method:

    void setName (String name) { this.name = name; }

    1. To what does this.name refer?


    2. To what does name (without this) refer?


    3. There is a name for methods (like this one) whose only purpose is to assign a value to a variable. What are these methods called?



  2. (3 points) In which kind of Java method is it illegal to use the keyword this?



  3. (4 points) There are five basic methods defined for all applets, but only one of them takes a parameter. Which one takes a parameter, and what is the type of that parameter?




  4. (3 points) Write a Java statement to output the string Hello.




  5. (4 points) Sometimes adding a constructor to a class, even if the constructor is correctly written and even if it is never used, will cause an error. Briefly, what is the error and why does it occur?





  6. (3 points) When you say that a class implements an interface, you are making a promise. What is that promise?





  7. (5 points) Write the HTML for a simple web page with Hello in both the title bar and the body.











  8. (4 points) If you want to put two buttons in the SOUTH part of a BorderLayout, how can you do it? (Answer in English, do not write Java code.)







  9. (3 points) If you write a statement in Java that might throw an Exception, what (if anything) does Java insist that you do about it?





  10. (4 points) Give a brief definition for each of the following terms:

    1. javadoc



    2. Swing



    3. Listener




  11. (4 points) Which of the following are objects in Java? (Write "yes" or "no" for each.)
      arrays errors events exceptions

General

  1. (5 points) Write a BNF definition for <integer>, where an <integer> consists of one or more digits, and the first digit may not be zero, unless it is the only digit (that is, 0 by itself is allowed, but 007 is not). You can assume that <digit> has already been defined.








  2. (6 points) Give a brief definition for each of the following terms:

    1. nonterminal



    2. scope (of a variable)



    3. signature (of a method)




  3. (2 points) What does "CRC" stand for?



  4. (2 points) What does "MVC" stand for?



  5. (4 points) Two common ways of passing parameters are by value and by reference.

    1. Mention one advantage of passing parameters by value.


    2. Mention one advantage of passing parameters by reference.



  6. (3 points) FORTRAN was the first "higher-level" language to become popular. What was the single most important factor in its success?