MCQs on Concurrency and Parallelism | Scala

Master concurrency and parallelism in Scala with essential MCQs on Akka, Cats Effect, ZIO, the actor model, and managing parallel computations. Test your expertise and refine your skills today!


Concurrency and Parallelism in Scala

1. Scala Concurrency Tools (Akka, Cats Effect, ZIO)

  1. What is the main purpose of Akka in Scala?
    • A) To handle REST APIs
    • B) To manage concurrent and distributed systems
    • C) To serialize objects
    • D) To build UIs
  2. Which concurrency tool uses IO monads to manage side effects in Scala?
    • A) Akka
    • B) Cats Effect
    • C) ZIO
    • D) Slick
  3. What feature does Cats Effect provide for concurrency?
    • A) Fiber-based concurrency
    • B) Immutable collections
    • C) Actor-based concurrency
    • D) Database integrations
  4. ZIO is best known for which of the following features?
    • A) Type-safe error handling
    • B) Actor-based systems
    • C) Reactive streams
    • D) None of the above
  5. Which tool is commonly used in Scala for lightweight, concurrent programming?
    • A) Akka Streams
    • B) Futures
    • C) Actors
    • D) All of the above
  6. What is a Fiber in Cats Effect?
    • A) A lightweight, concurrent unit of execution
    • B) A data serialization method
    • C) An immutable data structure
    • D) A debugging tool
  7. How does ZIO handle side effects?
    • A) Using Future
    • B) Using a pure functional effect system
    • C) Using global locks
    • D) By mutating shared variables
  8. Which library provides a typed actor system in Scala?
    • A) Akka
    • B) Cats Effect
    • C) ZIO
    • D) Slick
  9. What is the role of IO in Cats Effect?
    • A) To represent computations with side effects
    • B) To handle pattern matching
    • C) To manage HTTP requests
    • D) To create actor systems
  10. Which of the following is NOT a feature of Akka?
    • A) Actor-based concurrency
    • B) Stream processing
    • C) Database integration
    • D) Distributed systems support

2. Actor Model with Akka

  1. What is an actor in Akka?
    • A) A single-threaded process
    • B) A lightweight entity that processes messages asynchronously
    • C) A concurrent data structure
    • D) A type of immutable variable
  2. How do actors communicate in Akka?
    • A) Using shared memory
    • B) By passing messages
    • C) Using global locks
    • D) None of the above
  3. What method is used to send a message to an actor in Akka?
    • A) tell
    • B) ask
    • C) Both A and B
    • D) dispatch
  4. What is the purpose of the ask pattern in Akka?
    • A) To send a message and wait for a reply
    • B) To broadcast a message to multiple actors
    • C) To terminate an actor
    • D) To monitor actor health
  5. What is an ActorRef in Akka?
    • A) A reference to an actor that can be used to send messages
    • B) A type-safe wrapper for collections
    • C) A logging tool for debugging
    • D) None of the above
  6. How does Akka ensure thread safety for actors?
    • A) By allowing only one thread to access an actor at a time
    • B) By using global locks
    • C) By serializing all actor state
    • D) By running actors on separate physical machines
  7. What is the purpose of an actor supervisor in Akka?
    • A) To monitor and manage child actors
    • B) To serialize actor messages
    • C) To log errors
    • D) To create new threads
  8. Which configuration file is used to set Akka system parameters?
    • A) application.conf
    • B) settings.conf
    • C) akka.properties
    • D) config.json
  9. How does Akka implement message passing between actors?
    • A) Through immutable messages
    • B) Using mutable shared state
    • C) By locking critical sections
    • D) By copying actor states
  10. What is the purpose of the Akka Streams module?
    • A) To handle asynchronous stream processing
    • B) To manage actor lifecycle
    • C) To perform database operations
    • D) To manage global locks

3. Managing Parallel Computations

  1. Which of the following can execute computations in parallel in Scala?
    • A) Futures
    • B) Parallel collections
    • C) Cats Effect fibers
    • D) All of the above
  2. What method is used to combine two parallel computations in Scala Futures?
    • A) map
    • B) flatMap
    • C) zip
    • D) merge
  3. How do you execute a task asynchronously in Cats Effect?
    • A) Using IO.shift
    • B) Using Future.apply
    • C) Using Par.run
    • D) None of the above
  4. What is the purpose of parallel collections in Scala?
    • A) To execute collection operations concurrently
    • B) To manage actor systems
    • C) To implement database transactions
    • D) None of the above
  5. Which of the following can handle error recovery in parallel computations?
    • A) Futures
    • B) ZIO
    • C) Cats Effect IO
    • D) All of the above
  6. What is the key difference between concurrency and parallelism?
    • A) Concurrency involves managing multiple tasks; parallelism executes them simultaneously
    • B) Concurrency is always faster than parallelism
    • C) Parallelism handles errors better than concurrency
    • D) None of the above
  7. What is a key advantage of functional parallelism in Scala?
    • A) Immutability ensures thread safety
    • B) Faster computation times
    • C) Improved debugging features
    • D) None of the above
  8. How does ZIO handle parallel computations?
    • A) Using fibers
    • B) Using threads
    • C) Using locks
    • D) By mutating shared state
  9. What method in Akka Streams handles parallel stream processing?
    • A) mapAsync
    • B) filter
    • C) fold
    • D) zip
  10. Which Scala library provides the richest support for functional parallelism?
    • A) Cats Effect
    • B) Akka
    • C) ZIO
    • D) Both A and C

Answer Key

QnoAnswer (Option with the text)
1B) To manage concurrent and distributed systems
2B) Cats Effect
3A) Fiber-based concurrency
4A) Type-safe error handling
5D) All of the above
6A) A lightweight, concurrent unit of execution
7B) Using a pure functional effect system
8A) Akka
9A) To represent computations with side effects
10C) Database integration
11B) A lightweight entity that processes messages asynchronously
12B) By passing messages
13C) Both A and B
14A) To send a message and wait for a reply
15A) A reference to an actor that can be used to send messages
16A) By allowing only one thread to access an actor at a time
17A) To monitor and manage child actors
18A) application.conf
19A) Through immutable messages
20A) To handle asynchronous stream processing
21D) All of the above
22C) zip
23A) Using IO.shift
24A) To execute collection operations concurrently
25D) All of the above
26A) Concurrency involves managing multiple tasks; parallelism executes them simultaneously
27A) Immutability ensures thread safety
28A) Using fibers
29A) mapAsync
30D) Both A and C

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top