kotlin for android

20
Kotlin for Android Prepared by Shady Selim For GDG 6 October Google I/O 17 Event On 8/7/2017

Upload: shady-selim

Post on 21-Jan-2018

135 views

Category:

Technology


0 download

TRANSCRIPT

Kotlin for AndroidPrepared by Shady Selim

For GDG 6 October Google I/O 17 Event

On 8/7/2017

Speaker Bio

• Official Google Speaker

• GDG Helwan Founder & Leader

• Mobile & Web Evangelist

• Technology savvy

• Think tank, Father

• UI/UX freak

• Leader & Mentor

www.linkedin.com/in/shadyselim/

@dr_Shady_Selim

2

Who created Kotlin?

• IntelliJ IDEA

• PhpStorm

• ReSharper

• PyCharm

• RubyMine

• … others

3

What is Kotlin?

4

Why Kotlin Now?

5

6

Is Kotlin Really new?

7

Why Should I care!!?

• Statically typed programming language targeting the JVM

• Support for functional and OO paradigms

• Pragmatic, safe, concise, great Java interop

• Free and open-source

• Drastically reduce the amount of boilerplate code

• Lambda expression

• Avoid entire classes of errors such as null pointer exceptions

• Java 9 is …

8

The Strengths of Kotlin

• Modeling the data of your application concisely and expressively

• Creating reusable abstractions using functional programming techniques

• Creating expressive domain-specific languages

• Java interop ensures that all existing Java frameworks can be used

• No rewrite required to start using Kotlin in existing codebase

• Existing investment is fully preserved

9

Java Model Example

10

public class Customer {

private String name;

private String email;

private String company;

public Customer(String name) {

this(name, "", "");

}

public Customer(String name, String email) {

this(name, email, "");

}

public Customer(String name, String email, String company) {

this.name = name;

this.email = email;

this.company = company;

}

Java Model Example, cont.

11

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getEmail() {

return email;

}

public void setEmail(String email) {

this.email = email;

}

Java Model Example, cont.

12

public String getCompany() {

return company;

}

public void setCompany(String company) {

this.company = company;

}

@Override

public boolean equals(Object o) {

if (this == o) return true;

if (o == null || getClass() != o.getClass()) return false;

Customer customer = (Customer) o;

if (name != null ? !name.equals(customer.name) : customer.name != null) return false;

if (email != null ? !email.equals(customer.email) : customer.email != null) return false;

return company != null ? company.equals(customer.company) : customer.company == null;

}

Java Model Example, cont.

13

@Override

public int hashCode() {

int result = name != null ? name.hashCode() : 0;

result = 31 * result + (email != null ? email.hashCode() : 0);

result = 31 * result + (company != null ? company.hashCode() : 0);

return result;

}

@Override

public String toString() {

return "Customer{" +

"name='" + name + '\'' +

", email='" + email + '\'' +

", company='" + company + '\'' +

'}';

}

}

Kotlin Model Example, cont.

14

data class Customer(var name: String,

var email: String = "",

var company: String = "")

Do you like reactive programming?

15

You will not miss your frameworks or libraries

16

You will not miss your frameworks or libraries

17

kotlin.link

18

Resources

• https://kotlinlang.org/

• https://m.signalvnoise.com/kotlin-its-the-little-things-8c0f501bc6ea

• https://www.jetbrains.com/

• https://www.slideshare.net/intelliyole/kotlin-why-do-you-care

• https://github.com/ReactiveX/RxKotlin

• https://spring.io/blog/2016/02/15/developing-spring-boot-applications-with-kotlin

• https://www.slideshare.net/makingx/spring-kotlin

• https://kotlin.link/

19

Questions!?

20