1. This work is licensed under the Apache 2.0 License
Compose Camp
Android Basics with Compose:
Unit 1
Nishant Khandhar
2. Compose Camp is a hands-on introduction to
learning how you can build Android apps with
Jetpack Compose.
This work is licensed under the Apache 2.0 License
What is Compose Camp?
3. ● Basic computer literacy
● Basic math skills
● Computer & headphones
● Internet connection
● Android Studio
This work is licensed under the Apache 2.0 License
Prerequisites
4. ● Build your first Android apps
● Set up Android Studio on your computer
● Learn the basics of the Kotlin programming language
● Learn Jetpack Compose
● Discover resources to continue learning
This work is licensed under the Apache 2.0 License
Compose Camp Learning Objectives
5. This work is licensed under the Apache 2.0 License
INDEX
1. Introduction to Kotlin Playground.
2. Variables and Data types.
3. Functions in Kotlin.
4. Quiz
6. Kotlin Playground
This work is licensed under the Apache 2.0 License
Write and run Kotlin code in
the browser.
7. In computer programming, there's the
concept of a variable, which is a
container for a single piece of data.
You can envision it as a box that
contains a value. The box has a label,
which is the name of the variable. By
referring to the box by its name, you
have access to the value it holds.
This work is licensed under the Apache 2.0 License
Variables
9. Variable
s
Name value: Meghan
Age value: 28
Output:
My name is Meghan and
I am 28 years old
Name value: Janet
Age value: 49
Output:
My name is Janet and I
am 49 years old
name age
My name is and I am years old
This work is licensed under the Apache 2.0 License
10. Basic data types
This work is licensed under the Apache 2.0 License
Kotlin Data type What kind of data it can contain Example literal values
String Text
“Add contact”
“Search”
Int Whole integer number
32
-59873
Double Decimal number
2.0
-37123.9999
Float
Decimal number (less precise than a Double).
Has an f or F at the end of the number.
5.0f
-1630.209f
Boolean
true or false. Use this data type when there
are only two possible values.
true
false
11. val keyword
This work is licensed under the Apache 2.0 License
Use when you expect the variable value will
not change.
Example: name
var keyword
Use when you expect the variable value can
change.
Example: age
Defining a variable
Use the assignment operator (=) to
assign a value to a variable either
during declaration of the variable or
updating the variable.
12. Defining a variable
Variables start with a var or
val
keyword.
fun main() {
val name: String = "Meghan"
var age: Int = 28
}
This work is licensed under the Apache 2.0 License
13. Defining a variable
All variables must have a name.
fun main() {
val name: String = "Meghan"
var age: Int = 28
}
This work is licensed under the Apache 2.0 License
14. Defining a variable
Data type is the type of data
that the variable holds.
fun main() {
val name: String = "Meghan"
var age: Int = 28
}
This work is licensed under the Apache 2.0 License
15. Defining a variable
The initial value is the value that
is stored in the variable.
fun main() {
val name: String = "Meghan"
var age: Int = 28
}
This work is licensed under the Apache 2.0 License
16. Functions
A function is a segment of a program that
performs a specific task.
You can have many functions in your program
or only a single one.
The main() function doesn’t actually get called
anywhere in your code; the Kotlin compiler uses
it as a starting point.
17. Defining a function
Functions begin with the fun
keyword followed by
function name and
parentheses and curly
braces.
fun namer () {
}
This work is licensed under the Apache 2.0 License
fun main() {
println(“Hello World”)
}
fun helloWorld () {
}
18. Defining a function
Functions have a name so that
they can be called.
fun displayIntroduction() {
}
This work is licensed under the Apache 2.0 License
19. fun helloWorld () {
println(“Happy Birthday, Alex”)
println(“You are now 20 years old”)
}
Defining a function
Functions need a set of parentheses
after the function name in order to
surround the function inputs.
This work is licensed under the Apache 2.0 License
20. Defining a function
The curly braces make up the
function body and contain the
instructions needed to execute
a task.
fun displayIntroduction() {
}
This work is licensed under the Apache 2.0 License
21. Putting it together
fun displayIntroduction() {
// We will fill this out!
}
This work is licensed under the Apache 2.0 License
Output:
Hi I’m Meghan and I am 28 years old
22. Putting it together
This work is licensed under the Apache 2.0 License
fun displayIntroduction() {
val name : String = "Meghan"
val age : Int = 28
println("Hi I'm $name and I am $age years old")
}
23. Putting it together
This work is licensed under the Apache 2.0 License
fun main() {
displayIntroduction()
}
fun displayIntroduction() {
val name : String = "Meghan"
val age : Int = 28
println("Hi I'm $name and I am $age years old")
}
Output:
Hi I’m Meghan and I am 28 years old
24. Returning in a function
We can return an output from a
function as per its defined output
datatype.
fun displayIntroduction() : String {
return “HelloWorld”;
}
This work is licensed under the Apache 2.0 License
25. Parameters of a function
We can pass extra information into
a function via parameters which
are declared between the
parentheses.
fun add(n1 : Int, n2 : Int) {
return n1 + n2
}
This work is licensed under the Apache 2.0 License
26. Parameters of a function
These parameters can also have
default values.
fun add(n1 : Int = 0, n2 : Int = 0) {
return n1 + n2
}
This work is licensed under the Apache 2.0 License
27. Arguments of a function
While calling a function in another
function, the values we pass to the
parameters defined are known as
Arguments.
fun main() {
var a : Int = 2
var b : Int = 3
println(add(a, b))
}
This work is licensed under the Apache 2.0 License
28. Work on Unit 1, Pathway 1
This work is licensed under the Apache 2.0 License
Have a Question? Just ask