-
(a)Explain the term interface. Support your explanation with a Java program. [9 marks]
(b)List 5 primitive data types and write a snippet that shows how to declare each of them in Java and Python. [10 marks]
(c)Differentiate between parallelism and concurrency. [3 marks]
(d)Differentiate between a thread and a process. [3 marks]
-
(a)In a concise statement, describe language implementation in programming. [5 marks]
(b)Identify the syntax errors in the following code snippets and write the correct snippet. [5 marks]
(i)
x = (3 + 5;
(ii)
y = 3 + * 5;
(iii)
# This code snippet checks if the user is strictly up to 21 years of age
if age > 21:
print("Access granted.")
else:
print("Access denied.")
(iv)
# We want an average of 75 and 130
a = 75
b = 130
avg = a + b / 2
print (avg)
(c)A programming language is defined by two fundamental components; briefly discuss these components. [5 marks]
-
(a)Classify the following raw source code expressions into lexemes and tokens: [5 marks]
(i)
Y = (20 - B) / (35 + D * 7)(ii)
K = (P - T**3) / (J - W * Y)(b)Identify the logical errors in the following Python code snippets and write the correct snippet:
(i)[1 mark]
# The aim is to calculate 10% tax
price = 100
tax = price * 0.01
(ii)[1 mark]
# The aim is to print numbers 1 through 5
for i in range(1, 5):
print(i)
(iii)[3 marks]
# The aim is to count down from 10 to 1
countdown = 10
cycles = 0
while countdown > 0:
print(countdown)
cycles += 1
(c)List and explain three major approaches to formal semantics. [5 marks]
-
(a)Explain the term control structures and support your explanation with flowcharts. [5 marks]
(b)Given two arrays A = [1, 3, 4] and B = [1, 5, 6], the element-wise sum of the arrays is [2, 8, 10]. Write a Python or Java program that returns the element-wise sum and prints the resulting array. [5 marks]
(c)Using a suitable example in the Java programming language, differentiate between a while loop and a do-while loop. [5 marks]
-
(a)Explain the term exception handling in programming. [5 marks]
(b)Write a Python program to handle a zero division error, which may occur when accepting two numerical inputs from users and dividing them. [5 marks]
(c)Given these two lines of Java:
FileReader file = new FileReader("student.txt");
System.out.println("File opened successfully");
Add the appropriate exception to make it compile successfully. [5 marks]
-
(a)Explain linked list and stack data structures with the aid of a diagram. [4 marks]
(b)Differentiate between linear and non-linear data structures. [4 marks]
(c)Write a Java program that creates a LinkedList named books, adds five book titles, allows a new book title to be added at the beginning of the list, removes a specified book title, and displays all available books in the library. [7 marks]


