Unit 2: Introduction to Programming in Scala - Subjective Questions

INT315 — Cluster Computing • Practice Questions with Detailed Answers

20 questions

1

Explain the major features of Scala and discuss how Scala combines object-oriented and functional programming paradigms.

2

Describe the basic data types and literals used in Scala with suitable examples.

3

Explain operators in Scala and describe how operators are implemented as methods. Illustrate your answer with examples.

4

What is type inference in Scala? Explain its advantages and limitations with examples.

5

Distinguish between mutable and immutable collections in Scala. Discuss the benefits and drawbacks of each approach.

6

Define a function in Scala and explain the difference between a function definition, a function value, and a method.

7

Explain higher-order functions and closures in Scala. Provide examples showing how they are used.

8

Describe lists in Scala and explain important list operations such as construction, access, concatenation, mapping, filtering, and folding.

9

Compare lists and arrays in Scala with respect to mutability, access time, memory behavior, and typical use cases.

10

Explain maps in Scala and distinguish between immutable and mutable maps. Include examples of insertion, lookup, update, and traversal.

11

What are streams in Scala? Explain how streams support lazy evaluation and compare them with strict collections.

12

Write and explain a Scala program that uses a list, a higher-order function, and immutable transformations to calculate the sum of squares of even numbers.

13

Explain the difference between val, var, and def in Scala. Discuss their effect on immutability, evaluation, and repeated execution.

14

Describe pattern matching in Scala and explain how it can be used to process lists and other values.

15

Explain recursion and tail recursion in Scala. Derive a tail-recursive method for calculating the factorial of a non-negative integer.

16

Compare map, flatMap, and for comprehensions in Scala. Explain their relationship using examples.

17

Explain the role of Option, Some, and None in Scala map lookups and compare this approach with returning null.

18

Explain lazy evaluation in Scala and show how a lazy collection can improve efficiency in a sequence of transformations.

19

Discuss function parameters in Scala, including default parameters, named arguments, variable-length parameters, and call-by-name parameters.

20

Explain traits and objects in Scala and discuss their importance in designing Scala programs.