This document outlines the schedule and content for a Compose Camp. The camp will cover introductory Kotlin topics like variables, functions, conditionals, and null safety over 4 sessions from October 11-14, 2022. Session topics include an intro to Kotlin, building a birthday card app, a dice roller app, and a calculator app. The document provides code examples for variables, functions, if/else statements, when expressions, nullability, and repeat functions. Camp leaders include Kaustubh Narwade, Sujal Goswami, and Rishabh Sachan.
3. This work is licensed under the Apache 2.0 License
Kaustubh Narwade
GitHub
Camp leaders
Sujal Goswami
GitHub
Rishabh Sachan
GitHub
4. This work is licensed under the Apache 2.0 License
Camp Schedule
TOPIC TIME
Intro (Online) 0:00 - 0:00
Birthday Wish Card App (Offline) 0:00 - 0:00
Dice Roller App (Offiline) 0:00 - 0:00
Calculator (Online) 0:00 - 0:00
Sessions Date
Intro Session | Compose Camp 11th October, 2022
Birthday Wish Card App 12th October, 2022
Dice Roller App 13th October, 2022
Calculator App 14th October, 2022
5. This work is licensed under the Apache 2.0 License
Recap
● Variables
● functions
● Android Studio
● Birthday wish card
6. This work is licensed under the Apache 2.0 License
Recap
● Conditionals
● When statement
● Nullability
● Function types
● Repeat function
● Dice Roller App
7. This work is licensed under the Apache 2.0 License
8. This work is licensed under the Apache 2.0 License
Variables
fun main() {
val cartTotal = 0
cartTotal = 20
println("Total: $cartTotal")
}
Val cannot be reassignd
fun main() {
var cartTotal = 0
cartTotal = 20
println("Total: $cartTotal")
}
9. This work is licensed under the Apache 2.0 License
Functions
10. This work is licensed under the Apache 2.0 License
Use if/else statements to express conditions
11. This work is licensed under the Apache 2.0 License
When statement
12. This work is licensed under the Apache 2.0 License
fun main() {
val x: Any = 20
when (x) {
2, 3, 5, 7 -> println("x is a prime number between 1 and 10.")
in 1..10 -> println("x is a number between 1 and 10, but not a prime number.")
is Int -> println("x is an integer number, but not between 1 and 10.")
else -> println("x isn't an integer number.")
}
}
Some Keywords
13. This work is licensed under the Apache 2.0 License
if/else & when as
expressions
fun main() {
val trafficLightColor = "Black"
val message =
if (trafficLightColor == "Red") "Stop"
else if (trafficLightColor == "Yellow") "Slow"
else if (trafficLightColor == "Green") "Go"
else "Invalid traffic-light color"
println(message)
}
fun main() {
val trafficLightColor = "Amber"
val message = when(trafficLightColor) {
"Red" -> "Stop"
"Yellow", "Amber" -> "Proceed with caution."
"Green" -> "Go"
else -> "Invalid traffic-light color"
}
println(message)
}
14. This work is licensed under the Apache 2.0 License
Nullability
In Kotlin, there's a distinction between nullable and non-nullable types:
•Nullable types are variables that can hold null.
•Non-null types are variables that can't hold null.
15. This work is licensed under the Apache 2.0 License
Handle nullable variables
• Use the ?. safe-call operator fun main() {
var favoriteActor: String? = "Sandra Oh"
println(favoriteActor?.length)
}
• Use the ?: Elvis operator
fun main() {
val favoriteActor: String? = "Sandra Oh"
val lengthOfName = favoriteActor?.length ?: 0
println("The number of characters in your
favorite actor's name is $lengthOfName.")
}