A talk on what what you need to know in kotlin before you get started, and how easy its going to be especially to Java Developers. Presented in DevFest Jalingo 2018
GDG Minna 2014. - Graduate of BUK CS Student. - Founded Sysbit Nigeria. - Intern @ Flexisaf Edusoft. - Volunteer @ Nigerian Red Cross Society. - and I love meeting new people.
based language developed by JetBrains, a company known for the creation of IntelliJ IDEA, a powerful IDE for Java development. In Kotlin everything is an Object.
based language developed by JetBrains, 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).
based language developed by JetBrains, 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
based language developed by JetBrains, 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
NullPointerException the $1,000,000,000 mistake // compiler error var name: String A non-nullable object can’t be null name = null // compiler error Specify a nullable object by using “?” var name: String? val length = name.length Kotlin ensures that you don’t mistakenly operate on nullable objects
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.
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
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”
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!!!
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
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 ImmutableClass(val name: String, val age: Int, val grade: Char, val hobbies: List<String>) • Class is final by default • val implies that the parameters are final as well (values can’t be assigned)
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
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.
• 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