FlashKeepers

Kotlin · College · College and University

Kotlin I: Basics and Null Safety

Kotlin val and var, types, string templates, nullable types, safe calls, the elvis operator, when and control flow.

About this set

40 basic cards for College Kotlin. Set 1 of 4 in Kotlin. It opens with "What is the difference between val and var in Kotlin?" and "Does Kotlin require explicit type declarations for variables?". Study it alongside the other College sets below.

40 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What is the difference between val and var in Kotlin?
Show answerval is immutable (read-only), var is mutable (can be reassigned)
Does Kotlin require explicit type declarations for variables?
Show answerNo, Kotlin can infer types from the assigned value, though explicit types are allowed
What is the default integer type in Kotlin?
Show answerInt, which is a 32-bit signed integer
How do you declare a String variable in Kotlin?
Show answerUse the String type, e.g., val name: String = "Alice", or let the compiler infer it
What values can a Boolean variable hold in Kotlin?
Show answerOnly true or false
What is the syntax for inserting a variable inside a string template?
Show answerUse $variableName, e.g., "Hello $name"
How do you evaluate an expression inside a string template?
Show answerWrap it in curly braces: ${expression}, e.g., "The answer is ${2 + 2}"
How do you print a literal dollar sign in a string template?
Show answerUse a backslash to escape it: \$, e.g., "Cost is \$100"
How do you declare a variable that can hold null in Kotlin?
Show answerAdd a question mark after the type: Type?, e.g., val x: Int? = null
What is the default for a variable type in Kotlin if no question mark is added?
Show answerNon-nullable, meaning it cannot hold null and must be initialized with a value
Why does Kotlin require explicit nullable types?
Show answerTo prevent null pointer exceptions by making nullability explicit and forcing you to handle null cases
What is the syntax for the safe call operator in Kotlin?
Show answer?. (question mark followed by a dot), e.g., obj?.method()
What does the safe call operator do when the object is null?
Show answerIt returns null instead of throwing a null pointer exception
What happens when you use ?. on an object that is not null?
Show answerThe method or property is called normally and the result is returned
What is the symbol for the elvis operator in Kotlin?
Show answer?: (question mark followed by colon)

25 more cards in the app

Study this set free