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,
|
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: |
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; } }
|
Consider the following program in some pseudo-language:
procedure bump (x) x = x + 1 print x end ... m = 5 call bump (m) print mWhat two numbers will the program print
|
Consider class Point { int x, y; }
|
Consider the following code:
class MyClass { static int a; int b; ...methods... }Inside the methods of MyClass, we can refer to the two variables simply as a and b.
|
If a class has two or more constructors, and one of
the constructors calls another of the constructors,
|
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? |