6com1045 Coursework Test Questions
6com1045 Coursework Test Questions
1. Describe the von Neumann architecture and the fetch-execute cycle. (5 marks)
2. The concrete syntax of a statement is the text of the statement in a particular programming
language. Show the concrete syntax of an assignment statement in two different programming
languages, e.g. in BASIC and in Java. Which parts are similar and which are different? (6 marks)
3. Name some features typical of imperative programming. Name one language which supports
these features. (5 marks)
4. An abstract data type allows a programmer to encapsulate fields and methods together. Write an
example in either Java or Ruby which illustrates encapsulation of a field and a method. (6 marks)
6. Java version 7 introduced the diamond operator for type inference. Give an example of how the
diamond operator is used, and explain what advantages it provides the programmer. (6 marks)
9. The following BASIC program adds up all the numbers from 0 to a number given in N:
1010 LET N = 10
1020 LET I = 0
1030 LET SUM = 0
1040 LOOP:
1050 LET SUM = SUM + I
1060 LET I = I + 1
1070 IF I < N THEN GOTO LOOP
1080 PRINT SUM
Total: 20 marks
10. The Java language has evolved considerably since its first release in 1996.
a. Pick one of the following language features: interfaces, iteration, or switch statements and
describe how that construct has evolved through Java’s development. You should provide code
examples from an early version, and later versions to show how the changes. Explain what
advantages the changes provide for the programmer. (12 marks)
b. Early versions of Java did not support meta-programming (through annotations and reflection),
lambda expressions, or generics. Pick one of these aspects of the Java language, explain how it
works and how it improves the experience of programming in Java. (8 marks)
Total: 20 marks
11. Explain what is meant by the syntax and semantics of a programming language expression such
as 3+4*5. (6 marks)
Where "constant" refers to numbers such as 1, 2, 3…; "neg" to negate; "sum" to plus (+); "diff" to
subtract (-); "prod" to multiply (*); and "quot" to division (/). (You can assume "numerals" have the
usual definition as sequences of digits.)
You are asked to add a new operation to the expression definition, triple x (which returns the value
of 3*x).
a. Add a line to the syntax definition of “expr” for the triple operation (2 marks)
b. Give one or more rules to define the denotational semantics of the triple operation by
extending the definition of “meaning” (2 marks)
c. Show an example trace of the semantics using the expression “triple (2+1)”. You will first
have to write the expression using the syntax definitions, and then use the definition of
“meaning”. (10 marks)
Total: 20 marks
12. Functional programming allows the programmer to use functions as first-class values. Give
examples from any language of:
The following function counts the number of items in a list of Int values:
d. Explain what is meant by a polymorphic function and rewrite the lstCount function so that it
can be used with lists of any type. (6 marks)
e. The function lstCount above is not tail recursive. Explain what is meant by tail recursion, and
rewrite the function to be tail recursive. Why might this be more efficient? (8 marks)
Total: 20 marks
13. In the following Java program, explain the problem that the synchronized keyword is solving
and how it solves it.
Clojure provides a “software transaction memory” approach to solving the same problem. With the
help of a Clojure example, explain in your own words how “software transaction memory” works,
and in particular include an explanation of “optimistic concurrency”. (14 marks)
Total: 20 marks