Moving from Java to Kotlin (Android)

1 minute read

Published:

The first time I heard about Kotlin I thought of it as a new language with a different syntax, but then I turned out to be wrong!

Here’s how I started my journey in turning Java into Kotlin:

At first, I started looking for a way to convert Java syntax to Kotlin as I thought the way I code is constant while language is a variable. So when moving from a language to another nothing will change except for the syntax, and as a result, I decided to convert Java to Kotlin from Android-Studio. Here is how it went: From the “Code” menu choose “Convert Java File to Kotlin File”.

Check FIGURE-1 below.

FIGURE-1

And then after the conversion, it came to my attention that my code had some keywords like !! , ? , -> , object which I didn’t know what they mean. Then I realized that converting wasn’t enough!. So I went further to know more about the syntax (just syntax) and I started from Kotlin official doc.

I kept on reading, and reading, but I faced some terms that I haven’t seen before like (null-safety, lambda expressions, closure, object, companion object, late-init), and from here I decided to take a new step, and go further by watching this course named Kotlin Bootcamp for Programmers byGoogle and that was the turning point!.

If you want to start writing Kotlin instead of Java, and start a new challenge, then check the following:

  1. Extension functions

  2. Idioms

  3. Null Safety

  4. Higher-Order Functions and Lambdas

Tip: you might need to know more about classes, objects, companion object, late init variables, and data class.

The conclusion is moving from Java to Kotlin wasn’t just about changing the syntax.