Kotlin Tutorial Beginner Guide for Kotlin Programming Language Tutorial

Install Kotlin and Developer tools in MAC

In this article, we are going to create our Kotlin development environment in Mac.

Below are the articles for installation steps in Windows and Linux

Step 1: Install Java

Kotlin is a JVM language and the compiler will emit Java bytecode. Because of this, we are going to install Java JDK. Visit below URL and download Java JDK.

Download Java JDK

Below images show the JDK Installation Steps in Mac

              

For ensuring our Java is Installed Correctly we are going to check the Java Version for this open Command prompt and execute command “java --version”

Below is the output

Step 2: Install Kotlin Compiler

Now JDK is installed we first going to download and Install Kotlin Compiler

Download Kotlin Compiler

Kotlin Compiler Downloaded file is available in Downloads. Extract the Zip file

01 Download and Extract Kotlin Compiler Zip File

01 Download and Extract Kotlin Compiler Zip File

Now we ready to use Kotlin Compiler.

Use Command Line Compiler to compile Kotlin Code

First, we are going to write a Hello vLemonn code. Then we are going to compile it using Kotlin Command Line Compiler. And in the last, we are going to run our compile code.

Before moving ahead we are assuming few things.

  1. We are assuming you downloaded the Kotlin Compiler from Github.
  2. Kotlin Compiler Zip file is available in Download folder. Zip file name “kotlin-compiler-1.2.0.zip” and extracted folder name kotlinc.
  3. File extracted in Download folder.

With the above assumption execute the following command. If some of the points are not valid from the above assumption, please modify commands.

For writing code, we are going to use terminal.

  • Open Terminal: First we are going to open bin folder available in Kotlin Compiler extracted directory. Execute the command “cd Downloads/kotlinc/bin”
  • Create our first Kotlin file. By executing below command we are creating a plain text file. The filename is HellovLemonn.kt and File Extension is .kt. Execute “sudo nano HellovLemonn.kt” command in terminal 

 

  • Copy and paste the following command into nano editor.
fun main(args: Array<String>) {
	println("Hello, vLemonn!")
}

 

  • Save your file using Ctrl+O and then press Ctrl+X to exit the terminal.
  • sudo ./kotlinc "HellovLemonn.kt" -include-runtime -d "HellovLemonn.jar" command is for compiling our first code file. Compiled output is a jar file.
  • Let’s execute above jar file. java -jar "HellovLemonn.jar" command is going to execute our output .jar file.Our compile code .jar file is available at Downloads/kotlin-compiler-1.2.0/kotlinc/bin

 

Below is the output

Step 3: Install IDE for Kotlin

Now we know about how to use Kotlin Compiler. It’s time to check IDE for Kotlin. Kotlin is developed by JetBrains so it is Supported by IntelliJ IDEA. We are going to use IntelliJ IDEA Community edition in our entire tutorial series. IntelliJ IDEA community edition is free to use. But if you want to use Eclipse IDE, then we are going to learn how to enable Kotlin plugin for Eclipse.

Visit below URL to download IntelliJ IDEA for Windows

Download IntelliJ IDEA

IntelliJ IDEA Setup is very easy. Double click on the downloaded setup file. Follow the instructions. Below images shows various installation windows.

                 

Step 4: Install Kotlin Eclipse Plugin [optional]

This step is not mandatory. If you love to write code in eclipse follow steps to add Kotlin Plugin.

Download Eclipse

                      

 

 

Finally, install Kotlin Plugin

             

 

0 Comments
Leave A Comment

Please login to post your valuable comments.

share