Midterm Review Flashcards
What is the Android Manifest File?
The file which provides the OS with important information about the app including components, permissions, minimum API level, and other configurations
What is Val and Var?
Val - readonly/assign once
Var - mutable, can be changed/reassigned
How do you initialize and specify the type of a variable on the same line?
val characters: CharSequence = “abc”
How do you do string interpolation?
Using $ and { }
val name = “Anne”
val yearOfBirth = 1985
val yearNow = 2018
val message = “$name is ${yearNow - yearOfBirth} years old“
?
Null safety, used to set variables as nullable
!!
Returns non-null type value and throws exception if the value is null
?:
Elvis operator. Returns the expression to the left if not null, right if null
val l = b?.length ?: -1
Safe casting
val aInt: Int? = a as? Int
Null Filtering
Nullable collections can use filterNotNull() to filter out non-null elements
What is the When Statement?
Switch in Kotlin.
when (op) { "add" -> return a + b "subtract" -> return a - b "multiply" -> return a * b "divide" - > return a / b else -> throw Exception() }
What are companion objects?
An object declaration inside a class which allows you to define members that belong to the class itself rather than the instance, often used to hold static-like methods and properties that are accessible without creating an instance of the class (accessed via class name)
What is Lazy?
A property delegate that allows you to initialize a property only on access rather than time of object creation (lazy initialization)
val propertyName: Type by lazy { initializer }
What is a Data Class?
A special type of class primarily designed to hold data which automatically provides a set of standard functionalities
What are the Features of a Data Class?
Equals(), hashCode(), toString(), copy(), componentN()
What are Inner Classes?
Classes defined within another class using “inner” which have access to the instance of the outer class