Look at the modifications needed in the GroceryItem Example in Exercise 2 of the April 22 Notes
to restore the data when the device is rotated.
Look at the ChineseHoroscope Example. This example shows how to dynamically add options to a
Spinner
widget. Here are the source code files: activity_main.xml MainActivity.js
How do you write a Kotlin main method with command line parameters? Answer:
fun main(args : Array<String>) {
// body of main method
}
What is the Kotlin range operators? (There are more than one.) Answer:
a..b -- range from a to b, inclusive on both ends
a..<b -- range from a to b, inclusive for a but exclusive for b.
a downTo b -- range from b to a, inclusive on both ends
What is the Unit datatype?
Answer: a function with Unit datatype can only return one value, also
called Unit. This name comes from Type theory and
functional programming.
What are the similarities and differences between Java and Kotlin that you have
seen so far? Answer: Similarities: Both compile to byte code that runs on the Java Virtual
Machine (JVM).
Both execute at similar speeds. Comments use same symbols in both languages ( //
or /* ... */ ) If statements and while loops are
written in the same way in both languages. Both languages are statically
typed and object oriented.
Differences:
Kotlin is more concise Java has several primitive datatypes, whereas all Kotlin datatypes are class
types.
Kotlin uses duck typing. Kotlin distinguishes between nullable and
non-nullable types. Kotlin has better support than Java for lambda functions.