This work is licensed under the Apache 2.0 License
Compose Camp
Android Basics with Compose
This work is licensed under the Apache 2.0 License
A Club of the students of CTAE,
by the students of CTAE and for
the students of CTAE.
● Vision:
○ To promote each and every field of programming through Competitions.
○ To Engage each and every member of the Club in Programming through
Development and Problem Solving.
○ To help students in Resume Building.
○ To promote programming in all the branches of CTAE.
This work is licensed under the Apache 2.0 License
● Global Community with people from different colleges
● To organize hackathons, open source events, tech podcasts, etc.
● Connections with colleges across the country
● Official Google supported community
This work is licensed under the Apache 2.0 License
Compose Camp is a hands-on introduction to
learning how you can build Android apps with
Jetpack Compose.
What is Compose Camp?
This work is licensed under the Apache 2.0 License
● Build your first Android apps
● Set up Android Studio on your computer
● Learn the basics of the Kotlin programming
language
Compose Camp Learning Objectives
This work is licensed under the Apache 2.0 License
Android Basics
with Compose Course
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 Programming
Language
A statically-typed language is a
language, where variable types are
known at compile time. Kotlin is a
statically-typed language.
This work is licensed under the Apache 2.0 License
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
How to Print
Print displays the next text on the
same line, while println display
the next text on the next line.
println("Hello")
print("Hello, world!")
Hello
Hello, world!
This work is licensed under the Apache 2.0 License
Program
A series of instructions for a
computer to perform some
action.
fun main() {
println("Hello, world!")
}
Output:
Hello, world!
This work is licensed under the Apache 2.0 License
Code
Step by step instructions for
what the computer should do.
fun main() {
println("Hello, world!")
}
Output:
Hello, world!
This work is licensed under the Apache 2.0 License
main Function
The main function is the entry
point, or starting point, of the
program.
Start here
fun main() {
println("Hello, world!")
}
Output:
Hello, world!
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.
This work is licensed under the Apache 2.0 License
Defining a function
Functions begin with the fun
keyword.
fun displayIntroduction() {
}
This work is licensed under the Apache 2.0 License
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
Defining a function
Functions need a set of parentheses
after the function name in order to
surround the function inputs.
fun displayIntroduction() {
}
This work is licensed under the Apache 2.0 License
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
A container for a single piece of data.
Variables
This work is licensed under the Apache 2.0 License
My name is and I am years old
Variables
Name variable: Athrav
Age variable: 19
Output:
My name is Athrav and I
am 19 years old
Name variable Age variable
Name variable: Subin
Age variable: 19
Output:
My name is Subin and I
am 19 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
val keyword
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
This work is licensed under the Apache 2.0 License
Defining a variable
Variables start with a var or val
keyword.
fun displayIntroduction() {
val name: String = "Athrav"
var age: Int = 19
}
This work is licensed under the Apache 2.0 License
Defining a variable
All variables must have a name.
fun displayIntroduction() {
val name: String = "Athrav"
var age: Int = 19
}
This work is licensed under the Apache 2.0 License
Defining a variable
Data type is the type of data
that the variable holds.
fun displayIntroduction() {
val name: String = "Athrav"
var age: Int = 19
}
This work is licensed under the Apache 2.0 License
Defining a variable
The initial value is the value that
is stored in the variable.
fun displayIntroduction() {
val name: String = "Athrav"
var age: Int = 19
}
This work is licensed under the Apache 2.0 License
Putting it together
fun displayIntroduction() {
val name = "Athrav"
val age = 28
println("Hi I'm $name and I am $age years old")
}
This work is licensed under the Apache 2.0 License
String Templates
fun displayIntroduction() {
val name = "Athrav"
val age = 19
println("Hi I'm $name and I am $age years old")
}
String Templates allows you to include variable references and
expressions into strings. A template expression starts with a dollar
sign ($) and consists of either a name:
This work is licensed under the Apache 2.0 License
Putting it together
fun main() {
displayIntroduction()
}
fun displayIntroduction() {
val name = "Athrav"
val age = 19
println("Hi I'm $name and I am $age years old")
}
Output:
Hi I’m Athrav and I am 19 years old
This work is licensed under the Apache 2.0 License
Functions with return
Statement
Function on calling perform the set of
instruction and at last return the value.
fun generateAnswerString(): String {
val answerString = if (count == 42) {
"I have the answer."
} else {
"The answer eludes me"
}
return answerString
}
This work is licensed under the Apache 2.0 License
Null Safety
For a variable to hold a null value,
it must be of a nullable type. You
can specify a variable as being
nullable by suffixing its type with
?
//fails to compile
Val name: String = null
//correct way
Val name: String? = null
This work is licensed under the Apache 2.0 License
Conditionals
Kotlin features several mechanisms for implementing conditional logic. The
most common of these is an if-else statement. If an expression wrapped in
parentheses next to an if keyword evaluates to true, then code within that
branch (i.e. the immediately-following code that is wrapped in curly braces)
is executed. Otherwise, the code within the else branch is executed.
This work is licensed under the Apache 2.0 License
Conditionals
if (count > 10) {
println("I have the answer.")
} else {a
println("The answer is close.")
}
If-else Ladder
if (count == 42) {
println("I have the answer.")
} else if (count > 35) {
println("The answer is close.")
} else {
println("The answer eludes me.")
}
If-else Ladder
val answerString: String = if (count == 42) {
"I have the answer."
} else if (count > 35) {
"The answer is close."
} else {
"The answer eludes me."
}
When Keyword
val answerString = when {
count == 42 -> "I have the answer."
count > 35 -> "The answer is close."
else -> "The answer eludes me."
}
// “when” keyword is used when the
complexity of Conditional statements
increases.
Loops:
for loop
The for loop iterates through anything
that provides an iterator.
for (item in collection) {
print(item)
}
Loops:
While loops
while and do-while loops execute their
body continuously while their
condition is satisfied. The difference
between them is the condition
checking time:
// while loop
while (x > 0) {
x--
}
// do-while loop
do {
x++
} while (x<10)
Jump Statements
Kotlin has three structural jump expressions:
return by default returns from the nearest
enclosing function or anonymous function.
break terminates the nearest enclosing loop.
continue proceeds to the next step of the
nearest enclosing loop.
This work is licensed under the Apache 2.0 License
Filter
fun main() {
val list = listOf(1,2,3,4,5)
var selecteditems = list.filter ({
it < 4
}).forEach({
println(it)
})
}
When filter() function is called with a predicate, it returns the
collection elements that match the predicate.
This work is licensed under the Apache 2.0 License
Map
fun main() {
val list = listOf(1,2,3,4,5)
var selecteditems = list.map ({
it * it
}).forEach({
println(it)
})
}
when it comes to transforming the elements in the list, Map plays a
vital role in that. Suppose we want to convert each element in the list
into the square of themselves:
This work is licensed under the Apache 2.0 License
Let
fun main() {
var str = "Hello World"
str.let {
println("$it!!")
}
println(str)
}
Kotlin let is a scoping function wherein the variables declared inside
the expression cannot be used outside.
fun main() {
var myName: String? = null
myName?.let {
println(myName)
}
}
This work is licensed under the Apache 2.0 License
So What’s Next…
This work is licensed under the Apache 2.0 License
Let’s Create Our First
Android App
This work is licensed under the Apache 2.0 License
Thank You

Compose Camp

  • 1.
    This work islicensed under the Apache 2.0 License Compose Camp Android Basics with Compose
  • 2.
    This work islicensed under the Apache 2.0 License A Club of the students of CTAE, by the students of CTAE and for the students of CTAE. ● Vision: ○ To promote each and every field of programming through Competitions. ○ To Engage each and every member of the Club in Programming through Development and Problem Solving. ○ To help students in Resume Building. ○ To promote programming in all the branches of CTAE.
  • 3.
    This work islicensed under the Apache 2.0 License ● Global Community with people from different colleges ● To organize hackathons, open source events, tech podcasts, etc. ● Connections with colleges across the country ● Official Google supported community
  • 4.
    This work islicensed under the Apache 2.0 License Compose Camp is a hands-on introduction to learning how you can build Android apps with Jetpack Compose. What is Compose Camp?
  • 5.
    This work islicensed under the Apache 2.0 License ● Build your first Android apps ● Set up Android Studio on your computer ● Learn the basics of the Kotlin programming language Compose Camp Learning Objectives
  • 6.
    This work islicensed under the Apache 2.0 License Android Basics with Compose Course
  • 7.
    This work islicensed under the Apache 2.0 License Kotlin Programming Language Use Kotlin to start writing Android apps. Kotlin helps developers be more productive.
  • 8.
    This work islicensed under the Apache 2.0 License Kotlin Programming Language A statically-typed language is a language, where variable types are known at compile time. Kotlin is a statically-typed language.
  • 9.
    This work islicensed under the Apache 2.0 License
  • 10.
    This work islicensed under the Apache 2.0 License Kotlin Playground Write and run Kotlin code in the browser.
  • 11.
    This work islicensed under the Apache 2.0 License How to Print Print displays the next text on the same line, while println display the next text on the next line. println("Hello") print("Hello, world!") Hello Hello, world!
  • 12.
    This work islicensed under the Apache 2.0 License Program A series of instructions for a computer to perform some action. fun main() { println("Hello, world!") } Output: Hello, world!
  • 13.
    This work islicensed under the Apache 2.0 License Code Step by step instructions for what the computer should do. fun main() { println("Hello, world!") } Output: Hello, world!
  • 14.
    This work islicensed under the Apache 2.0 License main Function The main function is the entry point, or starting point, of the program. Start here fun main() { println("Hello, world!") } Output: Hello, world!
  • 15.
    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.
  • 16.
    This work islicensed under the Apache 2.0 License Defining a function Functions begin with the fun keyword. fun displayIntroduction() { }
  • 17.
    This work islicensed under the Apache 2.0 License Defining a function Functions have a name so that they can be called. fun displayIntroduction() { }
  • 18.
    This work islicensed under the Apache 2.0 License Defining a function Functions need a set of parentheses after the function name in order to surround the function inputs. fun displayIntroduction() { }
  • 19.
    This work islicensed under the Apache 2.0 License Defining a function The curly braces make up the function body and contain the instructions needed to execute a task. fun displayIntroduction() { }
  • 20.
    This work islicensed under the Apache 2.0 License A container for a single piece of data. Variables
  • 21.
    This work islicensed under the Apache 2.0 License My name is and I am years old Variables Name variable: Athrav Age variable: 19 Output: My name is Athrav and I am 19 years old Name variable Age variable Name variable: Subin Age variable: 19 Output: My name is Subin and I am 19 years old
  • 22.
    This work islicensed 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
  • 23.
    This work islicensed under the Apache 2.0 License val keyword 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
  • 24.
    This work islicensed under the Apache 2.0 License Defining a variable Variables start with a var or val keyword. fun displayIntroduction() { val name: String = "Athrav" var age: Int = 19 }
  • 25.
    This work islicensed under the Apache 2.0 License Defining a variable All variables must have a name. fun displayIntroduction() { val name: String = "Athrav" var age: Int = 19 }
  • 26.
    This work islicensed under the Apache 2.0 License Defining a variable Data type is the type of data that the variable holds. fun displayIntroduction() { val name: String = "Athrav" var age: Int = 19 }
  • 27.
    This work islicensed under the Apache 2.0 License Defining a variable The initial value is the value that is stored in the variable. fun displayIntroduction() { val name: String = "Athrav" var age: Int = 19 }
  • 28.
    This work islicensed under the Apache 2.0 License Putting it together fun displayIntroduction() { val name = "Athrav" val age = 28 println("Hi I'm $name and I am $age years old") }
  • 29.
    This work islicensed under the Apache 2.0 License String Templates fun displayIntroduction() { val name = "Athrav" val age = 19 println("Hi I'm $name and I am $age years old") } String Templates allows you to include variable references and expressions into strings. A template expression starts with a dollar sign ($) and consists of either a name:
  • 30.
    This work islicensed under the Apache 2.0 License Putting it together fun main() { displayIntroduction() } fun displayIntroduction() { val name = "Athrav" val age = 19 println("Hi I'm $name and I am $age years old") } Output: Hi I’m Athrav and I am 19 years old
  • 31.
    This work islicensed under the Apache 2.0 License Functions with return Statement Function on calling perform the set of instruction and at last return the value. fun generateAnswerString(): String { val answerString = if (count == 42) { "I have the answer." } else { "The answer eludes me" } return answerString }
  • 32.
    This work islicensed under the Apache 2.0 License Null Safety For a variable to hold a null value, it must be of a nullable type. You can specify a variable as being nullable by suffixing its type with ? //fails to compile Val name: String = null //correct way Val name: String? = null
  • 33.
    This work islicensed under the Apache 2.0 License Conditionals Kotlin features several mechanisms for implementing conditional logic. The most common of these is an if-else statement. If an expression wrapped in parentheses next to an if keyword evaluates to true, then code within that branch (i.e. the immediately-following code that is wrapped in curly braces) is executed. Otherwise, the code within the else branch is executed.
  • 34.
    This work islicensed under the Apache 2.0 License Conditionals if (count > 10) { println("I have the answer.") } else {a println("The answer is close.") }
  • 35.
    If-else Ladder if (count== 42) { println("I have the answer.") } else if (count > 35) { println("The answer is close.") } else { println("The answer eludes me.") }
  • 36.
    If-else Ladder val answerString:String = if (count == 42) { "I have the answer." } else if (count > 35) { "The answer is close." } else { "The answer eludes me." }
  • 37.
    When Keyword val answerString= when { count == 42 -> "I have the answer." count > 35 -> "The answer is close." else -> "The answer eludes me." } // “when” keyword is used when the complexity of Conditional statements increases.
  • 38.
    Loops: for loop The forloop iterates through anything that provides an iterator. for (item in collection) { print(item) }
  • 39.
    Loops: While loops while anddo-while loops execute their body continuously while their condition is satisfied. The difference between them is the condition checking time: // while loop while (x > 0) { x-- } // do-while loop do { x++ } while (x<10)
  • 40.
    Jump Statements Kotlin hasthree structural jump expressions: return by default returns from the nearest enclosing function or anonymous function. break terminates the nearest enclosing loop. continue proceeds to the next step of the nearest enclosing loop.
  • 41.
    This work islicensed under the Apache 2.0 License Filter fun main() { val list = listOf(1,2,3,4,5) var selecteditems = list.filter ({ it < 4 }).forEach({ println(it) }) } When filter() function is called with a predicate, it returns the collection elements that match the predicate.
  • 42.
    This work islicensed under the Apache 2.0 License Map fun main() { val list = listOf(1,2,3,4,5) var selecteditems = list.map ({ it * it }).forEach({ println(it) }) } when it comes to transforming the elements in the list, Map plays a vital role in that. Suppose we want to convert each element in the list into the square of themselves:
  • 43.
    This work islicensed under the Apache 2.0 License Let fun main() { var str = "Hello World" str.let { println("$it!!") } println(str) } Kotlin let is a scoping function wherein the variables declared inside the expression cannot be used outside. fun main() { var myName: String? = null myName?.let { println(myName) } }
  • 44.
    This work islicensed under the Apache 2.0 License So What’s Next…
  • 45.
    This work islicensed under the Apache 2.0 License Let’s Create Our First Android App
  • 46.
    This work islicensed under the Apache 2.0 License Thank You