Coding Friction

Kotlin Introduction

What is kotlin?

Kotlin is a statically typed, object-oriented language and general-purpose programming language

It runs on JVM. It’s compatible with Java that means java code can be used in kotlin

Why Use Kotlin?

  • kotlin is open source programming language.
  • Easy to learn. it has basic syntax. If you know java
  • it’s compatible with Java
  • it’s multiplatform so you can run program on any machine which supports JVM.
  • it is safe than java

Features of Kotlin

  • Null safety: kotlin eliminate the NullPointerException by providing null safety features . In Kotlin every variable is Non nullable.
  • Concise : It reduces writting the extra code.
  • Compilation Time: It has better performance and fast compilation time
  • Interoperable: you can use java code from kotlin and kotlin code from java.
  • Statically typed: that means every variable and expression will be checked on compile time.
  • Smart Cast: It explicitly typecasts the immutable values  and inserts the value in its safe cast automatically.

if try to access without smart cast it gives compile time error

fun main(args: Array){
    var str: String? = "Coding Friction"          
        print(str.length)       // compile time error
fun main(args: Array){
    var str: String? = "Coding Friction"
    if(str!= null) {               // smart cast
     print(str?.length) //  can't get length if str is null 

Applications of Kotlin language:

  • Android  applications
  • Web development
  • Server side applications And more.