Open In App
Related Articles

Introduction to Kotlin

Improve Article
Save Article
Like Article

Kotlin is a statically typed, general-purpose programming language developed by JetBrains, that has built world-class IDEs like IntelliJ IDEA, PhpStorm, Appcode, etc. It was first introduced by JetBrains in 2011 and a new language for the JVM. Kotlin is object-oriented language, and a “better language” than Java, but still be fully interoperable with Java code.

Kotlin is sponsored by Google, announced as one of the official languages for Android Development in 2017.

Example of Kotlin –

fun main()
    println("Hello Geeks");

Key Features of Kotlin:

  1. Statically typed – Statically typed is a programming language characteristic that means the type of every variable and expression is known at compile time. Although it is statically typed language, it does not require you to explicitly specify the type of every variable you declare.
  2. Data Classes– In Kotlin, there are Data Classes which lead to auto-generation of boilerplate like equals, hashCode, toString, getters/setters and much more.

    Consider the following example –

    /*     Java Code     */
    class Book {
        private String title;
        private Author author;
        public String getTitle()
            return title;
        public void setTitle(String title)
            this.title = title;
        public Author getAuthor()
            return author;
        public void setAuthor(Author author)
   = author;


    But in Kotlin only one line used to define the above class –

    /* Kotlin Code */
    data class Book(var title:String, var author:Author)
  3. Concise – It drastically reduces the extra code written in other object-oriented programming languages.
  4. Safe – It provides the safety from most annoying and irritating NullPointerExceptions by supporting nullability as part of its system.
    Every variable in Kotlin is non-null by default.

    String s = "Hello Geeks"    // Non-null 

    If we try to assign s null value then it gives compile time error.So,

    s = null                    // compile time error

    To assign null value to any string string it should be declared as nullable.

    String nullableStr? = null  // compiles successfully

    length() function also disabled on the nullable strings.

  5. Interoperable with Java – Kotlin runs on Java Virtual Machine(JVM) so it is totally interoperable with java. We can easily access use java code from kotlin and kotlin code from java.
  6. Functional and Object Oriented Capabilities – Kotlin has rich set of many useful methods which includes higher-order functions, lambda expressions, operator overloading, lazy evaluation, operator overloading and much more.
    Higher order function is a function which accepts function as a parameter or returns a function or can do both.

    Example of higher-order function –

    fun myFun(company: String,product: String, fn: (String,String) -> String): Unit {
        val result = fn(company,product)
    fun main(args: Array){
        val fn:(String,String)->String={org,portal->"$org develops $portal"}


    JetBrains develops Kotlin
  7. Smart Cast – It explicitly typecasts the immutable values and inserts the value in its safe cast automatically.
    If we try to access a nullable type of String ( String? = “BYE”) without safe cast it will generate a compile error.

    fun main(args: Array){
        var string: String? = "BYE"          
            print(string.length)       // compile time error
    fun main(args: Array){
        var string: String? = "BYE"
        if(string != null) {               // smart cast
  8. Compilation time – It has higher performance and fast compilation time.
  9. Tool- Friendly – It has excellent tooling support. Any of the Java IDEs – IntelliJ IDEA, Eclipse and Android Studio can be used for Kotlin. We can also be run Kotlin program from command line.

Advantages of Kotlin language:

  • Easy to learn – Basic is almost similar to java.If anybody worked in java then easily understand in no time.
  • Kotlin is multi-platform – Kotlin is supported by all IDEs of java so you can write your program and execute them on any machine which supports JVM.
  • It’s much safer than Java.
  • It allows using the Java frameworks and libraries in your new Kotlin projects by using advanced frameworks without any need to change the whole project in Java.
  • Kotlin programming language, including the compiler, libraries and all the tooling is completely free and open source and available on github. Here is the link for Github

Applications of Kotlin language:

  • You can use Kotlin to build Android Application.
  • Kotlin can also compile to JavaScript, and making it available for the frontend.
  • It is also designed to work well for web development and server-side development.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 06 Dec, 2019
Like Article
Save Article
Similar Reads