SlideShare a Scribd company logo
Kotlin: What you
need to know
Android Development with Kotlin v1.0 ThisThis workwork isislicensedlicensed underunder thethe
ApacheApache 2
2licenselicense.. 1
1
1
Umar SaiduAuna
Software Engineer, gidimo
tech community Organizer
umarauna
November 24, 2021
Kotlin  what_you_need_to_know-converted event 4 with nigerians
What mostly happen to JAVA programmers before Kotlin
otlin history
History
Kotlin is a cross-platform, statically typed, general-purpose
programming language and runs on the JVM
History
Kotlin is a cross-platform, statically typed, general-purpose
programming language and runs on the JVM.
Kotlin was developed by JetBrains (Makers of IntelliJ)
History
Kotlin is a cross-platform, statically typed, general-purpose programming language and
runs on the JVM.
Kotlin was developed by JetBrains (Makers of IntelliJ)
First commit dates back to 2010, but was first publicly seen around 2011.
History - Why did Google make it official?
Awesome features - nullable types, concise, data classes, etc.
Great community support
There was an overwhelming request for Kotlin
official support on Android
otlin What?
What is Kotlin
Kotlin is a cross-platform, statically typed, general-purpose programming
language, it is also JVM based language developed by JetBrains as
described before, a company known for the creation of IntelliJ IDEA, a
powerful IDE for Java development. In Kotlin everything is an Object.
What is Kotlin
Kotlin is a cross-platform, statically typed, general-purpose programming
language, it is also JVM based language developed by JetBrains as
described before, a company known for the creation of IntelliJ IDEA, a
powerful IDE for Java development. In Kotlin everything is an Object.
Kotlin is very intuitive and easy to learn for Java developers
(give it 10 days trials and you wont regret).
What is Kotlin
Kotlin is a cross-platform, statically typed, general-purpose programming
language, it is also JVM based language developed by JetBrains as
described before, a company known for the creation of IntelliJ IDEA, a
powerful IDE for Java development. In Kotlin everything is an Object.
Kotlin is very intuitive and easy to learn for Java developers
(give it 10 days trials and you wont regret).
Its more expressive & safer
What is Kotlin
Kotlin is a cross-platform, statically typed, general-purpose programming
language, it is also JVM based language developed by JetBrains as
described before, a company known for the creation of IntelliJ IDEA, a
powerful IDE for Java development. In Kotlin everything is an Object.
Kotlin is very intuitive and easy to learn for Java developers
(give it 10 days trials and you wont regret).
Its more expressive & safer
Its highly interoperable
otlin interesting
features
“In Kotlin, everything is an object
(reference type), we don’t find primitives
types as the ones we can use in
Java……...”
#1 Fastest growing language
Companies Using Kotlin
Companies Using Kotlin
Job requirements
Kotlin  what_you_need_to_know-converted event 4 with nigerians
implemeantation 'com.github.UmarAuna:Carousels-Kotlin:0.0.2'
http://bit.ly/kotlin-image-carousel
Kotlin sample code…..
fun main(args: Array<String>){
//your code goes here
}
Kotlin 1.3 no more (args: Array<String>)
fun main(){
// your code goes here
}
Kotlin  what_you_need_to_know-converted event 4 with nigerians
Kotlin  what_you_need_to_know-converted event 4 with nigerians
Null Safety - nullable types and non-nullable types
Tony Hoare, one of the creators of the programming language ALGOL.
Protects against NullPointerException the $1,000,000,000 mistake
Null Safety - nullable types and non-nullable types
Tony Hoare, one of the creators of the programming language ALGOL.
Protects against NullPointerException the $1,000,000,000 mistake
A non-nullable object can’t be null
// compiler error
var name: String
name = null
Null Safety - nullable types and non-nullable types
Tony Hoare, one of the creators of the programming language ALGOL.
Protects against NullPointerException the $1,000,000,000 mistake
A non-nullable object can’t be null
// compiler error
var name: String
name = null
Specify a nullable object by using “?”
// compiler error
var name: String?
val length = name.length Kotlin ensures that you don’t mistakenly operate on nullable objects
Kotlin  what_you_need_to_know-converted event 4 with nigerians
Null Safety - Accessing properties in a nullable object
1. Checking for null types
// handle non-null case and null case
var name: String? = null
val length = if (name != null) name.length else 0
Null Safety - Accessing properties in a nullable object
2. Making safe calls using “?.”
//use ?. to make safe call
var name: String?
...
val length = name?.length
Use ?. to safely access a property/method on a
nullable object
If name happens to be null, the value of length is 0
(inferred integer).
length would be null if it were of another type.
Null Safety - Accessing properties in a nullable object
3. Making use of the “?:” elvis operator
//use elvis operator
var name: String?
val length = name?.length ?: 0
This reads as “if name is not null, use
name.length else use 0
Elvis Presley. His hairstyle resembles a Question Mark
Null Safety - Accessing properties in a nullable object
4. Making use of the “!!” assertion operator
//use assertion operator
var name: String? = null
val length = name!!.length
This reads as “if name is not null, use
name.length else throw a null pointer
exception”
Null Safety - Accessing properties in a nullable object
4. Making use of the “!!” assertion operator
//use elvis operator
var name: String? = null
val length = name!!.length
This reads as “if name is not null, use
name.length else throw a null pointer
exception”
Be very careful with this operator!!!
Null Safety - NPE free!
You can only have the NullPointerException in Kotlin if:
1. You explicitly throw a NPE
2. You make use of the !! operator
3. An external Java code causes the NPE.
String Interpolation / template in Kotlin
fun hello(name: String) {
println("Hello, $name")
}
String Interpolation in Java + Kotlin
void hello(String name) {
System.out.println("Hello, " + name);
}
Immutability
Kotlin helps developers to be intentional about immutability.
Immutability simply means that things you create can’t be changed.
We need immutability because it:
● helps us with thread safety - no synchronization issues
● is good for value objects - objects that simply hold value, POJOs etc.
● helps debugging threaded applications without losing your hair
Immutability
How does it work in Java?
●Immutability in Java?
final classes
private fields
no setters
● Immutability in Kotlin? Guess?
Immutability
How does Kotlin help?
var vs val
// compiler error: val cannot be reassigned
val name = "Umar"
name = name.toUpperCase()
// works fine
var name = "Umar"
name = name.toUpperCase()
Immutability
How does Kotlin help?
Immutable and Mutable collections
// immutable collection
val unchangeableHobbies = listOf("coding", "hiking")
unchangeableHobbies.add() // add method doesn’t exist
// mutable collection
val changeableHobbies = mutableListOf("reading", "running")
changeableHobbies.add("travelling") // you can add
Immutability
In Java vs Kotlin
public final class ImmutableClassJava {
private final String name;
private final int age;
public ImmutableClassJava(String name, int age) {
this.name = name;
this.age = age;
}
// no setters
public String getName() {
return name;
}
public int getAge() {
return age;
}
}
class ImmutableClassJava(val name: String, val age: Int)
● Class is final by default
●val implies that the parameters are
final as well (values can’t be assigned)
Functions
// function sample
fun sampleFunc() {
// code goes here
}
A function is declared using the “fun”
keyword
Functions
// function sample
fun sampleFunc() {
// code goes here
}
// function with param
fun sampleFuncWithParam(param: String) {
// code goes here
}
A function is declared using the “fun”
keyword
Method parameters use the “name:Type”
notation
Functions
// function sample
fun sampleFunc() {
// code goes here
}
// function with param
fun sampleFuncWithParam(param: String) {
// code goes here
}
// func with param and return type
fun capitalize(param: String): String {
return param.toUpperCase()
}
A function is declared using the “fun”
keyword
Method parameters use the “name:Type”
notation
Return types are specified after the
method definition.
Functions - infix functions
// infix function
infix fun Int.times(x: Int): Int {
return this * x
}
We can use the function as an arithmetic operator, i.e.,
using it without writing dots and parentheses.
Functions - infix functions
// infix function
infix fun Int.times(x: Int): Int {
return this * x
}
// usage
fun useInfix() {
val product = 2 times 5
println(product)
}
We can use the function as an arithmetic operator, i.e.,
using it without writing dots and parentheses.
Functions - extension functions
// extension function
fun Int.square(): Int {
return this * this
}
Extension function is a member function of a class that is
defined outside the class
Functions - extension functions
// extension function
fun Int.square(): Int {
return this * this
}
Extension function is a member function of a class that is
defined outside the class
// usage
fun useExtension() {
val square = 2.square()
println(square)
}
Functions
Others:
● Higher order functions
● Lambdas
● Inline functions etc.
Kotlin  what_you_need_to_know-converted event 4 with nigerians
Iterators
Java Kotlin
When Expression
otlin conciseness
Conciseness in Kotlin
public void doSomething() {
// do something
}
fun doSomething(): Unit {
// do same thing
}
Conciseness in Kotlin
public void doSomething() {
// do something
}
fun doSomething(): Unit {
// do same thing
}
Conciseness in Kotlin
public void doSomething() {
// do something
}
fun doSomething() {
// do same thing
}
Conciseness in Kotlin
public String getName() {
return name;
}
fun getName(): String {
return name
}
Conciseness in Kotlin
public String getName() {
return name;
}
fun getName() {
return name
}
Conciseness in Kotlin
public String getName() {
return name;
}
fun getName() = name
Kotlin  what_you_need_to_know-converted event 4 with nigerians
otlin class
Class in Java vs Data Class in Kotlin
public class Person {
private String name;
String getName () {
return name;
}
void setName (String name) {
this.name = name;
}
@Override
public String toString () {
return "Person{" +
"name='" + name + ''' +
'}';
}
}
data class Person(val name: String)
Class in Java vs Regular Class in Kotlin
public class Person {
private String name;
String getName () {
return name;
}
void setName (String name) {
this.name = name;
}
public int getNameLength () {
return name.length
}
}
class Person(name: String) {
var name: String
get() = name
set(name) {
this.name = name
}
fun getNameLength(): Int {
return name.length
}
}
Class in Java vs Regular Class in Kotlin
public class Person {
private String name;
String getName () {
return name;
}
void setName (String name) {
this.name = name;
}
public int getNameLength () {
return name.length
}
}
class Person(name: String) {
var name: String
get() = name
set(name) {
this.name = name
}
fun getNameLength() = name.length
}
Kotlin  what_you_need_to_know-converted event 4 with nigerians
otlin: getting started
Important place to learn…….
Important place to learn…….
Tutorials Point - Kotlin
Important place to learn…….
Tutorials Point - Kotlin
Kotlin for Android Developers – Antonio Leiva
Important place to learn…….
Tutorials Point - Kotlin
Kotlin for Android Developers – Antonio Leiva
Koans online – try.kotl.in/koans
Important place to learn…….
Tutorials Point - Kotlin
Kotlin for Android Developers – Antonio Leiva
Koans online – try.kotl.in/koans
Kotlin Bootcamp for Programmers - Udacity
Important place to learn…….
Tutorials Point - Kotlin
Kotlin for Android Developers – Antonio Leiva
Koans online – try.kotl.in/koans
Kotlin Bootcamp for Programmers - Udacity
https://developer.android.com/kotlin/learn
Compilations
Kotlin  what_you_need_to_know-converted event 4 with nigerians
IDE’s
Build Tools
Stay updated…….
Kotlin Weekly
http://www.kotlinweekly.net/
Kotlin Conf
kotlinconf.com
Summary
• Interoperable with Java (100%)
• Reduces Boilerplate code
• Object-Oriented and procedural
• Safety code
• No Semicolon
• Expands your skillset
• Perfect Support with Android Studio & Gradle
• Very easy to get started with Android Development
otlin: libraries
Reduces Boilerplates codes like:
findViewById, Async, build interfaces
with Kotlin code etc
Kotlin Android Extension it includes a view
binder. The plugin automatically creates a set
of properties that give direct access to all the
views in the XML.
Async Server - Client
Finally
You have 3 Options..
1
Decide Kotlin is not
For you and continue
with Java
Finally
1
Decide Kotlin is not
For you and continue
with Java
You have 3 Options..
2
Try to learn
everything
on your own
Finally
1
Decide Kotlin is not
For you and continue
with Java
You have 3 Options..
3
Go and learn on
MOOC websites
2
Try to learn
everything
on your own
Questions
? Thank
you!
Android Development with Kotlin v1.0 ThisThis workwork isislicensedlicensed underunder thethe
ApacheApache 2
2licenselicense.. 878787
Umar SaiduAuna
Software Engineer, gidimo
tech community Organizer
umarauna
A PROGRAMMING
LANGUAGE THAT BRINGS JOY
TO PROGRAMMERS
INTRODUCTION TO
KOTLIN
SOFTWARE DEVELOPER
AND TRAINER
ABO
UT
ME
• Android and IOS Developer.
• Lead Mobile Developer for DOUBLET (App For
Couples).
• Project Lead and Lead Mobile
Developer for KITCHLY (App for Food
Lovers).
• Software Trainer at Rework Academy.
CONNECT: linkedin.com/in/young-batimehin-
5a6208159
YOUNG AYODEJI BATIMEHIN
LET’s GET TO
KNOW THE
AUDIENCE
1) Introduction to
Kotlin
2) Features
3) Kotlin Vs Java
4) Set Up Development Environment
5) Build a List App.
6) Conclusion and Questions.
Today’s
Agenda
• Kotlin is a statically typed programming language.
• It supports object-oriented programming and functional programming
features.
• It can also be compiled into Javascript source code.
• Extension of the Kotlin is (.kt)
• It’s a JVM targeted language.
• Kotlin supports procedural programming with the use of functions.
• Supports Multi-platform projects.
• It is an open-source language.
• It is now the official language for Android Development.
INTRODUCTIO
N
KOTLIN
FEATURES
Use Kotlin for any
type of Enterprise
Java EE
Development
100 %
Compactible
with all JVM
frameworks
Null Safety. Kotlin
Avoids the null
pointer exception
when using or
declaring variables.
Kotlin wants you
to write less
code
Familiar to Java.
But you can still
learn Kotlin
without
experience with
java
Automatic
Conversion from
Kotlin to java
Strong
Community
Kotlin integrates well
with all existing Java
Frameworks and
Libaries
LIST APP
• Open Android Studio
• Set-up Android project with Kotlin as code base
• Brief explanation of all dependency and
implementation
• Implement Recycler View
• Implement Cardview
• Use Custom RecyclerView Adapter
• Model Class
• Layout Managers
Set Up Development
Environment
FOR LIST APP

More Related Content

PPTX
Getting Started With Kotlin
PPTX
Say Goodbye To Java: Getting Started With Kotlin For Android Development
PPTX
Android with kotlin course
PPTX
Java For Automation
PPTX
Kotlin Native - C / Swift Interop - ACCU Autmn 2019
PDF
PPTX
Kotlin presentation
Getting Started With Kotlin
Say Goodbye To Java: Getting Started With Kotlin For Android Development
Android with kotlin course
Java For Automation
Kotlin Native - C / Swift Interop - ACCU Autmn 2019
Kotlin presentation

What's hot (20)

PPTX
OCL in EMF
PDF
Introduction to kotlin for Java Developer
PPTX
Kotlin in action
PDF
Kotlin - Better Java
PPTX
Exploring Kotlin language basics for Android App development
PDF
Introduction to Kotlin - Android KTX
PPT
Virtual Function
PDF
Kotlin a problem solver - gdd extended pune
PDF
New c sharp4_features_part_ii
PDF
From Java to Kotlin
PPTX
Why functional programming in C# & F#
ODP
Enrich Your Models With OCL
PDF
Lambda: A Peek Under The Hood - Brian Goetz
PDF
Concepts of functional programming
PDF
Dependency Injection: Make your enemies fear you
PPSX
Kotlin Language powerpoint show file
PPT
Smoothing Your Java with DSLs
PPTX
OCP Java (OCPJP) 8 Exam Quick Reference Card
PDF
Clojure and The Robot Apocalypse
DOCX
Using traits in PHP
OCL in EMF
Introduction to kotlin for Java Developer
Kotlin in action
Kotlin - Better Java
Exploring Kotlin language basics for Android App development
Introduction to Kotlin - Android KTX
Virtual Function
Kotlin a problem solver - gdd extended pune
New c sharp4_features_part_ii
From Java to Kotlin
Why functional programming in C# & F#
Enrich Your Models With OCL
Lambda: A Peek Under The Hood - Brian Goetz
Concepts of functional programming
Dependency Injection: Make your enemies fear you
Kotlin Language powerpoint show file
Smoothing Your Java with DSLs
OCP Java (OCPJP) 8 Exam Quick Reference Card
Clojure and The Robot Apocalypse
Using traits in PHP
Ad

Similar to Kotlin what_you_need_to_know-converted event 4 with nigerians (20)

PDF
Kotlin: A pragmatic language by JetBrains
PDF
Little Helpers for Android Development with Kotlin
PPTX
Introduction to Kotlin for Android developers
PDF
Kotlin for Android devs
PPTX
Introduction to Kotlin Language and its application to Android platform
PDF
Develop your next app with kotlin @ AndroidMakersFr 2017
PDF
Kotlin, smarter development for the jvm
PPTX
Introduction to Koltin for Android Part I
PDF
Basics of kotlin ASJ
PDF
Kotlin from-scratch
PPTX
Why kotlininandroid
PDF
Privet Kotlin (Windy City DevFest)
PDF
PDF
9054799 dzone-refcard267-kotlin
PDF
Coding for Android on steroids with Kotlin
PDF
Exploring Kotlin
PDF
Be More Productive with Kotlin
PPTX
Unit 1 part for information technology 1.pptx
PDF
Summer of Tech 2017 - Kotlin/Android bootcamp
PPTX
Kotlin as a Better Java
Kotlin: A pragmatic language by JetBrains
Little Helpers for Android Development with Kotlin
Introduction to Kotlin for Android developers
Kotlin for Android devs
Introduction to Kotlin Language and its application to Android platform
Develop your next app with kotlin @ AndroidMakersFr 2017
Kotlin, smarter development for the jvm
Introduction to Koltin for Android Part I
Basics of kotlin ASJ
Kotlin from-scratch
Why kotlininandroid
Privet Kotlin (Windy City DevFest)
9054799 dzone-refcard267-kotlin
Coding for Android on steroids with Kotlin
Exploring Kotlin
Be More Productive with Kotlin
Unit 1 part for information technology 1.pptx
Summer of Tech 2017 - Kotlin/Android bootcamp
Kotlin as a Better Java
Ad

Recently uploaded (20)

PPTX
GDM (1) (1).pptx small presentation for students
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
Cell Types and Its function , kingdom of life
PPTX
Final Presentation General Medicine 03-08-2024.pptx
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Yogi Goddess Pres Conference Studio Updates
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
Lesson notes of climatology university.
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Classroom Observation Tools for Teachers
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Computing-Curriculum for Schools in Ghana
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
GDM (1) (1).pptx small presentation for students
Module 4: Burden of Disease Tutorial Slides S2 2025
Orientation - ARALprogram of Deped to the Parents.pptx
Cell Types and Its function , kingdom of life
Final Presentation General Medicine 03-08-2024.pptx
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
2.FourierTransform-ShortQuestionswithAnswers.pdf
Yogi Goddess Pres Conference Studio Updates
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
human mycosis Human fungal infections are called human mycosis..pptx
Chinmaya Tiranga quiz Grand Finale.pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Lesson notes of climatology university.
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Classroom Observation Tools for Teachers
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Computing-Curriculum for Schools in Ghana
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3

Kotlin what_you_need_to_know-converted event 4 with nigerians

  • 1. Kotlin: What you need to know Android Development with Kotlin v1.0 ThisThis workwork isislicensedlicensed underunder thethe ApacheApache 2 2licenselicense.. 1 1 1 Umar SaiduAuna Software Engineer, gidimo tech community Organizer umarauna November 24, 2021
  • 3. What mostly happen to JAVA programmers before Kotlin
  • 5. History Kotlin is a cross-platform, statically typed, general-purpose programming language and runs on the JVM
  • 6. History Kotlin is a cross-platform, statically typed, general-purpose programming language and runs on the JVM. Kotlin was developed by JetBrains (Makers of IntelliJ)
  • 7. History Kotlin is a cross-platform, statically typed, general-purpose programming language and runs on the JVM. Kotlin was developed by JetBrains (Makers of IntelliJ) First commit dates back to 2010, but was first publicly seen around 2011.
  • 8. History - Why did Google make it official? Awesome features - nullable types, concise, data classes, etc. Great community support There was an overwhelming request for Kotlin official support on Android
  • 10. What is Kotlin Kotlin is a cross-platform, statically typed, general-purpose programming language, it is also JVM based language developed by JetBrains as described before, a company known for the creation of IntelliJ IDEA, a powerful IDE for Java development. In Kotlin everything is an Object.
  • 11. What is Kotlin Kotlin is a cross-platform, statically typed, general-purpose programming language, it is also JVM based language developed by JetBrains as described before, a company known for the creation of IntelliJ IDEA, a powerful IDE for Java development. In Kotlin everything is an Object. Kotlin is very intuitive and easy to learn for Java developers (give it 10 days trials and you wont regret).
  • 12. What is Kotlin Kotlin is a cross-platform, statically typed, general-purpose programming language, it is also JVM based language developed by JetBrains as described before, a company known for the creation of IntelliJ IDEA, a powerful IDE for Java development. In Kotlin everything is an Object. Kotlin is very intuitive and easy to learn for Java developers (give it 10 days trials and you wont regret). Its more expressive & safer
  • 13. What is Kotlin Kotlin is a cross-platform, statically typed, general-purpose programming language, it is also JVM based language developed by JetBrains as described before, a company known for the creation of IntelliJ IDEA, a powerful IDE for Java development. In Kotlin everything is an Object. Kotlin is very intuitive and easy to learn for Java developers (give it 10 days trials and you wont regret). Its more expressive & safer Its highly interoperable
  • 15. “In Kotlin, everything is an object (reference type), we don’t find primitives types as the ones we can use in Java……...”
  • 16. #1 Fastest growing language
  • 22. Kotlin sample code….. fun main(args: Array<String>){ //your code goes here }
  • 23. Kotlin 1.3 no more (args: Array<String>) fun main(){ // your code goes here }
  • 26. Null Safety - nullable types and non-nullable types Tony Hoare, one of the creators of the programming language ALGOL. Protects against NullPointerException the $1,000,000,000 mistake
  • 27. Null Safety - nullable types and non-nullable types Tony Hoare, one of the creators of the programming language ALGOL. Protects against NullPointerException the $1,000,000,000 mistake A non-nullable object can’t be null // compiler error var name: String name = null
  • 28. Null Safety - nullable types and non-nullable types Tony Hoare, one of the creators of the programming language ALGOL. Protects against NullPointerException the $1,000,000,000 mistake A non-nullable object can’t be null // compiler error var name: String name = null Specify a nullable object by using “?” // compiler error var name: String? val length = name.length Kotlin ensures that you don’t mistakenly operate on nullable objects
  • 30. Null Safety - Accessing properties in a nullable object 1. Checking for null types // handle non-null case and null case var name: String? = null val length = if (name != null) name.length else 0
  • 31. Null Safety - Accessing properties in a nullable object 2. Making safe calls using “?.” //use ?. to make safe call var name: String? ... val length = name?.length Use ?. to safely access a property/method on a nullable object If name happens to be null, the value of length is 0 (inferred integer). length would be null if it were of another type.
  • 32. Null Safety - Accessing properties in a nullable object 3. Making use of the “?:” elvis operator //use elvis operator var name: String? val length = name?.length ?: 0 This reads as “if name is not null, use name.length else use 0 Elvis Presley. His hairstyle resembles a Question Mark
  • 33. Null Safety - Accessing properties in a nullable object 4. Making use of the “!!” assertion operator //use assertion operator var name: String? = null val length = name!!.length This reads as “if name is not null, use name.length else throw a null pointer exception”
  • 34. Null Safety - Accessing properties in a nullable object 4. Making use of the “!!” assertion operator //use elvis operator var name: String? = null val length = name!!.length This reads as “if name is not null, use name.length else throw a null pointer exception” Be very careful with this operator!!!
  • 35. Null Safety - NPE free! You can only have the NullPointerException in Kotlin if: 1. You explicitly throw a NPE 2. You make use of the !! operator 3. An external Java code causes the NPE.
  • 36. String Interpolation / template in Kotlin fun hello(name: String) { println("Hello, $name") }
  • 37. String Interpolation in Java + Kotlin void hello(String name) { System.out.println("Hello, " + name); }
  • 38. Immutability Kotlin helps developers to be intentional about immutability. Immutability simply means that things you create can’t be changed. We need immutability because it: ● helps us with thread safety - no synchronization issues ● is good for value objects - objects that simply hold value, POJOs etc. ● helps debugging threaded applications without losing your hair
  • 39. Immutability How does it work in Java? ●Immutability in Java? final classes private fields no setters ● Immutability in Kotlin? Guess?
  • 40. Immutability How does Kotlin help? var vs val // compiler error: val cannot be reassigned val name = "Umar" name = name.toUpperCase() // works fine var name = "Umar" name = name.toUpperCase()
  • 41. Immutability How does Kotlin help? Immutable and Mutable collections // immutable collection val unchangeableHobbies = listOf("coding", "hiking") unchangeableHobbies.add() // add method doesn’t exist // mutable collection val changeableHobbies = mutableListOf("reading", "running") changeableHobbies.add("travelling") // you can add
  • 42. Immutability In Java vs Kotlin public final class ImmutableClassJava { private final String name; private final int age; public ImmutableClassJava(String name, int age) { this.name = name; this.age = age; } // no setters public String getName() { return name; } public int getAge() { return age; } } class ImmutableClassJava(val name: String, val age: Int) ● Class is final by default ●val implies that the parameters are final as well (values can’t be assigned)
  • 43. Functions // function sample fun sampleFunc() { // code goes here } A function is declared using the “fun” keyword
  • 44. Functions // function sample fun sampleFunc() { // code goes here } // function with param fun sampleFuncWithParam(param: String) { // code goes here } A function is declared using the “fun” keyword Method parameters use the “name:Type” notation
  • 45. Functions // function sample fun sampleFunc() { // code goes here } // function with param fun sampleFuncWithParam(param: String) { // code goes here } // func with param and return type fun capitalize(param: String): String { return param.toUpperCase() } A function is declared using the “fun” keyword Method parameters use the “name:Type” notation Return types are specified after the method definition.
  • 46. Functions - infix functions // infix function infix fun Int.times(x: Int): Int { return this * x } We can use the function as an arithmetic operator, i.e., using it without writing dots and parentheses.
  • 47. Functions - infix functions // infix function infix fun Int.times(x: Int): Int { return this * x } // usage fun useInfix() { val product = 2 times 5 println(product) } We can use the function as an arithmetic operator, i.e., using it without writing dots and parentheses.
  • 48. Functions - extension functions // extension function fun Int.square(): Int { return this * this } Extension function is a member function of a class that is defined outside the class
  • 49. Functions - extension functions // extension function fun Int.square(): Int { return this * this } Extension function is a member function of a class that is defined outside the class // usage fun useExtension() { val square = 2.square() println(square) }
  • 50. Functions Others: ● Higher order functions ● Lambdas ● Inline functions etc.
  • 55. Conciseness in Kotlin public void doSomething() { // do something } fun doSomething(): Unit { // do same thing }
  • 56. Conciseness in Kotlin public void doSomething() { // do something } fun doSomething(): Unit { // do same thing }
  • 57. Conciseness in Kotlin public void doSomething() { // do something } fun doSomething() { // do same thing }
  • 58. Conciseness in Kotlin public String getName() { return name; } fun getName(): String { return name }
  • 59. Conciseness in Kotlin public String getName() { return name; } fun getName() { return name }
  • 60. Conciseness in Kotlin public String getName() { return name; } fun getName() = name
  • 63. Class in Java vs Data Class in Kotlin public class Person { private String name; String getName () { return name; } void setName (String name) { this.name = name; } @Override public String toString () { return "Person{" + "name='" + name + ''' + '}'; } } data class Person(val name: String)
  • 64. Class in Java vs Regular Class in Kotlin public class Person { private String name; String getName () { return name; } void setName (String name) { this.name = name; } public int getNameLength () { return name.length } } class Person(name: String) { var name: String get() = name set(name) { this.name = name } fun getNameLength(): Int { return name.length } }
  • 65. Class in Java vs Regular Class in Kotlin public class Person { private String name; String getName () { return name; } void setName (String name) { this.name = name; } public int getNameLength () { return name.length } } class Person(name: String) { var name: String get() = name set(name) { this.name = name } fun getNameLength() = name.length }
  • 68. Important place to learn…….
  • 69. Important place to learn……. Tutorials Point - Kotlin
  • 70. Important place to learn……. Tutorials Point - Kotlin Kotlin for Android Developers – Antonio Leiva
  • 71. Important place to learn……. Tutorials Point - Kotlin Kotlin for Android Developers – Antonio Leiva Koans online – try.kotl.in/koans
  • 72. Important place to learn……. Tutorials Point - Kotlin Kotlin for Android Developers – Antonio Leiva Koans online – try.kotl.in/koans Kotlin Bootcamp for Programmers - Udacity
  • 73. Important place to learn……. Tutorials Point - Kotlin Kotlin for Android Developers – Antonio Leiva Koans online – try.kotl.in/koans Kotlin Bootcamp for Programmers - Udacity https://developer.android.com/kotlin/learn
  • 79. Summary • Interoperable with Java (100%) • Reduces Boilerplate code • Object-Oriented and procedural • Safety code • No Semicolon • Expands your skillset • Perfect Support with Android Studio & Gradle • Very easy to get started with Android Development
  • 81. Reduces Boilerplates codes like: findViewById, Async, build interfaces with Kotlin code etc
  • 82. Kotlin Android Extension it includes a view binder. The plugin automatically creates a set of properties that give direct access to all the views in the XML.
  • 83. Async Server - Client
  • 84. Finally You have 3 Options.. 1 Decide Kotlin is not For you and continue with Java
  • 85. Finally 1 Decide Kotlin is not For you and continue with Java You have 3 Options.. 2 Try to learn everything on your own
  • 86. Finally 1 Decide Kotlin is not For you and continue with Java You have 3 Options.. 3 Go and learn on MOOC websites 2 Try to learn everything on your own
  • 87. Questions ? Thank you! Android Development with Kotlin v1.0 ThisThis workwork isislicensedlicensed underunder thethe ApacheApache 2 2licenselicense.. 878787 Umar SaiduAuna Software Engineer, gidimo tech community Organizer umarauna
  • 88. A PROGRAMMING LANGUAGE THAT BRINGS JOY TO PROGRAMMERS INTRODUCTION TO KOTLIN
  • 89. SOFTWARE DEVELOPER AND TRAINER ABO UT ME • Android and IOS Developer. • Lead Mobile Developer for DOUBLET (App For Couples). • Project Lead and Lead Mobile Developer for KITCHLY (App for Food Lovers). • Software Trainer at Rework Academy. CONNECT: linkedin.com/in/young-batimehin- 5a6208159 YOUNG AYODEJI BATIMEHIN
  • 90. LET’s GET TO KNOW THE AUDIENCE
  • 91. 1) Introduction to Kotlin 2) Features 3) Kotlin Vs Java 4) Set Up Development Environment 5) Build a List App. 6) Conclusion and Questions. Today’s Agenda
  • 92. • Kotlin is a statically typed programming language. • It supports object-oriented programming and functional programming features. • It can also be compiled into Javascript source code. • Extension of the Kotlin is (.kt) • It’s a JVM targeted language. • Kotlin supports procedural programming with the use of functions. • Supports Multi-platform projects. • It is an open-source language. • It is now the official language for Android Development. INTRODUCTIO N KOTLIN
  • 93. FEATURES Use Kotlin for any type of Enterprise Java EE Development 100 % Compactible with all JVM frameworks Null Safety. Kotlin Avoids the null pointer exception when using or declaring variables. Kotlin wants you to write less code Familiar to Java. But you can still learn Kotlin without experience with java Automatic Conversion from Kotlin to java Strong Community Kotlin integrates well with all existing Java Frameworks and Libaries
  • 95. • Open Android Studio • Set-up Android project with Kotlin as code base • Brief explanation of all dependency and implementation • Implement Recycler View • Implement Cardview • Use Custom RecyclerView Adapter • Model Class • Layout Managers Set Up Development Environment FOR LIST APP