Kotlin tutorial for beginner : Introduction and setup

Kotlin for beginner - Part one (Setup):

Kotlin was developed by JetBrains, the company behind different popular products like IntelliJ IDEA, PyCharm, RubyMine etc. They have started it in July 2011, but the first official stable release was on Feb 15, 2016(Kotlin V1.0). Kotlin is an opensource project under Apache 2 license. On Google IO 2017, Google has announced full Kotlin support for Android development and starting Android Studio 3.0, kotlin is included in the Android Studio by default. You can even run kotlin code along with Java code. This is our first post on kotlin. In this tutorial, we will learn the basics of Kotlin language, how to setup and how to run a simple program. Let’s take a look :

What development IDE to use for Kotlin?

Different IDE is available for Kotlin. You can use any one of them or use the one you use regularly. We are not going to discuss in details about the installation because it is different for different IDEs and it may change in the future. You can check the official installation guide for more details. You can use any one of the following IDE for kotlin development :

  1. IntelliJ IDEA
  2. Eclipse 
  3. NetBeans 
  4. Visual Studio code

We are going to use IntelliJ IDEA for our tutorials. The main reason is that we have a future plan to write Android development tutorials using kotlin and since the Android studio is developed on IntelliJ, it will be easier for you to pick up.

How to create a simple “Hello World” application on Kotlin using IntelliJ IDEA :

  1. First of all, download the IntelliJ IDEA from the link above, install and run it. One new window will open, click on “Create new project” and select the option Kotlin/JVM on that window :

kotlin 1 2. Enter your project name and location :

kotlin 2 3. Open the left window and you will see the project folders like below :

kotlin 3 4. Now, we will create our first class on this project. Right-click on the src folder, click on new and then click on Kotlin File/ class. It will show you one popup. Write one name for the class and make sure to select the Kind as file.

kotlin 4 5. Start writing main and it will show you one prediction of main function. Click enter and one function with name will be printed out :

fun main(args: Array) {

}

Now, write one println() method with Hello world !! as its argument string :

fun main(args: Array) {
    println("Hello world !!")
}

kotlin 5 Run the program using the little green play button near the method name and it will print out the result :

kotlin 6 That’s it. You have run your first kotlin program. We will explore kotlin more on our next tutorials.