KOTLIN / NOTES</>↗Kotlin03 Jul 2026
In Kotlin, use async to start concurrent work inside a coroutine scope, then call await() to get each result. Basic example: import kotlinx.coroutines.* suspend fun fetchUser(): String { delay(1000) return "User" } suspend fun fetchPosts(): List<String> { delay(1000) return listOf("Post 1", "Post 2") } fun main() = runBlocking { val userDeferred = async { fetchUser() […]
KOTLIN / NOTES</>↗Kotlin03 Jul 2026
In Kotlin, a suspend function is declared with the suspend modifier. suspend fun fetchUser(): User { // Can call other suspend functions here return api.getUser() } A suspend function can pause without blocking the thread and later resume. It is commonly used with coroutines for asynchronous work. Example: import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking suspend fun greetAfterDelay() […]
KOTLIN / NOTES</>↗Kotlin03 Jul 2026
Use kotlinx.coroutines.delay(…) inside a coroutine instead of Thread.sleep(…). Thread.sleep blocks the current thread. delay suspends the coroutine without blocking the thread, so other coroutines can keep running. import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking fun main() = runBlocking { println("Before delay") delay(1_000) // suspends for 1 second, does not block the thread println("After delay") } If you currently […]
KOTLIN / NOTES</>↗Kotlin03 Jul 2026
In Kotlin, you can use runBlocking to start a coroutine scope that blocks the current thread until its coroutines finish, and launch to start a new coroutine inside that scope. import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking fun main() = runBlocking { launch { println("Coroutine is running") } println("Main coroutine continues") } Output may look like: Main coroutine […]
SPRING / NOTES</>↗Spring02 Jul 2026
External configuration means keeping settings such as application names, URLs, ports, feature flags, credentials, or environment-specific values outside your Java code. Spring supports this mainly through: application.properties application.yml environment variables command-line arguments external property files @Value @ConfigurationProperties 1. Using application.properties In a Spring or Spring Boot application, you can place configuration in: src/main/resources/application...
SPRING / NOTES</>↗Spring02 Jul 2026
In Spring, bean scope controls how many instances of a bean Spring creates and how long those instances live. By default, Spring beans are singleton scoped, meaning Spring creates one shared instance per ApplicationContext. Common Spring Bean Scopes Scope Meaning singleton One shared instance per Spring container prototype A new instance every time the bean […]