Getting Started with Kotlin

Reading Time: 2 minutes

Introduction:

In this blog, I am going to discuss the basics of the kotlin programming language. Kotlin is a statically, typically programmed programming language developed by JetBrains. It produces world-class IDEs like IntelliJ IDEA, PhpStorm, Appcode, etc. However, It was first introduced by JetBrains in 2011 with the new JVM language. It is an object-oriented language and a “better language” than Java. This language is still fully compatible with Java code.

Some features of Kotlin:

  • Statically Type: In addition, Statically type is a feature of programming language. That is the type of all the variables and expressions are known at the time of compilation.
  • Concise: Meanwhile it drastically reduces the extra code written in other object-oriented programming languages.
  • Safe:  It provides the safety from most annoying and irritating NullPointerExceptions by supporting nullability as part of its system.
  • Interoperqable with java: It runs on JVM (Java Virtual Machine) so it is totally interoperable with java. We can easily access use java code from kotlin and kotlin code from java.
  • Compilation time: The performance and compilation time of is very high.
  • Tool-Friendly: It has excellent tool support. We an use any Java IDE like intellij, Eclipse etc for kotlin programming.

Applications:

  • We can use it for building android applications.
  • It can also compile to JavaScript, and making it available for the frontend.
  • We can also use it for web development and sever-side development.

Kotlin installation in Linux:

Step 1: Creating Packages

Open your Linux terminal and update your package information from all configured sources.

# sudo apt update

Step 2: Install jdk

As it is based on JDK so for that, you have to install Java Development Kit.

# sudo apt install default-jdk

Step 3: Install Kotlin using SDKMAN

Since SDKMAN is an easier way to install Kotlin on UNIX-based systems. After Installing SDKMAN restart your computer.

# curl -s https://get.sdkman.io | bash

Now we will install Kotlin using the following command.

# sdk install kotlin

Now, we will check the version using the following command.

# kotlin -version 

After the installation, we will create a Kotlin file and check it by doing compile and run.

Step 4: Creating kotlin file

Open any text editor and write the following code and save it with the .kt extension.

For creating a file write nano fileName.kt in your terminal. Then write your Kotlin code inside that file and save it using ctrl + x and then press y.  


// Function in Kotlin
fun main(args: Array<String>) {
    
    // Print statement
    println("Hello World!!!!")
}

Step 5: Compile kotlin file

Navigate to that folder in which you have created your file and then compile that file using the following command. Replace Kotlin.kt with your file name and the value of the -d option specifies the name of the output file.

# kotlinc Kotlin.kt -include-runtime -d outPutFile.jar

Step 5: Run the Program

# java -jar outPutFile.jar

Output: Hello World!!!!

Conclusion:

In conclusion, in this blog, we have learned about the basics knowledge and overview of Kotlin programming language. I will cover more topics in the further blogs. Happy learning 🙂

For more, you can refer to the kotlin documentation: https://kotlinlang.org/docs/getting-started.html#create-your-powerful-application-with-kotlin

Checkout more Kotlin Blogs here.

knoldus

Written by 

Hello! Currently, I am Software Consultant at Knoldus Inc. I have completed my B.Tech from Abdul Kalam Technical University. Right now I am focusing on JAVA Frameworks. Apart from that my hobbies are playing guitar and listening to music.