What is Kotlin and Why use it?

What is Kotlin and Why use it?

What is Kotlin?

  • Kotlin is a development language created by JetBrains, renowned for developing the world's leading commercial development tool, IntelliJ IDEA. It can be said that it was newly created by a group of experts with a deep understanding of the Java language to maintain enterprise-level applications with minimal effort. It was first introduced in 2011, went through a beta period, and 1.0 was released in 2016. As of 2024, 1.9.23 has been released. (Interestingly, JetBrains consists of Russian and Czech developers, and Kotlin is named after an island in Russia.)

The Future of Kotlin is Bright.

  • Kotlin was initially created by JetBrains, who actively lead its version upgrades. The fact that one of the world’s leading development tool manufacturers, spanning the Java, Python, and PHP communities, is behind this language suggests that it has a low chance of failing in the future.

  • More interestingly, in 2017, Google adopted Kotlin as the official language for Android. As of two years later, all reference documents issued by Google prioritize Kotlin. (Moreover, the official development tool for Android, Android Studio, was created by JetBrains.)

Kotlin is More Concise than Java.

  • One of the biggest shocks for someone coming from a scripting language to Java is its verbosity. For the simple purpose of holding data, one must repeatedly implement Getter, Setter, Equals, HashCode, ToString, etc., manually. Although this can be solved by using an external library like Lombok, it’s hard to escape the outdated and unproductive feeling inherent to the Java language. Kotlin neatly solves these issues at the language level with its data class. This is why once Java developers start using Kotlin, they can never go back.

  • Kotlin is one of the most advanced languages, resulting from the long deliberation of Java's top experts. Its concise design philosophy can be found throughout its basic syntax and libraries. Another charm of Kotlin’s conciseness is that it doesn't sacrifice the readability of the source code for brevity. Unless intentionally written in a complicated manner, there are hardly any cases where code reading is difficult.

Kotlin is Easy to Learn.

  • Explaining the code of an operating Java application to someone who is learning Java for the first time is not an easy task. Kotlin has eliminated verbosity at the language level. That is, it has minimized the parts of the basic syntax to memorize and reduced the source code needed for implementing logic, making it an entirely unburdening language for beginners. (According to a statistic, it took Java developers an hour to understand Kotlin source code, and they were fully adapted in three days.)

Kotlin is Friendly to Type-Safety.

  • Type-Safe means explicitly enforcing the specific type of a variable that has meaning from a data perspective at the source code level. For example, a variable holding a member's gender cannot contain any value other than MALE or FEMALE, and it ensures that this value does not change to a completely different type.

  • The reason Java has been the throne in the backend worldwide for so long is precisely because it encourages and aims for Type-Safe at the language level. Enterprise applications designed with Type-Safe in mind discover errors in the development compile stage. If designed only considering immediate productivity without regard for Type-Safe, errors are unexpectedly found after deployment under specific circumstances. While this may be acceptable for simple applications that can be quickly fixed and redeployed, it is not tolerated in crucial services handling money. This is why the most conservative financial sector insists on Java. (Meanwhile, JavaScript and its basis Node.js, along with Python, are dynamic typed languages that are completely opposite. The frontend sector, due to the high degree of freedom and dynamic typing characteristics of the JavaScript language, leading to an unbearable number of errors in enterprise-level applications with large teams, prompted Microsoft to introduce and popularize TypeScript to strongly control Type-Safe.)

  • However, there are not only advantages. Due to these characteristics, Java has the disadvantage of verbosity and unproductivity compared to other languages. But, with the emergence of Kotlin, it maintained the strengths of Type-Safe while also possessing conciseness and productivity as advantages. Moreover, Kotlin supports Null checks for variables, which is not available in Java. Therefore, Kotlin can be said to be very friendly to Type-Safe. (In fact, serious efforts are underway to solve HTML, CSS syntax through Kotlin's DSL to increase reusability and block errors at their source.)

Kotlin and Java are Interoperable.

  • Even if you recognize the advantages of Kotlin, the sigh that comes out at the thought of changing all the existing Java-developed legacy services to Kotlin. Is there no way? In fact, as mentioned earlier, since Java and Kotlin are siblings sharing the same JVM ecosystem, it is entirely possible to freely mix Kotlin in projects developed with Java. It is also feasible to write new features in Kotlin or to use existing developed classes in Kotlin. Whether to implement new features only or to change the entire thing is entirely up to the developer.

  • For methods to mix the two languages in a Spring Boot-based project, refer to this article on this blog.

Kotlin Can Use Java's Libraries and Frameworks.

  • Java is a very mature language, first released in 1995. Since then, countless talented developers around the world have freely shared a wealth of libraries and frameworks, arguably more so than any other language. As mentioned earlier, since Kotlin can be mixed with Java, libraries and frameworks can also be used as is. In fact, combining Kotlin with Java's celebrated technologies such as JPA, Hibernate, Spring Boot Data JPA, and Querydsl can be quite productive.

Kotlin and Java Perform Equally.

  • When source code written in Java or Kotlin is compiled, it is converted into byte code with a .class extension that can be executed in real operational environments, meaning that the final output of both languages is essentially the same. (It's obvious that performance cannot be discussed when the output is identical.) Therefore, the byte code can be executed as is in any operational environment where the JVM is installed. This is also why mixing Java and Kotlin languages within a project, and why you can use Java source code and libraries in Kotlin source code without any problems.

Kotlin is Within the JVM Ecosystem.

  • The entity that executes the compiled results of source code written in Java or Kotlin is called the JVM (Java Virtual Machine). The development of the JVM involves various global IT companies under the ownership of Oracle. As for free JVMs, Azul Zulu from the US is a leading example, and Amazon has also released Amazon Corretto, a JVM optimized for their EC2 instances.

  • Developing in Kotlin means being able to operate services under the high-performance JVM environment of this globally powerful ecosystem.

Further Reading