CSC 8310   Linguistics of Programming Languages

Dr. David Matuszek,   dave@acm.org
Fall 1998, Villanova University

Sample questions from previous exams
An unsigned integer consists of one or more digits, where the first digit may not be zero (unless it's the only digit). Write a pure BNF (not extended BNF) description of an unsigned integer.
Suppose you want to define a digitlist as a comma-separated list of digits, enclosed in brackets. Some examples might be [], [8], and [3,1,4,1,6]. Write a BNF definition (not an Extended BNF definition) of digitlist.
Once space is allocated for an array in Java, it stays that same size. Name a Java class that you can use like an array but that automatically gets bigger as you add things to it.
What are two important differences between Java 1.0 and Java 1.1?
In System.out.println,
  • System is a(n) ________________
  • out is a(n) ________________, and
  • println is a(n) ________________.
If a method is declared as public void dumpIt (Object ob), are all parameter types legal, or is there something you can't give dumpIt as a parameter?
Which Java package do you never have to import, because it's always automatically imported for you?
Can you use java.awt in applications, or is it only for applets?
In Java, are parameters passed by name, by reference, or by value?
The following statement could cause an ArithmeticException to be thrown. Add code to set result to 0 if this happens (but don't try to prevent it from happening).
      result = max / min;
One common type of exception in Java is the NullPointerException. What is odd about the name of this exception?
List three of the methods in the Applet class that you will probably override when you write an applet. (Just name them, don't talk about them.)
There is something wrong with this HTML that prevents the applet from showing up in the browser. Fix the problem.
    <html>
    <head>
    <title>This is my applet.
    </head>
    <body>
    <applet code="MyApplet.class" height=100 width=100>
    </applet>
    </body>
    </html>
Finish this sentence: The goal of structured programming is to write programs that are ____________________________________________.
For decades, most new languages "borrowed" the syntax of common statements (assignments, if statements, loops) from the language ___________. Recently, it has become more popular to "borrow" syntax from the language ___________.
The four terms function, procedure, method, and predicate have similar meanings, but I want to know how to tell them apart. Tell what is different about each of these that justifies having a separate name for it.
function:

procedure:

method:

predicate:

Consider the following code:
    public class Speed {
       int speed;
       Speed (int s) { speed = s; }
    }
    class Velocity extends Speed {
       int direction;
       Velocity (int d) { direction = d; }
    }
  1. Why does the compiler give an error message for this code?
  2. If you leave class Velocity alone, what change could you make to class Speed to solve the problem? (Write the new version of class Speed.)
  3. If you leave class Speed alone, what change could you make to the constructor in class Velocity to solve the problem? (Write the new version of the constructor for Velocity.)
Consider the following program in some pseudo-language:
    procedure bump (x)
    x = x + 1
    print x
    end
...
    m = 5
    call bump (m)
    print m
What two numbers will the program print

  1. if parameters are passed by value?

  2. if parameters are passed by reference?

Consider class Point { int x, y; }
  1. Does it have a constructor?
  2. Write a simple constructor for class Point above that takes two arguments and uses them to set x and y.
  3. Assuming that you have answered (2) correctly, now how many constructors are there for Point? Why?
Consider the following code:
class MyClass { static int a; int b; ...methods... }
MyClass foo = new MyClass ();
Inside the methods of MyClass, we can refer to the two variables simply as a and b.

  1. Outside the class, how do we refer to variable a?

  2. Outside the class, how do we refer to variable b?

If a class has two or more constructors, and one of the constructors calls another of the constructors,

  1. What special keyword is used to call the other constructor?

  2. Where must the call to the other constructor be placed?

If class Polygon extends class Shape, and class Shape extends class Object, in what order are the constructors executed when you call new Polygon ()?
Every object in Java can be printed, although the output may be something like Polygon@dde07e9. If you want objects to be printed more nicely, what is the name of the method you have to override?