top of page

How to start Kotlin development with Spring+Maven


What is Kotlin?

  1. Kotlin is open source statically typed(type safety) programming language introduced by jet-brains

  2. Kotlin runs on the Java virtual machine so it works great with all existing Java libraries/frameworks and runs with the same level of performance as Java.

  3. It supports all object oriented programming principle & the main advantages it greatly support functional and reactive programming

Release history of kotlin:

  • Kotlin v1.0 was released on February 15, 2016. This is considered to be the first officially stable release

  • in 2017, google comes with KOTLIN project by jet brains and adopted as a first language for android development

  • Kotlin v1.2 was released on November 28, 2017.Sharing Code between JVM and JavaScript platforms feature was newly added to this release.

What are the advantages of Kotlin over Java?

Kotlin is derived from the java language and inherits its advantage and overcomes its limitations. Below are some advantages of kotlin over java.

  • Concise - Drastically reduce the amount of boilerplate code.

  • Safe - Avoid entire classes of errors such as null pointer exception.

  • Lazy-Loading - The lazy-loading feature basically increases the startup time, which is very useful when using Kotlin for Android app development. In simple words, it’s the best solution for all developers who wants to reduce their Android app startup time so that their apps’ content can be shown faster

  • Interoperable - One of the major as well as best features of Kotlin is its deep interoperability with Java. This, in fact, has attracted many Java developers as well as Android app developers to learn Kotlin

  • Extension - Extensions of Kotlin are very useful because they allow developers to add methods to classes without making changes to their source code. Just like Scala’s implicit methods, in Kotlin you can add methods on a per-user basis to classes

  • Tool friendly - Choose any java IDE or build from command line.

Companies like Pinterest, Uber, Evernote and Coursera, etc. are using kotlin languages in many parts of application program and apps.

This Article will help you with the first step for starting development with Spring Kotlin language by building a Kotlin HelloWorld example using SpringBoot, Maven

Before develop let’s set up Environment First

Install Kotlin Plugin for Eclipse

This Kotlin Plugin for Eclipse helps you write, run, debug and test programs in Kotlin language.

Steps:

1. Go to main menu click on help install new software

2. Add kotlin plugin for eclipse with link like below

Link: https://dl.bintray.com/jetbrains/kotlin/eclipse-plugin/last/

Then we will get eclipse plugin in Tab like below

Then click on Kotlin check box and click next

3. Now follow the guides to install Kotlin plugin. After all is done, we will get a Software Update message dialog

Now Press Yes, then once it complete you will get warning to restart your Eclipse

Click yes and restart it

Create SpringBoot project with Kotlin language:

Open Eclipse, choose File -> New -> Other -> Spring Starter Project

Next mention artifact, groupid and environment details in Tab like below

Now Press Next you will get one more tab to add dependency like below

Click on Finish, then application will be imported to your workspace

Open Project structure

You can check the extension of file is “.kt”

Open class SpringBootKotlinExampleApplication, then write some print statement as below

As by default this SpringBootKotlinExampleApplication is final in Kotlin, so it is not able to Enable @AutoConfiguration so make it Non-final just add ‘open’ keyword on class level like below

Now right click this main class, and run it as Kotlin application like below

Now check the console, below you will find response

Source code : Download

YouTube : Video

 


bottom of page