Resit-Question-Ct006 3 3 Aplc
Resit-Question-Ct006 3 3 Aplc
Resit-Question-Ct006 3 3 Aplc
SECTION A
Answer ALL questions.
Each question carries ONE (1) mark.
1. Which of the following programming paradigm that focuses on binding functions for
computations like mathematical functions and avoid changing state and mutable data?
(a) Imperative programming
(b) Functional programming
(c) Logic programming
(d) Object oriented programming
3. The following statements are correct for side-effect in functional programming paradigm
except
(a) the function that performs a recursive call
(b) the function that modifies a data structure in place
(c) the function that changes the file system
(d) the function that mutate the external data
5. The following statements demonstrate the differences between functional (FP) and object-
oriented programming (OOP) except
(a) FP uses immutable data while OOP uses mutable data
(b) FP follows declarative programming model while OOP follows imperative
programming model
(c) FP focuses on “how you are doing” while OOP focuses on “what you are doing”
(d) FP supports parallel programming while OOP is not suitable for parallel programming
6. Which of the following programming concept describes turning a function with multiple
arity into a function with less arity?
(a) Closure
(b) Currying
(c) Partial application
(d) Monad
7. Given the following code below. Which one is higher order function?
(a) Stream.of()
(b) reduce()
(c) get()
(d) Optional.isPresent()
8. Given the f() method below. Which of the following curried function is correctly defining
the f() method?
(a)
Function<Integer, Function<Integer, Integer>> f(int a, int
b) {
return c -> d -> (a+b) * (c+d);
}
(b)
Function<Integer, Function<Integer, Integer>> f(int a) {
return b -> c -> d -> (a+b) * (c+d);
}
(c)
Function<Integer, Function<Integer, Function<Integer,
Function<Integer, Integer>>>> f = a -> b -> c -> d -> (a+b)
* (c+d);
(d)
Function<Integer, Function<Integer, Function<Integer,
Function<Integer, Integer>>>> f = (a+b) * (c+d);
9. Based on the given multiply() method. Which of the following code is valid to call the
method?
class Demo{
10. Given the code snippet below. Which lambda expression best represents the
factorial(n) method?
class Demo{
static final int factorial(int n) {
// stop condition
if (n == 0) {
return 1;
}
return n * factorial(n - 1);
// recursive call
}
}
(a)
static final UnaryOperator<int> factorial = n -> n == 0 ? 1 :
n * Demo.factorial.apply(n - 1);
(b)
static final UnaryOperator<Integer> factorial = n -> n == 0 ?
1 : n * Demo.factorial.apply(n - 1);
(c)
static final UnaryOperator<Integer> factorial = n -> n == 0 ->
1 -> n * Demo.factorial.apply(n - 1);
(d)
static final Function<Integer, Integer> factorial = n -> n ==
0 -> 1 -> n * Demo.factorial.apply(n - 1);
13. Which of the following is incorrect statement regarding the use of generics and
parameterized types in Java language?
(a) Generics provide type safety by shirting more type checking responsibilities to the
compiler.
(b) Generics and parameterized types eliminate the need for down casts when using Java
collections
(c) When designing your own collections class, say LinkedList, generics and
parameterized types allow you to achieve type safety with just a single class definition
as opposed to defining multiple classes.
(d) All of the above
import java.util.*;
15. In light of parametric polymorphism, generics introduce type inference. Which of the
following explains type inference in Java correctly?
(a) With type inferencing engine, the JVM restrict the types that can be used as generic
type arguments.
(b) Type inference enables the compiler look at the type of a method argument to infer a
generic type.
(c) Type inference means that generic type information is not available to the JVM at
runtime, only compile time.
(d) None of the above
16. The lambda expression is the first step of functional programming in Java. Choose a correct
statement for the lambda expression.
(a) Lambda expressions are considered to be anonymous functions that are bound to
identifiers.
(b) Lambda expressions implement functional interfaces with multiple abstract methods.
(c) Lambda expressions are functions that can be created belonging to a class.
(d) Lambda expressions enable passing functionality as an argument to another method
such as what action should be taken when event occurred.
17. Given the following lambda expression. Choose the correct return type of this lambda
expression.
(a) String
(b) Object
(c) void
(d) Function
(e) None of the above
18. Given the following lambda expression. Choose the correct return type of this lambda
expression.
(a) String
(b) Object
(c) void
(d) Function
(e) None of the above
19. Consider the following statement. Which of the following best describes the programming
practice used?
20. Assume that Holder, Account and Rate classes are predefined. Which of the
following is the most reasonable discussion on the given code?
(a) The program code design looks well-formatted with all possible null object checking.
It is an essential code pattern to meet the requirements.
(b) Multiple checks included for nullable objects may result in a lot of boilerplate code to
make sure no null exception occurs. This way, coding can be cumbersome.
(c) It is not an ideal approach to check the nullable cases or absence/presence of a value
at runtime. The object can be modelled in a container to optionally contain a value
during compilation.
(d) All of the above
23. Which of the following are the effects of eager evaluation strategy except
(a) Code that is easily understandable in terms of execution order that does not potentially
change its behaviour based on a change of execution context.
(b) An easier debug process compared to other evaluation strategies
(c) Responsibility for code performance is however shifted towards the programmer thus
requiring a careful code optimization process.
(d) The ability of define control flow as abstractions instead of primitives.
24. The following explains the lazy evaluation strategy in functional programming paradigms
except
(a) Lazily allows the language runtime to mandatorily evaluate subexpressions that are
not directly linked to the final result of the expression.
(b) Lazily increases the time complexity of an algorithm by evaluating the temporary
computations and conditionals.
(c) Lazily is easy to find its performance because it contains thunks/delayed objects of
expression before their executions.
(d) None of the above.
[25 marks]
SECTION B
Answer ALL questions.
Each question carries TWENTY-FIVE (25) marks.
Question B1
[25 marks]