ZOFTINO.COM android and web dev tutorials

Running Kotlin Program in Eclipse

In this tutorial, you can learn how to setup eclipse for writing programs in Kotlin, create Kotlin project, write a sample Kotlin program and run it in eclipse.

Installing Kotlin Eclipse Plugin

First install eclipse by downloading it from eclipse website. To use eclipse for writing kotlin programs, you need to install kotlin eclipse plugin. To install kotlin plugin in Ecipse, go to Help menu and click Eclipse Marketplace.

eclipse marketplace

Type kotlin in the find text box and enter. It will display kotlin plugin for eclipse with install button which you need to click to start installing the plugin.

eclipse marketplace search kotlin click install

Then it will display license terms window where you need to accept license terms by selecting the radio button and click finish to complete the installation.

kotlin eclipse plugin installation accept license terms

Creating Kotlin Project in Eclipse

Following are the steps to create kotlin project.

Go to File > New menu and click other, it will open select wizard window. In the window, expand kotlin folder, select kotlin project wizart and click next.

eclipse create kotlin project

Next, it will display kotlin project window where you need to enter project name.

eclipse create kotlin project enter project name

It will create kotlin project with project structure shown in the following image.

kotlin project structure

Kotlin Program

Kotlin file contains kotlin code. So, you need to create kotlin file to write program. To do that, right click the src folder in your kotlin project, select new > other menu, and then select kotlin file.

create kotlin file

Then in the next window, enter package name and file name.

create kotlin file enter package file name

Like in Java, the starting point of kotlin program is main routine. To create main routine, open the kotlin file which you have created, type main in it and hit ctrl-space to auto complete it.

kotlin main routine

Then add code in the main routine. Following examples takes input from user and prints it. It uses Java Scanner class.

package com.zoftino.kotlin.sample

import java.util.Scanner

fun main(args: Array<String>) {
	println("Enter your name:");
	val input = Scanner(System.`in`)
    val name = input.next();
	println("Hello "+name);
}

Running Kotlin Program

To run kotlin program, click Run menu and run as and then select kotlin application.

running kotlin program

Here is the output of the program.

Enter your name:
kotlin
Hello kotlin