The document is a presentation on basics of Android development using Kotlin and Jetpack Compose. It includes an introduction to Kotlin programming concepts like variables, functions, data types etc. It then covers topics like building a basic Android app using Android Studio and Jetpack Compose. The schedule includes an introduction to Kotlin, setting up Android Studio and building a first Android app.
1. This work is licensed under the Apache 2.0 License
COMPOSE CAMP,
GDSC PATAN
2. WELCOME TO
SESSION ON BASICS
OF ANDROID
DEVELOPMENT
This work is licensed under the Apache 2.0 License
3. This work is licensed under the Apache 2.0 License
Ganpat Parmar
3rd Year Student
CSE Department
GEC, Patan
Camp Facilitator
4. This work is licensed under the Apache 2.0 License
Today’s Schedule
TOPIC
Basic Intro To Kotlin
Set-up Your Android Studio
Build Your First Android App
6. This work is licensed under the Apache 2.0 License
What is Kotlin?
• Kotlin is a modern but already mature programming
language aimed to make developers happier.
• It's concise, safe, interoperable with Java and other
languages, and provides many ways to reuse code
between multiple platforms for productive
programming.
7. This work is licensed under the Apache 2.0 License
What’s Kotlin is for?
Multiplatform
Sharing code between
mobile platforms is one of
the major Kotlin
Multiplatform use cases.
Server Side
Kotlin is a great fit for
developing server-side
applications. It allows
you to write concise and
expressive code.
JavaScript
Kotlin/JS provides the
ability to transpile your
Kotlin code, the Kotlin
standard library, and any
compatible dependencies
to JavaScript
Data Science
From building data
pipelines to
productionizing machine
learning models, Kotlin
can be a great choice for
working with data
8. This work is licensed under the Apache 2.0 License
Kotlin for Android
• Less code combined with greater readability
• Mature language and environment
• Kotlin support in Android Jetpack and other
libraries.
• Interoperability with Java
• Support for multiplatform development
• Code safety
• Easy learning
• Big community
9. This work is licensed under the Apache 2.0 License
Lets get handy
with Kotlin
10. This work is licensed under the Apache 2.0 License
● Kotlin Compiler
● Compiler v/s Interpreter
● main() Function
Our First Program in
Kotlin
Output
11. This work is licensed under the Apache 2.0 License
Parts of a Function
● Define v/s call a Function
● Define a Function
1. fun keyword
2. Name (camelCase)
3. Inputs
4. body (Multiple Lines;)
fun ( ) {
}
name inputs
body
12. This work is licensed under the Apache 2.0 License
Kotlin Style Guide
1. Function names should be in camel case and should be
verb or verb phase.
2. Each statement should be on its own line.
3. The opening curly braces should appear at the end of
the line where function begins.
4. There should be space before opening curly brace.
5. Indent by 4 spaces.
6. Vertically align.
space
Opening
braces
indent
14. This work is licensed under the Apache 2.0 License
Container and Label Relationship
name
value
15. This work is licensed under the Apache 2.0 License
Data Types
Kotlin Data type What kind of data it can
contain
Range Example
String Text String of any length “Hello World”,
“b”, “A”
Int Whole Integer Number -2147483648 to 2147483647 28, 2001, -8925
Double Decimal Number -1.79769313486231E308 to -
4.94065645841247E-324 (for -ve)
4.94065645841247E-324 to
1.79769313486232E308 (for +ve)
4283.01413
-256.3241
Float Decimal number that is less precise
then decimal number
4.94065645841247E-324 to
1.79769313486232E308
1.98
3.14
-54.89
Boolean Use when there are only two possible
values.
True or False true
false
16. This work is licensed under the Apache 2.0 License
Define and Use Variables
● Declare a variable (a)
name
Val : data type = Initial value
Val count : Int = 2
Assignment
operator
17. This work is licensed under the Apache 2.0 License
Define and Use Variables
● Declare a variable (b)
name
Var = Initial value
Var count = 2
18. This work is licensed under the Apache 2.0 License
Difference b/w val and var
val keyword:-
Whenever we declare a variable with val keyword it
means that it’s a constant. Its value can not be
changed throughout the program.
var keyword:-
When we declare a variable with var keyword it
means that it is not a constant and we can reassign
new value to that variable
19. This work is licensed under the Apache 2.0 License
Basic Math operations with Integers
Basic calculations :-
Define an integers variable for unread
un-read emails in your inbox. And
initialize it with value such as 50.
Define an integers variable for unread
read emails in your inbox. And
initialize it with value such as 100.
Then print total number of emails in your inbox by adding the two integers numbers together.
Run the program and it should display the total numbers of messages in the inbox.
20. This work is licensed under the Apache 2.0 License
Update Variables
numberOfItems
30
5
21. This work is licensed under the Apache 2.0 License
Explore Other Data Types
22. This work is licensed under the Apache 2.0 License
Explore Other Data Types
23. This work is licensed under the Apache 2.0 License
Explore Other Data Types
24. This work is licensed under the Apache 2.0 License
Enhance the readability of Your Code
// This is Comment
/*
* This is a very long comment that can
* take up multiple lines.
*/
Single Line Comment
Multi Line Comment
25. This work is licensed under the Apache 2.0 License
Continue…
26. This work is licensed under the Apache 2.0 License
Conclusion
A variable is a container for a single piece of data.
You must declare a variable first before you use it.
Use the val keyword to define a variable that is read-only where the value cannot change once it's
been assigned.
Use the var keyword to define a variable that is mutable or changeable.
In Kotlin, it's preferred to use val over var when possible.
To declare a variable, start with the val or var keyword. Then specify the variable name, data type,
and initial value. For example: val count: Int = 2.
27. This work is licensed under the Apache 2.0 License
Continue..
With type inference, omit the data type in the variable declaration if an initial value is provided.
Some common basic Kotlin data types include: Int, String, Boolean, Float, and Double.
Use the assignment operator (=) to assign a value to a variable either during declaration of the
variable or updating the variable.
You can only update a variable that has been declared as a mutable variable (with var).
Use the increment operator (++) or decrement operator (--) to increase or decrease the value of
an integer variable by 1, respectively.
Use the + symbol to concatenate strings together. You can also concatenate variables of other data
types like Int and Boolean to Strings.
29. This work is licensed under the Apache 2.0 License
Define and call a Function
fun ( ) {
}
name inputs
body
30. This work is licensed under the Apache 2.0 License
Can Function Return Something ?
fun ( ) : {
}
name inputs
body
Return type
Return statement
31. This work is licensed under the Apache 2.0 License
Function Returning String
32. This work is licensed under the Apache 2.0 License
Function With Multiple Arguments
33. This work is licensed under the Apache 2.0 License
Function With Default Arguments
34. This work is licensed under the Apache 2.0 License
Conclusion
•Functions are defined with the fun keyword and contain reusable pieces of code.
•Functions help make larger programs easier to maintain and prevent the unnecessary repetition of code.
•Functions can return a value that you can store in a variable for later use.
•Functions can take parameters, which are variables available inside a function body.
•Arguments are the values that you pass in when you call a function
•You can name arguments when you call a function. When you use named arguments, you can reorder the arguments
without affecting the output.
•You can specify a default argument that lets you omit the argument when you call a function.
36. This work is licensed under the Apache 2.0 License
Problem – 1 (print messages)
• Can you write a main() function that prints these messages on four separate lines?
Use the val keyword when the value doesn't change.
Use the var keyword when the value can change.
When you define a function, you define the parameters that can be passed to it.
When you call a function, you pass arguments for the parameters.
37. This work is licensed under the Apache 2.0 License
Problem – 2 (fix compile error)
fun main() {
println("New chat message from a friend'}
}
1. Can you figure out the root cause of the compile errors in this program and fix them?
2. Does the code use appropriate symbols to indicate the open and close of the string and function
argument?
38. This work is licensed under the Apache 2.0 License
Problem – 3 (String Templaets)
fun main() {
val discountPercentage: Int = 0
val offer: String = ""
val item = "Google Chromecast"
discountPercentage = 20
offer = "Sale - Up to $discountPercentage% discount on $item! Hurry up!"
println(offer)
}
1) Can you figure out the root cause of the errors and fix them?
2) Can you determine the output of this program before you run the code in Kotlin Playground?
39. This work is licensed under the Apache 2.0 License
Problem – 4 (String Concatenation)
Can you guess the output ?
fun main() {
val numberOfAdults = "20"
val numberOfKids = "30"
val total = numberOfAdults + numberOfKids
println("The total party size is: $total")
}
40. This work is licensed under the Apache 2.0 License
Problem – 5 (Message formatting)
1) Can you figure out the output of this code before you run it in Kotlin Playground?
2) When you run the code in Kotlin Playground, does it print the output that you expected?
fun main() {
val baseSalary = 5000
val bonusAmount = 1000
val totalSalary = "$baseSalary + $bonusAmount"
println("Congratulations for your bonus! You will receive a
total of $totalSalary(additional bonus).")
}
41. This work is licensed under the Apache 2.0 License
Problem – 6 (Implement basic math operations)
fun main() {
val firstNumber = 10
val secondNumber = 5
val thirdNumber = 8
val result = add(firstNumber, secondNumber)
val anotherResult = add(firstNumber, thirdNumber)
println("$firstNumber + $secondNumber = $result")
println("$firstNumber + $thirdNumber = $anotherResult")
}
// Define add() function below this line
Can you guess the output ?
42. This work is licensed under the Apache 2.0 License
Problem – 7
Can you guess the Reason ?
?
43. This work is licensed under the Apache 2.0 License
Introduction to
Jetpack Compose
44. This work is licensed under the Apache 2.0 License
Let’s start Making Our First Android
App Using Jetpack Compose
Design Pane in Android Studio
Add a new Text element
Change Font size
Add another text element
Arrange text element in column and row
Display on the device
45. This work is licensed under the Apache 2.0 License
Add Image Composable to Our App
Add Box Layout, Row and Column layout
Position and Scale the Image Composable
Align text and add padding
Arrange Adopt good scale Practice
Display on the device
46. This work is licensed under the Apache 2.0 License
Let’s Practice Some of the Composable that we
have learnt
Text Composable
Column Composable
Row Composable
Image Composable
47. This work is licensed under the Apache 2.0 License
Let’s Practice Some of the Composable that we
have learnt
48. This work is licensed under the Apache 2.0 License
Let’s Practice Some of the Composable that we
have learnt
49. This work is licensed under the Apache 2.0 License
Let’s Practice Some of the Composable that we
have learnt
50. This work is licensed under the Apache 2.0 License
THANK
YOU
This work is licensed under the Apache 2.0 License