readyforhires

Advanced Kotlin test (Advanced)

40 questions · 40 minutes · Free

Coroutines in depth, Flow, DSLs and Android/server architecture.

Take the Advanced Kotlin test

What it covers

Interview format

Earn a certificate

The Advanced Kotlin test is one of the 5 tests of the Android Developer: Advanced learning path. Pass it and the other 4 tests at 70% or more and readyforhires issues you a verifiable certificate in your name, with its own code and verify link to share or add to LinkedIn.

Sample learning path certificate for Android Developer: Advanced, made out to “Your name” and marked SAMPLE
Pass with 70% or more to earn a verifiable certificate. This is a sample: yours carries your name, the date you earned it and its own verify code.

Sample questions

5 sample questions from the Advanced Kotlin test, with the answers. Samples are taken out of the live test, so you will not meet these when you sit it.

  1. What will happen when a coroutine is launched inside a `coroutineScope { }` block that is part of a parent scope with a `Default` dispatcher?

    1. The coroutine will run on the Default dispatcher and will be cancelled when the parent scope is cancelled.
    2. The coroutine will run on the Main dispatcher and will not be cancelled when the parent scope is cancelled.
    3. The coroutine will run on the IO dispatcher and will be cancelled when the parent scope is cancelled.
    4. The coroutine will run on the Unconfined dispatcher and will not be cancelled when the parent scope is cancelled.

    Answer: A. The coroutine will run on the Default dispatcher and will be cancelled when the parent scope is cancelled.

    When using `coroutineScope { }`, the coroutine runs within the context of the parent scope. If the parent scope is cancelled, the coroutine will also be cancelled. The `coroutineScope` function creates a new coroutine scope that inherits the context of the parent scope, including the dispatcher. In this case, the `Default` dispatcher is used, which is the default for CPU-bound tasks.

  2. Which of the following statements correctly describes the capabilities of a DSL builder in Kotlin?

    1. A DSL builder can only be created using the apply function and cannot use other functions or builder patterns
    2. A DSL builder can use only one function to create the entire API and cannot use any other functions or builder patterns
    3. A DSL builder can only be implemented using the with function and cannot use any other functions or builder patterns
    4. A DSL builder can use scope functions like apply, with, and also can use builder functions like run and also can use custom functions to create a fluent API

    Answer: D. A DSL builder can use scope functions like apply, with, and also can use builder functions like run and also can use custom functions to create a fluent API

    DSL builders in Kotlin can leverage scope functions (such as apply, with, also, let, and run) to create a fluent and readable API. They can also define custom functions and use builder patterns to structure the DSL in a way that is idiomatic and easy to use. This allows for a more natural and expressive syntax when constructing domain-specific languages.

  3. Consider the following code snippet: `flowOf(1, 2, 3).filter { it % 2 == 0 }.map { it * 2 }`. What is the likely issue with this code that prevents the Flow from emitting any values?

    1. The Flow is being collected, but the filter and map operators are not applied in the correct order.
    2. The Flow is not being collected correctly, leading to no emissions.
    3. The Flow is being collected, but the filter and map operators are not properly chained.
    4. The Flow is being collected, but the filter and map operators are not compatible with the data type.

    Answer: B. The Flow is not being collected correctly, leading to no emissions.

    The Flow is not being collected because the collect() function is not called on the transformed Flow. The filter and map operators are applied correctly, but without collecting the Flow, the transformations will not have any effect. The correct approach would be to call collect() on the Flow after applying the transformations.

  4. Which of the following statements correctly describes the distinction between Flow and Channel in Kotlin coroutines?

    1. A Flow is a cold stream, while a Channel is a hot stream.
    2. Both Flow and Channel are cold streams.
    3. A Flow is a hot stream, while a Channel is a cold stream.
    4. Both Flow and Channel are hot streams.

    Answer: A. A Flow is a cold stream, while a Channel is a hot stream.

    A Flow is a cold stream, meaning it only emits values when there is a subscriber, and it does not retain any state. A Channel, on the other hand, is a hot stream, meaning it can retain values and send them to new subscribers even if they join after the values have been emitted. This distinction is crucial in Kotlin coroutines for managing data streams.

  5. What is the key distinction between Flow operator chaining and using Channels for data processing in Kotlin coroutines, and when is Flow more appropriate?

    1. Flow operator chaining provides synchronous data processing, whereas Channels offer asynchronous handling, making Flow more appropriate for high-performance applications.
    2. Flow operator chaining is less efficient than using Channels for data stream processing, making Channels the preferred choice in most scenarios.
    3. Flow operator chaining is used exclusively for synchronous data processing, whereas Channels are used for asynchronous data processing, making them suitable for different use cases.
    4. Flow operator chaining allows for declarative, asynchronous data processing with backpressure support, whereas using a Channel requires manual management of sending and receiving operations, making Flow more suitable for reactive, pipeline-based data streams.

    Answer: D. Flow operator chaining allows for declarative, asynchronous data processing with backpressure support, whereas using a Channel requires manual management of sending and receiving operations, making Flow more suitable for reactive, pipeline-based data streams.

    Flow operator chaining is designed for asynchronous, reactive data processing with built-in backpressure handling. It abstracts away the complexity of managing data flow manually, which is required when using Channels. Flow is ideal for scenarios involving continuous data streams, such as UI updates or network data, while Channels are better suited for direct, low-level communication between coroutines.

Frequently asked questions

How many questions are in the Advanced Kotlin test?
40 questions (24 multiple choice, 12 multi-answer, 4 predict-the-output), with 40 minutes to answer them.
What does the Advanced Kotlin test cover?
Coroutine scopes and structured concurrency, Flow and channels, Inline and reified, DSL builders, Android and Ktor architecture.
Is the Advanced Kotlin test free?
Yes. It is free to take with a readyforhires account.
What level is the Advanced Kotlin test?
Advanced, in Backend.

More Backend tests

Roles that test these skills

Companies that test these skills

All practice tests · All Backend tests

Last updated