Questions
Kotlin questions
Choose a question page, learn the concept, then test your understanding with a quiz.
Kotlin Secondary Constructors: Syntax, Delegation, and Examples
Learn how to declare Kotlin secondary constructors, delegate to a primary constructor, validate inputs, and avoid common syntax mistakes.
Kotlin Spread Operator (*) Before an Array Variable
Learn how Kotlin’s spread operator (*) expands an array into vararg arguments, why SpringApplication.run uses it, and how to avoid common mistakes.
Kotlin String Formatting: Format Numbers in String Templates
Learn how to format numbers in Kotlin string templates, including limiting decimal places for Double values with practical examples.
Kotlin Ternary Conditional Operator Equivalent Explained
Learn the Kotlin equivalent of the ternary conditional operator and how to use if as an expression with clear examples.
Kotlin Void vs Unit vs Nothing: Differences, Uses, and Examples
Learn the difference between Kotlin Void, Unit, and Nothing with clear examples, return type rules, and practical usage patterns.
Kotlin and JPA Entities: Default Constructors, Immutability, and Practical Patterns
Learn how Kotlin works with JPA entities, why no-arg constructors matter, and how to handle nullability, immutability, and Hibernate safely.
Kotlin const vs val: What’s the Difference?
Learn the difference between const and val in Kotlin, when to use each, and common mistakes with clear examples.
Kotlin init Blocks vs Constructors: Differences and Usage
Learn the difference between Kotlin constructors and init blocks, their initialization order, validation patterns, and practical class examples.
Kotlin switch-case Equivalent: Using when Expression
Learn how to replace Java switch-case in Kotlin using when, with syntax, examples, common mistakes, and real-world usage.
Kotlin withContext vs async/await: Context Switching and Concurrency
Learn when Kotlin withContext is preferable to async/await, how dispatchers and Deferred work, and how to run coroutine tasks concurrently.
Make Kotlin Data Classes Parcelable in Android with @Parcelize
Learn how to make Kotlin data classes Parcelable in Android using @Parcelize, including setup, examples, supported types, and common pitfalls.
Mark Unused Callback Parameters in Kotlin
Learn how to suppress unused parameter warnings in Kotlin callbacks, use underscore lambda parameters, and keep callback code clear.
Open Android Settings Programmatically with Intents
Learn how to open Android system and app settings programmatically using Kotlin Intents, Settings actions, package URIs, and safe fallbacks.
Passing Functions as Parameters in Kotlin
Learn how to pass a function as a parameter in Kotlin using function references, lambdas, and matching function types.
Read an InputStream into a String in Kotlin
Learn the idiomatic Kotlin way to read an InputStream as a String, choose a charset, close resources safely, and preserve line breaks.
Replace systemUiVisibility with WindowInsetsController in Android Kotlin
Learn how to replace deprecated systemUiVisibility flags with WindowInsetsController and WindowInsetsControllerCompat in Android Kotlin.
Return Multiple Values from a Kotlin Function
Learn how Kotlin functions return multiple values with data classes, Pair, Triple, and destructuring declarations through practical examples.
Room Persistence Library Auto-Increment Primary Key in Kotlin
Learn how to create an auto-increment primary key in Room using Kotlin, with @PrimaryKey(autoGenerate = true) examples and common mistakes.
Single Exclamation Mark in Kotlin: Boolean Negation and Java Interop
Learn what a single ! means in Kotlin, how boolean negation works, and why it often appears when calling Java APIs.
Sort by Multiple Fields in Kotlin: sortedBy, thenBy, and compareBy
Learn how to sort a list by multiple fields in Kotlin using compareBy, thenBy, and sortedWith with clear examples and common pitfalls.