About Kotlin

Reading Time: 3 minutes

What is Kotlin all about?

It is a new programming language targeting the Java platform. Kotlin is concise, safe, pragmatic, and focused on interoperability with Java code. It can be used almost everywhere Java is used today.

  • For server-side development
  • Android apps
  • JavaScript
  • Native
    • Kotlin/Native is a technology for compiling Kotlin code to native binaries, which can run without a virtual machine.

Kotlin works great with all existing Java libraries and framworks and runs with the same level of performance as Java.

Target platforms: Server-side, Android, anywhere Java runs

The primary goal of Kotlin is to provide a more concise, more productive, safer alternative to Java that’s suitable in all contexts where Java is used today. Java is an extremly popular language, and it is used in a broad variety of environments, from smart cards to the largest data centers run by Google, Twitter, LinkedIn, and other internet-scale companies. In most of these places, using Kotlin can help developers achieve their goals with less code and fewer annoyances along the way.

The most common areas to use Kotlin are

  • Building server-side code (typically, backends of web applications)
  • Building mobile applications that run on Android devices

In addition to Java, Kotlin can be compiled to JavaScript, allowing you to run Kotlin code in the browser.

Statically typed

Just like Java, Kotlin is a statically typed programming language.

This means the type of every expression in a program is known at complie time, and the compiler can validate that the methods and fields you are trying to access exist on the objects you are using.

Following are some of the benefits of static typing

  • Performance – Calling methods is faster because there’s no need to figure out at runtime which method needs to be called.
  • Reliability – The compiler verifies the correctness of the program, so there are fewer chances for crashes at runtime.
  • Maintainability – Working with unfamilier code is easier because you can see what kind of objects the code is working with.
  • Tool support – Static typing enables reliable refactorings, precise code completion, and other IDE features.

Kotlin doesn’t require you to specify the tpye of every variables explicitly in your source code. In many cases, the type of a veriable can automatically be determined from the context, allowing you to omit the type declaration.

You are declaring a variable, and because it is initialized with an integer value, Kotlin automatically determines that its type is Int. The abilitiy of the complier to determine types from context is called type interference.

Free and open sourced

The Kotlin language, including the complier, libraries, and all releated tooling, is entirely open sourced and free to use for any purpose.

The development happens in the open on GitHub and communitiy contributions are welcome.

Kotlin source code on GitHub

You also have a choice of three open source IDEs for developing your Kotlin applications:

  • IntelliJ IDEA
  • Android Studio
  • Eclipse

Kotlin on Android

A typical mobile application is much different from a typical enterprise application. It is much smaller, it is less dependent on integration with existing codebases and it usually needs to be delivered quickly while ensuring reliable operation on a larger variety of devices. Kotlin works just as well for projects of that kind.

Kotlin’s language features, combined with a special complier plug-in supporting the Android framework, turn Android Development into a much more productive and pleasurable experience. Common development tasks, such as adding listeners to controls or binding layout elements to fields, can be accomplished with much less code, or sometimes with no code at all, because the complier generate it for you.

Another big advantage of using is better application reliability. If you have any experience developing Android applications, you are no doubt familiar with the dialog:

Unfortunetly, Process Has Stopped

This dialog is shown when your application throws an unhandled exception, in many cases, a NullPointerException. Kotlin’s type system, with its precise tracking of null values, makes the problem of null pointer exceptions much less pressing. Most of the code that would lead to a NullPointerException in Java fails to complie in Kotlin, ensuring that you fix the error before the application gets to your users.

Summary

Kotlin is statically typed and supports type interference, allowing it to maintain correctness and performance while keeping the source code concise.

Kotlin supports both object-oriented and functional programming styles, enabling higher-level abstractions through first-class functions and simplifying testing and multithreaded development through the support of immutable values.

It works well for server-side applications, fully supporting all existing Java frameworks and providing new tools for common tasks such as HTML generation and persistence.

It works for Android as well, thank to a compact runtime, special compiler supports for Android APIs, and a rich library providing Kotlin-friendly functions for common Android development tasks.

It is free and open source, with full support for the major IDEs and build systems.

Kotlin is pragmatic, safe, concise and interoperable, meaning it focuses on using proven solutions for common tasks, preventing common erros such a NullPointerExceptions, supporting compact and easy-to-read code, and providing unrestricted integraion with Java.

 Source: Dimitry Jemerov, Svetlana Isakova: Kotlin in action 

Follow and like us:

Click to rate this post!
[Total: 0 Average: 0]

Leave a comment

stay informed!

Subscribe to receive exclusive content and notifications