Kotlin

Software development as most of us know is a very fast-moving industry. New frameworks and languages are being developed all the time. Today I’d like to talk about a relatively new programming language Kotlin. Released in 2016, Kotlin had been in development since 2010 by JetBrains. Kotlin is a general-purpose programming language that is closely related to Java, even going as far as naming the language after an island just like Java was when it was created all the way back in 1995. Kotlin is designed to work in conjunction with the Java Virtual Machine (1). The Java Virtual Machine (JVM) is simply a virtual machine that allows any machine to run Java or Kotlin or any other JVM language by creating the framework of compiling your code into Java bytecode, a low-level code related to machine code, and then to machine code to be run on your machine.

Image result for jvm pipeline"

Plainly put, Kotlin was designed to directly replace Java by being a better programming language but still retaining all the power and versatility of Java. The strong link with Java is cited as being another strength as it allows companies to make a gradual seamless transition from Java to Kotlin (2). Kotlin’s biggest advantage over Java is its conciseness. Kotlin can declare classes, declare data structures and solve many complex problems in one tenth the amount of code as Java. This allows programmers to code faster without being bogged down in the time-consuming realm of syntax. It also enables the creation of code with a much higher level of readability and inherently makes coding safer as it prevents programmers from making mistakes that are common in less powerful languages (3). Overall, conciseness and readability can be a huge advantage for individual programmers and companies alike. Another big advantage is that it allows coders who are new to the language to learn it much quicker than most other languages and allows experienced programmers to code much faster and efficiently giving an additional productivity boost to companies. In fact, for this very reason since the introduction of Kotlin into Android studio Kotlin has surpassed Java as the preferred language of Android app developers (1). Here is an example of Kotlin class creation vs Java.

Image result for kotlin vs java"

As a software developer it is always exciting to learn about new technologies and languages. In my opinion always having the necessity to continue learning is one of the best parts of being a programmer. While I don’t think Java is going anywhere, Kotlin’s ease of use and the lack of 25 years of bundled legacy code, makes Kotlin an extremely appealing option for any savvy programmer. Overall, Kotlin is more of an iteration of Java, a step forward for an aging language, which is making a best effort to boil down the core principles and make a better language out of it.

If curious here is a long list of direct differences between Java and Kotlin from a great blog written by Vijay Singh (link to blog: https://hackr.io/blog/kotlin-vs-java)

Java vs Kotlin: Comparison

FeatureJavaKotlin
Checked ExceptionsAvailableUnavailable
Code ConcisenessCan’t be labeled as conciseBetter than Java
CoroutinesUnavailableAvailable
Data ClassesRequired to write a lot of boilerplate codeRequires adding only the data keyword in the class definition
Extension FunctionsUnavailableAvailable
Higher-Order Functions and LambdasHigher-order functions are implemented using Callables. Lambdas expressions are introduced in the Java 8Comes as one of the prebuilt features
Implicit Widening ConversionsAvailableUnavailable
Inline FunctionsUnavailableAvailable
Native Support for DelegationUnavailableAvailable
Non-private FieldsAvailableUnavailable
NullPointerExceptionsAvailableUnavailable
Primitive TypesVariables of a primitive type aren’t objectsVariables of a primitive type are objects
Smart CastsUnavailableAvailable
Static MembersAvailableUnavailable
Support for ConstructorsCan’t have secondary constructors. Although, can have multiple constructors (constructor overloading)Can have one or more secondary constructors
Ternary OperatorAvailableUnavailable
Wildcard TypesAvailableUnavailable, has declaration-site variance and type projects as an alternative

Sources:

  1. https://kotlinlang.org/api/latest/jvm/stdlib/index.html
  2. https://www.jrebel.com/blog/interview-with-kotlin-creator-andrey-breslav
  3. https://business.udemy.com/blog/kotlin-vs-java-9-benefits-of-kotlin-for-your-business/
  4. Vijay Singh’s blog post: https://hackr.io/blog/kotlin-vs-java

Image 1: https://image.slidesharecdn.com/ivankrylov-lifecycleofajitcompiledcode-180530151711/95/lifecycle-of-a-jit-compiled-code-4-638.jpg?cb=1527693632

Image 2: https://www.mediaan.com/wp-content/uploads/2019/02/Java_vs_Kotlin.png

Leave a comment

Design a site like this with WordPress.com
Get started