Compose Camp
Android Basics with Compose:
Unit 1
D S S Lakshmana Reddy
This work is licensed under the Apache 2.0 License
What is Compose Camp?
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
Prerequisites
● Basic computer literacy
● Basic math skills
● Computer & headphones
● Internet connection
● Android Studio
This work is licensed under the Apache 2.0 License
Compose Camp Learning Objectives
● 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
1. Why are you here?
2. What are you goals?
3. How do you plan to achieve them?
This work is licensed under the Apache 2.0 License
Who would like to share?
This work is licensed under the Apache 2.0 License
This work is licensed under the Apache 2.0 License
g.co/android/basics-compose
Start here:
Android Basics
with Compose Course
This work is licensed under the Apache 2.0 License
Unit 1: Your first Android
App
This work is licensed under the Apache 2.0 License
A Pathway
This work is licensed under the Apache 2.0 License
Take a Quiz
This work is licensed under the Apache 2.0 License
Earn badges!
This work is licensed under the Apache 2.0 License
Google Developer Profile
This work is licensed under the Apache 2.0 License
Carrie Sawyer
Session Overview
This work is licensed under the Apache 2.0 License
Kotlin Programming Language
Use Kotlin to start writing Android apps.
Kotlin helps developers be more
productive.
This work is licensed under the Apache 2.0 License
Kotlin Playground
Write and run Kotlin code in
the browser.
This work is licensed under the Apache 2.0 License
Output:
Hello, world!
Program
A series of instructions for a
computer to perform some action.
This work is licensed under the Apache 2.0 License
fun main() {
println("Hello, world!")
}
Output:
Hello, world!
Code
Step by step instructions for what
the computer should do.
This work is licensed under the Apache 2.0 License
fun main() {
println("Hello, world!")
}
main Function
The main function is the entry
point, or starting point, of the
program.
Start here
This work is licensed under the Apache 2.0 License
Output:
Hello, world!
fun main() {
println("Hello, world!")
}
Variables
A container for a single piece of data.
This work is licensed under the Apache 2.0 License
Variables
name age
My name is and I am
years old
This work is licensed under the Apache 2.0 License
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
Variables
name age
My name is and I am years old
This work is licensed under the Apache 2.0 License
Basic data types
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
This work is licensed under the Apache 2.0 License
Defining a variable
This work is licensed under the Apache 2.0 License
var keyword
Use when you expect the variable value can
change.
Example: age
val keyword
Use when you expect the variable value will
not change.
Example: name
Defining a variable
Variables start with a var or val
keyword.
This work is licensed under the Apache 2.0 License
fun main() {
val name: String = "Meghan"
var age: Int = 28
}
Defining a variable
All variables must have a name.
This work is licensed under the Apache 2.0 License
fun main() {
val name: String = "Meghan"
var age: Int = 28
}
Defining a variable
Data type is the type of data
that the variable holds.
This work is licensed under the Apache 2.0 License
fun main() {
val name: String = "Meghan"
var age: Int = 28
}
Defining a variable
The initial value is the value that
is stored in the variable.
This work is licensed under the Apache 2.0 License
fun main() {
val name: String = "Meghan"
var age: Int = 28
}
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.
Defining a function
Functions begin with the fun
keyword.
This work is licensed under the Apache 2.0 License
fun displayIntroduction() {
}
Defining a function
Functions have a name so that
they can be called.
This work is licensed under the Apache 2.0 License
fun displayIntroduction() {
}
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
fun displayIntroduction() {
}
Defining a function
The curly braces make up the
function body and contain the
instructions needed to execute
a task.
This work is licensed under the Apache 2.0 License
fun displayIntroduction() {
}
Output:
Hi I’m Meghan and I am 28 years old
fun displayIntroduction() {
// We will fill this out!
}
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")
}
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
This work is licensed under the Apache 2.0 License
Putting it together
Returning in a function
We can return an output from a
function as per its defined output
datatype.
This work is licensed under the Apache 2.0 License
fun displayIntroduction() : String {
return “HelloWorld”;
}
Parameters of a function
We can pass extra information into
a function via parameters which
are declared between the
parentheses.
This work is licensed under the Apache 2.0 License
fun add(n1 : Int, n2 : Int) {
return n1 + n2
}
Parameters of a function
These parameters can also have
default values.
This work is licensed under the Apache 2.0 License
fun add(n1 : Int = 0, n2 : Int = 0) {
return n1 + n2
}
Arguments of a function
While calling a function in another
function, the values we pass to the
parameters defined are known as
Arguments.
This work is licensed under the Apache 2.0 Licens
fun main() {
var a : Int = 2
var b : Int = 3
println(add(a, b))
}
Welcome back
And congrats on learning Kotlin Basics!
This work is licensed under the Apache 2.0 License
This work is licensed under the Apache 2.0 License
Unit 1: Pathway 1
This work is licensed under the Apache 2.0 License
Have a Question? Just ask
Work on Unit 1, Pathway 1
This work is licensed under the Apache 2.0 License
What’s coming next:
This work is licensed under the Apache 2.0 License
#ComposeCamp
Share what you’ve
learned using
on social media
For a chance to be
featured by Android,
submit your tips on
learning Compose to
goo.gle/compose-tips
This work is licensed under the Apache 2.0 License
Optional resources to check out:
● Official Android Developers Site: developer.android.com
● Official Android Developers Blog (for announcements)
● Android Developers Medium Blog (for more technical articles)
● Android Developers YouTube channel
● Follow @AndroidDev on Twitter
● Follow @AndroidDev on LinkedIn
● Subscribe to the Android Developer Newsletter
See you at the next Compose Camp Session!
This work is licensed under the Apache 2.0 License

day1.docx

  • 1.
    Compose Camp Android Basicswith Compose: Unit 1 D S S Lakshmana Reddy This work is licensed under the Apache 2.0 License
  • 2.
    What is ComposeCamp? 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
  • 3.
    Prerequisites ● Basic computerliteracy ● Basic math skills ● Computer & headphones ● Internet connection ● Android Studio This work is licensed under the Apache 2.0 License
  • 4.
    Compose Camp LearningObjectives ● 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
  • 5.
    1. Why areyou here? 2. What are you goals? 3. How do you plan to achieve them? This work is licensed under the Apache 2.0 License
  • 6.
    Who would liketo share? This work is licensed under the Apache 2.0 License
  • 7.
    This work islicensed under the Apache 2.0 License g.co/android/basics-compose Start here:
  • 8.
    Android Basics with ComposeCourse This work is licensed under the Apache 2.0 License
  • 9.
    Unit 1: Yourfirst Android App This work is licensed under the Apache 2.0 License
  • 10.
    A Pathway This workis licensed under the Apache 2.0 License
  • 11.
    Take a Quiz Thiswork is licensed under the Apache 2.0 License
  • 12.
    Earn badges! This workis licensed under the Apache 2.0 License
  • 13.
    Google Developer Profile Thiswork is licensed under the Apache 2.0 License Carrie Sawyer
  • 14.
    Session Overview This workis licensed under the Apache 2.0 License
  • 16.
    Kotlin Programming Language UseKotlin to start writing Android apps. Kotlin helps developers be more productive. This work is licensed under the Apache 2.0 License
  • 17.
    Kotlin Playground Write andrun Kotlin code in the browser. This work is licensed under the Apache 2.0 License
  • 18.
    Output: Hello, world! Program A seriesof instructions for a computer to perform some action. This work is licensed under the Apache 2.0 License fun main() { println("Hello, world!") }
  • 19.
    Output: Hello, world! Code Step bystep instructions for what the computer should do. This work is licensed under the Apache 2.0 License fun main() { println("Hello, world!") }
  • 20.
    main Function The mainfunction is the entry point, or starting point, of the program. Start here This work is licensed under the Apache 2.0 License Output: Hello, world! fun main() { println("Hello, world!") }
  • 21.
    Variables A container fora single piece of data. This work is licensed under the Apache 2.0 License
  • 22.
    Variables name age My nameis and I am years old This work is licensed under the Apache 2.0 License
  • 23.
    Name value: Meghan Agevalue: 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 Variables name age My name is and I am years old This work is licensed under the Apache 2.0 License
  • 24.
    Basic data types KotlinData 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 This work is licensed under the Apache 2.0 License
  • 25.
    Defining a variable Thiswork is licensed under the Apache 2.0 License var keyword Use when you expect the variable value can change. Example: age val keyword Use when you expect the variable value will not change. Example: name
  • 26.
    Defining a variable Variablesstart with a var or val keyword. This work is licensed under the Apache 2.0 License fun main() { val name: String = "Meghan" var age: Int = 28 }
  • 27.
    Defining a variable Allvariables must have a name. This work is licensed under the Apache 2.0 License fun main() { val name: String = "Meghan" var age: Int = 28 }
  • 28.
    Defining a variable Datatype is the type of data that the variable holds. This work is licensed under the Apache 2.0 License fun main() { val name: String = "Meghan" var age: Int = 28 }
  • 29.
    Defining a variable Theinitial value is the value that is stored in the variable. This work is licensed under the Apache 2.0 License fun main() { val name: String = "Meghan" var age: Int = 28 }
  • 30.
    Functions A function isa segment of a program that performs a specific task. You can have many functions in your program or only a single one.
  • 31.
    Defining a function Functionsbegin with the fun keyword. This work is licensed under the Apache 2.0 License fun displayIntroduction() { }
  • 32.
    Defining a function Functionshave a name so that they can be called. This work is licensed under the Apache 2.0 License fun displayIntroduction() { }
  • 33.
    Defining a function Functionsneed 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 fun displayIntroduction() { }
  • 34.
    Defining a function Thecurly braces make up the function body and contain the instructions needed to execute a task. This work is licensed under the Apache 2.0 License fun displayIntroduction() { }
  • 35.
    Output: Hi I’m Meghanand I am 28 years old fun displayIntroduction() { // We will fill this out! } Putting it together This work is licensed under the Apache 2.0 License
  • 36.
    fun displayIntroduction() { valname : String = "Meghan" val age : Int = 28 println("Hi I'm $name and I am $age years old") } Putting it together This work is licensed under the Apache 2.0 License
  • 37.
    fun main() { displayIntroduction() } fundisplayIntroduction() { 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 This work is licensed under the Apache 2.0 License Putting it together
  • 38.
    Returning in afunction We can return an output from a function as per its defined output datatype. This work is licensed under the Apache 2.0 License fun displayIntroduction() : String { return “HelloWorld”; }
  • 39.
    Parameters of afunction We can pass extra information into a function via parameters which are declared between the parentheses. This work is licensed under the Apache 2.0 License fun add(n1 : Int, n2 : Int) { return n1 + n2 }
  • 40.
    Parameters of afunction These parameters can also have default values. This work is licensed under the Apache 2.0 License fun add(n1 : Int = 0, n2 : Int = 0) { return n1 + n2 }
  • 41.
    Arguments of afunction While calling a function in another function, the values we pass to the parameters defined are known as Arguments. This work is licensed under the Apache 2.0 Licens fun main() { var a : Int = 2 var b : Int = 3 println(add(a, b)) }
  • 42.
    Welcome back And congratson learning Kotlin Basics! This work is licensed under the Apache 2.0 License
  • 43.
    This work islicensed under the Apache 2.0 License
  • 44.
    Unit 1: Pathway1 This work is licensed under the Apache 2.0 License
  • 45.
    Have a Question?Just ask Work on Unit 1, Pathway 1 This work is licensed under the Apache 2.0 License
  • 46.
    What’s coming next: Thiswork is licensed under the Apache 2.0 License
  • 47.
    #ComposeCamp Share what you’ve learnedusing on social media For a chance to be featured by Android, submit your tips on learning Compose to goo.gle/compose-tips This work is licensed under the Apache 2.0 License
  • 48.
    Optional resources tocheck out: ● Official Android Developers Site: developer.android.com ● Official Android Developers Blog (for announcements) ● Android Developers Medium Blog (for more technical articles) ● Android Developers YouTube channel ● Follow @AndroidDev on Twitter ● Follow @AndroidDev on LinkedIn ● Subscribe to the Android Developer Newsletter See you at the next Compose Camp Session! This work is licensed under the Apache 2.0 License