Kotlin - Big word for android developers

Hello 
I am back with one another new concept for android developers

Technologies & languages are getting updated with time... & here is one another
"Kotlin language"

What is "Kotlin"?

Kotlin is a "Statically typed programming language for modern multi-platform applications".

Best thing is kotlin is 100% inter operable with Java and Android.


What does it look like?

Concise, simple and very easy to read (and write)

package hello //Optional package header //Package-level function, which takes an Array of strings as a parameter fun main(args: Array<String>) { println("Hello World!") //Have you noticed? Semicolons are optional }

Why use Kotlin for Android Development?

1. Concise : Drastically reduce the amount of boilerplate code.

Examples :


Create a POJO with getters, setters, equals(), hashCode(), toString() and copy() in a single line:
data class Customer(val name: String, val email: String, val company: String)
Or filter a list using a lambda expression:
val positiveNumbers = list.filter { it > 0 }

Want a singleton? Create an object:
object ThisIsASingleton {
    val companyName: String = "JetBrains"
}



2. Safe : Avoid entire classes of errors such as null pointer exceptions.

Examples:

Get rid of those pesky NullPointerExceptions, you know, The Billion Dollar Mistake

var output: String
output = null   // Compilation error

Kotlin protects you from mistakenly operating on nullable types
val name: String? = null    // Nullable type
println(name.length())      // Compilation error

And if you check a type is right, the compiler will auto-cast it for you
fun calculateTotal(obj: Any) {
    if (obj is Invoice)
        obj.calculateTotal()
}

3. Interoperable : Leverage existing libraries for JVM, Android and the browser.

Examples:

Use any existing library on the JVM, as there’s 100% compatibility, including SAM support.
import io.reactivex.Flowable
import io.reactivex.schedulers.Schedulers

Flowable
    .fromCallable {
        Thread.sleep(1000) //  imitate expensive computation
        "Done"
    }
    .subscribeOn(Schedulers.io())
    .observeOn(Schedulers.single())
    .subscribe(::println, Throwable::printStackTrace)

Target either the JVM or JavaScript. Write code in Kotlin and decide where you want to deploy to
import kotlin.browser.window

fun onLoad() {
    window.document.body!!.innerHTML += "<br/>Hello, Kotlin!"
}


4. Tool-friendly : Choose any Java IDE or build from the command line.

Examples:

A language needs tooling and at JetBrains, it's what we do best!



That is just the basic things that everyone should know..

Learning Kotlin for a Java developer shouldn’t be too hard. 

Here is official website for kotlin:
https://kotlinlang.org/


I am always here to answer your questions & queries, don't forget to comment if you like & also if you want any other concept to explore..

Also, Please share you thoughts about kotlin..

Is Kotlin is better than java or not so good??

& keep waiting for more... because there is more to explore.. till that bye.. have a good day.. :D

Comments

Popular posts from this blog

FCM - Firebase cloud messanfing for Notification

Read sms automatically to verify OTP

Create shapes online - Android Shapes Generator