KOTLIN / NOTES</>↗Kotlin08 May 2025
In Kotlin, the when expression can be used as an alternative to the traditional switch statement found in languages like Java. The when expression is versatile, concise, and supports a wide range of matching conditions. Here’s how you can use it: Examples of Using the when Expression Using when as a simple switch: fun getResponse(code: […]
CONCURRENCY / NOTES</>↗Concurrency08 May 2025
To throttle concurrent threads using ThreadPoolExecutor settings in Java, you can configure its key parameters: core pool size, maximum pool size, and queue capacity. These settings control how ThreadPoolExecutor manages the number of concurrently running threads and queued tasks. Explanation of Key ThreadPoolExecutor Settings: Core Pool Size: This defines the number of threads that are […]
CONCURRENCY / NOTES</>↗Concurrency07 May 2025
To process tasks as they complete using a CompletionService in Java, you can take advantage of the ExecutorCompletionService. This class provides a mechanism to submit tasks for execution and retrieve their results in the order of completion, rather than the order of submission. Key Steps for Using CompletionService: Create an ExecutorService: This handles the thread […]
CONCURRENCY / NOTES</>↗Concurrency07 May 2025
To cancel long-running tasks in an ExecutorService, you can use the Future object returned when you submit a task and invoke its cancel method. Below are the steps and some important considerations for canceling tasks: 1. Submit Tasks to the ExecutorService When you submit a task to an ExecutorService, it returns a Future object that […]
KOTLIN / NOTES</>↗Kotlin06 May 2025
In Kotlin, you can use default arguments and named arguments to simplify function calls and make your code more readable and flexible. Here’s how each of them works: Default Arguments Default arguments allow you to set a default value for a function parameter. If you don’t pass a value for that parameter when calling the […]
KOTLIN / NOTES</>↗Kotlin06 May 2025
In Kotlin, defining and calling functions is straightforward and follows a clear syntax. Here’s how you can define and use functions: Defining a Function The fun keyword is used to define a function in Kotlin. Basic Syntax: fun functionName(parameters: ParameterType): ReturnType { // Function body return someValue // Optional if the return type is Unit […]