E-Multitech Solution

Blog

Why Kotlin better than Java?

Bibek Sharma in Discussion Discussion, Mobile Apps

1 Comment

KOTLIN

Kotlin is statically typed open source programming language for modern multiplatform applications. Kotlin was primary developed by programmers of JetBrains. Kotlin runs on Java Virtual Machine (JVM) and also can be compiled to JavaScript source code. While the syntax is not compatible with Java, the JVM implementation of Kotlin’s standard library is designed to interoperate with Java code and is reliant on Java code from the existing Java Class Library, such as the collections framework. Kotlin uses aggressive type inference to determine the type of values and expressions for which type has been left unstated. The file extensions of Kotlin file are .kt or .kts.

 

A little bit of History

JetBrains unveiled a new language for the JVM in July 2011, Project Kotlin, named after Kotlin Island near St. Petersburg Russia. The first officially stable release v1.0 was released in Feb 15, 2016.

Kotlin was announced the first-class supported language for Android at Google I/O 2017.

 

Why Kotlin? (More like, Why Kotlin over Java.)

JetBrains lead Dmitry Jemerov said that most languages did not have the features they were looking for.

Development lead Andrey Breslav has said that Kotlin is designed to be an industrial-strength object-oriented language, and a “better language” than Java, but still be fully interoperable with Java code, allowing companies to make a gradual migration from Java to Kotlin.

They needed a language better then Java and Kotlin was made to be better than Java.

 

So what makes Kotlin better?

  1. Concise

Drastically reduce the amount of boilerplate code.

  1. Safe

Avoid entire classes of errors such as null pointer exceptions.

  1. Interoperable

Leverage existing libraries for the JVM, Android, and the browser.

  1. Tool-friendly

Choose any Java IDE or build from the command line.

 

Open Source

Kotlin is an open source project under Apache 2 license. Kotlin project can be found in Github:

https://github.com/JetBrains/kotlin

The project has more than 230+ open source contributors, 1400+ branches, 10000+ release and 47000+ commits.

COOL RIGHT!!!

 

Where to use?

One can use Kotlin to build applications for:

  1. JVM Applications
  2. Android Applications
  3. Browser Applications
  4. Native Applications

 

Ok Enough of Talking… Let’s code Hello World.

You don’t even need to setup the environment to run Kotlin codes. Yes you heard it right. You can try Kotlin code in online tool:

https://try.kotlinlang.org

Also there are tools available that you can explore Kotlin with:

  1. Intellij IDEA

Bundled with Community Edition or Intellij IDEA Ultimate

  1. Android Studio

Bundled with Studio 3.0 or plugin available for earlier versions

  1. Eclipse

Install the plugin from the Eclipse marketplace

  1. Compiler

Use any editor and build from the command line

 

Hello World!!

 

fun main(args: Array<String>) {

    println(“Hello, world!”)

}

 

Yeah that’s it… That’s one complete program. Notice there is optional package header.

Also Good Bye to the semicolons. Or if you are in love with them you can keep it. It’s optional.

 

 

KOTLIN on Android

From on 2017 Kotlin is officially supported language on Android. Its interoperable with the existing Android language and runtime. Also Kotlin and Java can be mixed together. A method in Kotlin class can be called from Java and vice versa.

 

Kotlin for Android is expressive, concise, safe and powerful. Kotlin is safe as it checks nullability at compile time hence no more NullPointerExceptions. I know you are relieved, NO NULL POINTERS. It contains safety features for nullability and immutability, to make your Android apps healthy and performance by default.

 

Again its a Goodbye time, Say Goodbye to findViewById()

You know findViewById()  is an expensive process. But with Kotlin’s kotlinx.android.synthetic library you can directly use views without need to initialize them with findViewById()

 

Get Started With Kotlin on Android

If you want to develop Android App with Kotlin or you want to implement Kotlin in your existing project then you can start doing right away. You don’t even need to know Kotlin. That’s because of the 100% interoperability of Kotlin with Java and great tooling support of Android Studio.

 

Kotlin is 100% interoperable with Java means you can add Java files and Kotlin files both in your project and you can call Java methods from Kotlin files and vice versa.

 

And if you don’t yet know the Kotlin syntax or you got in problem somewhere with new Kotlin code then no worries, you can write the code in Java file and copy-paste it in Kotlin file it will convert the code for you. Or you can convert Java files to Kotlin files also.

 

So what are you waiting for GET GOING WITH KOTLIN!

Just do it and you will thank me later!

 

Here are some useful links for you that might help:

 

  1. Kotlin Github Project

https://github.com/JetBrains/kotlin

  1. Kotlin Online Tools

https://try.kotlinlang.org/

  1. Kotlin Refrence

https://kotlinlang.org/docs/reference/

  1. Kotlin Tutorial

https://kotlinlang.org/docs/tutorials/

  1. Other Kotlin Resources

https://kotlinlang.org/docs/resources.html

  1. Kotlin Books

https://kotlinlang.org/docs/books.html

  1. Blog

http://blog.jetbrains.com/kotlin

  1. Kotlin Community

https://kotlinlang.org/community.html

  1. Twitter

https://twitter.com/kotlin

  1. Issue Tracker

https://youtrack.jetbrains.com/issues/KT

1 Comments

Leave a Comment.

Verify CAPTCHA *