1. Stargazing at State
Migration Meadow
Testing Trails
Performance Peak
Layout Lake
Material Tents
Google Developer Student Clubs
Bakhtiyarpur College Of Engineering - Patna
2. This work is licensed under the Apache 2.0 License
Compose Camp #2
Introduction to Kotlin,
Adding a Button &
Interaction with UI
Google Developer Student Clubs
Bakhtiyarpur College Of Engineering - Patna
22nd September, 2022
3. This work is licensed under the Apache 2.0 License
Agenda
Introduction to Kotlin
● What is Kotlin ?
● History of Kotlin
● Why Kotlin ?
● main() function
● Variables in Kotlin
● Control Flow
● if…else
● when
● Loops
○ for
○ while
○ do while
● functions
Adding a button
● Creating our first application
using Android Studio
● Understanding the basic layout of
Android Studio
● Writing codes using Kotlin
● Run them on Emulator
Interacting with UI & state
● Adding functionality to button
● Run code live
4. This work is licensed under the Apache 2.0 License
What is Kotlin ?
Kotlin is a general purpose, free, open source, modern programming
language which also supports cross-platform. It supports OOP and is
better than JAVA for android app development. For iOS some
framework like Codename One or Kotlin Multi platform is used.
It was introduced by JetBrains in 2011.
At Google I/0 2017, Google announced first-class support for Kotlin on
Android and announced Kotlin as an official language for android
development.
Kotlin Fundamentals
5. This work is licensed under the Apache 2.0 License
Why Kotlin ?
Kotlin is designed to interoperate fully with Java,
and the JVM version of kotlin's standard library
depends on the Java class library
Google made Kotlin as first preference for developing
apps
30% less code as compared to Java
Time spent on reviews and maintenance is less
60% professional Android developers use Kotlin
6. This work is licensed under the Apache 2.0 License
Kotlin is an programming language that
combines object-oriented
programming and functional features
into a unique platform.
main() function - Entry point of the kotlin application
function declaration –> fun keyword
Example :
fun main(args:Array<string>)
{
println(“Welcome to Compose Camp ”)
}
main() FUNCTION :-
7. This work is licensed under the Apache 2.0 License
VARIABLES :-
Variables in kotlin :-
A simple Box in which we can hold the data.
There are mainly two types of variables in Kotlin:
1. var 2. val
var and val :-
● var can be reassigned.
● val can’t be reassigned.
8. This work is licensed under the Apache 2.0 License
Data Types in Kotlin :-
There are mainly Four types of data
types:
1. Integer 2. Floating Point
3. Boolean 4. Character
fun main () {
var score :Int= 12
var température:Double=89.4
var isRaining:Boolean = false
var alphabet: char=’A’
var message: string=”Hello World”
}
9. This work is licensed under the Apache 2.0 License
Control Flow :-
if-else :-
if (condition) {
// Run this code if condition is true
}
else {
// Run this code if condition is false
}
10. This work is licensed under the Apache 2.0 License
Control Flow :-
When :-
It is similar to switch case which is used in C/C++.
Readability of code is more than if-else statement.
fun main ( ) {
val animal =”horse”
// if (animal ==”Horse”) {
//println(“Animal is Horse”)
// }
//else if (animal==”Cat”) {
// println(“Animal is Cat”) } }
when(animal) {
“horse”->println(“Animal is
Horse”)
“Cat”->println(“Animal is Cat”)
else -> println(“Animal not found”)
}
}
11. This work is licensed under the Apache 2.0 License
for Loop
a for-loop is a control flow statement for specific iteration , which allows code
to be executed repeatedly.
LOOPS:
fun main ( )
{
for(item in 1…5)
{
println(item)
}
}
12. This work is licensed under the Apache 2.0 License
The while loop through a block of code as long a specified condition is true .
while Loop:-
fun main ( )
{
while (condition)
{
// code block to be executed while
// the condition is true
}
}
13. This work is licensed under the Apache 2.0 License
The do…while is similar to the loop with a difference that the this loop will executed to
the code block once, before checking if the condition is true , then it will repeat the loop
as long as the condition is true.
do…while Loop:-
fun main ( )
{
do {
// Body of the loop
}
while (condition)
}
14. This work is licensed under the Apache 2.0 License
FUNCTIONS :-
Block of code to perform certain functionality and helps to reuse the code
Syntax of function
:-
fun functionName(par1,par2,....: ReturnType)
{
Block of statements
return result
}
Example :
15. This work is licensed under the Apache 2.0 License
Let’s build this on Android Studio
Add a button to App
Add a button to App
16. This work is licensed under the Apache 2.0 License
Let’s build this on Android Studio
Interacting with UI & state
Interacting with UI &States
17. This work is licensed under the Apache 2.0 License
Earn digital badges
For each quiz successfully
passed
18. This work is licensed under the Apache 2.0 License
Carrie Sawyer
See Developer Profile FAQ
Badges are added
to your
Google Developer Profile
19. This work is licensed under the Apache 2.0 License
Milestones
Attend sessions and
workshops organised
by GDSC BCE Patna
Complete all the
units under
different tracks
Build apps with
Compose with the
guidelines provided
(app development
guidelines coming soon)*
20. This work is licensed under the Apache 2.0 License
App submission
Coming Soon !!
21. This work is licensed under the Apache 2.0 License
Compose Camp Week #2 Content
Kotlin Fundamentals Add a button to App Interacting with UI &States
22. This work is licensed under the Apache 2.0 License
THANK
YOU
Google Developer Student Clubs
Bakhtiyarpur College Of Engineering - Patna