INFO5126 Quiz #1 Flashcards

1
Q

Who developed Kotlin?

A

JetBrains

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does Kotlin compile to native code?

A

LLVM

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the 5 reasons to use Kotlin? (Can’t Sell In The Nude)

A
  1. Concise
  2. Safe
  3. Interoperable
  4. Tool Friendly
  5. No checked exceptions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why is Kotlin considered safe?

A

Avoids entire classes of errors like Null Pointer Exception

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which keyword is used for read only variables?

A

val

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which keyword is used for mutable variables?

A

var

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you perform string interpolation?

A

$ and { }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you test that two variables refer to the same object?

A

===

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What keyword is used for switch statements?

A

when

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the Elvis operator?

A

?:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What operator is used to return the non-null type value and throw an exception if the value is null?

A

!!
val l = b!!.length

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What operator returns the expression on the left if not null and the expression on the right if null?

A

?:
val l = b?.length ?: 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you filter out non-null elements from a collection of Nullable type?

A

filterNotNull()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What function instantiates an immutable list?

A

listOf()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What function instantiates a mutable list?

A

mutableListOf()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What keyword is used to declare a function?

A

fun

17
Q

Class member functions are ________

A

virtual

18
Q

Class members are ________ by default

A

public

19
Q

Classes are ________ by default

A

final

20
Q

If a class member is not initialized during construction what keyword do you use to initialize it?

A

lateinit

21
Q

What keyword is used to create a Singleton?

A

object

22
Q

What keyword is used for static methods?

A

companion

23
Q

What is view binding a subset of?

A

Data Binding

24
Q

In most cases view binding replaces what function?

A

findViewById()

25
Q

What file do you change to enable view binding?

A

Gradle Module

26
Q

What function is used with view binding to give direct reference to the root view of the corresponding layout file?

A

getRoot()

27
Q

What does ViewBinding change the IDs of the XML layout file to?

A

camelCase

28
Q

What library did we use for JSON with Kotlin?

A

GSON

29
Q

What kind of class should you use when working with JSON?

A

data

30
Q

What keyword should you use to make data class field names different from the JSON names?

A

@SerializedName(“key_name”)

31
Q

How do you parse a class object into JSON using GSON?

A

Gson().toJson(Object)