Kotlin Language Essentials for Android
var vs val, null safety, data classes, when expressions, extension functions, scope functions and fundamental Kotlin concepts
1What is the difference between 'var' and 'val' in Kotlin?
What is the difference between 'var' and 'val' in Kotlin?
Answer
'var' declares a mutable (modifiable) variable, while 'val' declares an immutable (read-only) variable. It's recommended to use 'val' by default to promote immutability and avoid bugs.
2What does the '?' operator after a type mean in Kotlin?
What does the '?' operator after a type mean in Kotlin?
Answer
The '?' operator indicates that the variable can contain null. For example, 'String?' means the variable can be a String or null. This is the basis of Kotlin's null safety system.
3What does the '!!' operator do in Kotlin?
What does the '!!' operator do in Kotlin?
Answer
The '!!' operator (not-null assertion) forces the compiler to treat a nullable value as non-null. If the value is null, a NullPointerException is thrown. Only use when you're certain the value is not null.
What is the Elvis operator '?:' used for in Kotlin?
What is a data class in Kotlin?
+21 interview questions
Other Android interview topics
Android Fundamentals
Android UI and Resources
Android Lifecycle
Android Navigation
Android Data Management
Android Networking
Android Testing
Android Gradle
Room Database
Background Work
Jetpack Compose
Permissions and Device Features
Firebase for Android
Android MVVM Architecture
Advanced Android Networking
Kotlin Collections and Operators
Kotlin Coroutines and Flow
Android Dependency Injection
Android MVI Architecture
Android Clean Architecture
Android Compose Advanced
Android Performance and Monitoring
Android Security and Privacy
Android CI/CD and Release
Android UX and Form Factors
Android Testing Advanced
Master Android for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free