Kotlin Introduction

Latest posts
Get notified of the Latest Sport News Update from Our Blog
Share

What is kotlin?

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

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

History of Kotlin

Kotlin is developed by JetBrains and it was first introduced in 2011 and officially announced as a new language for Android development by Google in 2017.

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 eliminates the NullPointerException by providing null safety features. In Kotlin every variable is NonNullable.
  • Concise : Kotlin is known for its concise syntax, reducing the amount of boilerplate code required. This results in cleaner and more readable code compared to Java. It reduces writing the extra code.
  • Compilation Time: It has better performance and fast compilation time
  • Interoperable: we can use java code in kotlin programs and kotlin code in java programs.
  • Statically typed: That means every variable and expression will be checked on compile time.
  • Coroutines: Kotlin introduces coroutines, which are a powerful and lightweight concurrency design pattern. It simplify asynchronous programming, making it easier to write asynchronous code without the complexity of callbacks.
  • Extension Functions: Extension functions are a powerful feature in Kotlin that allow you to add new functions to existing classes without modifying their source code. Extension functions in Kotlin are declared outside the class
  • Smart Cast: Smart casting allows the compiler to automatically cast a variable after a type check. In simpler terms, if you’ve checked the type of a variable, Kotlin understands it and lets you use it as that type without needing an explicit cast. let’s take an example

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(){
    var str1: String? = "Coding Friction"
    var str2:String? = null
    println(str2 is String) // false
    if(str1 is String) {            
        // No need for explicit casting, Kotlin smart casts 'value' to String
        // here not using null safety operator
        println(str1.length) // 15
    }
    println(str1?.length)//15 
}

Applications of Kotlin language:

  • Android  applications
  • Web development
  • Server side applications And more.
  • Desktop Applications:

Related blogs

Nullam quis risus eget urna mollis ornare vel eu leo. Aenean lacinia bibendum nulla sed 

Subscribe to get 15% discount