Android: What does Kotlin first mean? Java or Kotlin?

Leo N
6 min readJun 11, 2019

--

Android development will become increasingly Kotlin-first,” Google writes in today’s announcement. “Many new Jetpack APIs and features will be offered first in Kotlin. If you’re starting a new project, you should write it in Kotlin; code written in Kotlin often mean much less code for you–less code to type, test, and maintain.

It was only two years ago, at I/O 2017, that Google announced support for Kotlin in its Android Studio IDE. That came as a bit of a surprise, given that Java had long been the preferred language for Android app development, but few announcements at that year’s I/O got more applause. Over the course of the last two years, Kotlin’s popularity has only increased. More than 50% of professional Android developers now use the language to develop their apps, Google says, and in the latest Stack Overflow developer survey, it ranks as the fourth-most loved programming language.

Why Google chose Kotlin as a primary language for android app development?

The collaboration and support for kotlin from both Google and JetBrains ensured that Android developers could easily migrate from Java to Kotlin without any hiccups. Soon, Android developers began to realize the benefits of Kotlin over Java for Android app development, some of which were:

  1. Developers could write concise, yet expressive codes in comparison to the verbosity in Java coding.
  2. One major complaint with Java for Android app development was the NullPointerException. Kotlin addressed this issue by forcing developers to explicitly allow variables to be null and negate any such problems.
  3. It is generally hard for developers to migrate to new languages, especially when you’re used to developing android apps on a language as old as Java. This issue was easily addressed by the Android Studio’s Java to Kotlin conversion feature which let developers convert Java code directly into Kotlin.

The road ahead for Android app development with Kotlin

Google does not intend to replace Java by introducing Kotlin and promoting its use in android app development. But it simply needs something to run along with the former.

https://www.infoworld.com/article/3224868/what-is-kotlin-the-java-alternative-explained.html

Kotlin is a statically typed programming language for Java Virtual Machine (JVM) and JavaScript. Described as a general purpose language, Kotlin introduces functional features to support Java interoperability. The Kotlin project was born out of the aspiration for heightened productivity. The goal was to improve the coding experience in a way that was both practical and effective.

You can see that functions are defined with the fun keyword, and that semicolons are now optional when newlines are present. The valkeyword declares a read-only property or local variable. Similarly, the varkeyword declares a mutable property or local variable.

Nevertheless, Kotlin is strongly typed. The val and var keywords can be used only when the type can be inferred. Otherwise you need to declare the type. Type inference seems to be improving with each release of Kotlin.

Have a look at the function declaration near the top of both panes. The return type in Java precedes the prototype, but in Kotlin it succeeds the prototype, demarcated with a colon as in Pascal.

Key Differences Between Java vs Kotlin

Both Java vs Kotlin are popular choices in the market; let us discuss some of the major Differences Between Java vs Kotlin:

  • Kotlin has the support of smart cast which identifies immutable types and performs implicit cast by compiler whereas in Java we need to identify and perform the casting.
  • Kotlin has the support of type inference which means we don’t need to specify the data type of variable explicitly whereas in Java we need to specify explicitly.
  • In Kotlin, we don’t have checked exceptions, which is a disadvantage as it leads to error prone-code whereas Java has support for checked exceptions by which we can perform error handling.
  • Java compilation time is 15–20% faster than Kotlin compilation time but in perspective of incremental build compilation, Kotlin will also take same compilation time as Java.
  • In Kotlin, we can’t assign null values to variables or return values, if we really want to assign then we can declare a variable with special syntax whereas in Java we can assign null values but when we try to access objects pointing to null values raises an exception.
  • Kotlin is interchangeable with Java irrespective of difference between Java vs Kotlin. We can call Kotlin code in Java and Java code in Kotlin. So we can have both Java vs Kotlin classes side by side in a project and compiles without any issues. After compilation we unable to find which class written in Java or Kotlin.

Conclusion — Java vs Kotlin

Finally, its an overview of comparison Between Java vs Kotlin. I hope you will have a better understanding of these Java vs Kotlin languages after reading this Java vs Kotlin article. In my view, we can proceed with Kotlin for Android application development without worrying about the compilation time even though Java has few advantages over Kotlin.

“Kotlin first” refers to a development approach that prioritizes the use of Kotlin as the primary programming language for Android development over Java. This term has gained traction in the Android community as Kotlin has become the preferred language for Android development since its official support was announced by Google in 2017.

Key Aspects of “Kotlin First”

  1. Preferred Language: When an organization or project adopts a “Kotlin first” approach, it means that new code and features are developed using Kotlin. Existing Java code can still be used and maintained, but new implementations are done in Kotlin.
  2. Interoperability: Kotlin is fully interoperable with Java, which means you can call Kotlin code from Java and vice versa. This allows developers to gradually migrate existing Java codebases to Kotlin without the need to rewrite everything at once.
  3. Modern Language Features: Kotlin offers modern programming features such as null safety, extension functions, higher-order functions, coroutines for asynchronous programming, and concise syntax, making it easier and more efficient to write and maintain code.
  4. Tooling and Support: Android Studio and other tools have extensive support for Kotlin, making it easier to write, debug, and test applications using this language.
  5. Community and Ecosystem: The Kotlin community has been growing rapidly, and many libraries and frameworks are being developed with Kotlin in mind, further enhancing its ecosystem.

When to Use Java

While “Kotlin first” emphasizes Kotlin for new development, Java still has its place in Android development, especially in existing applications or when developers are more comfortable with Java. Some scenarios where Java might still be used include:

  • Maintaining legacy codebases.
  • Working in environments or teams that have standardized on Java.
  • Integrating with certain libraries or frameworks that are Java-centric.

--

--

Leo N
Leo N

Written by Leo N

🇻🇳 🇸🇬 🇲🇾 🇦🇺 🇹🇭 Engineer @ GXS Bank, Singapore | MSc 🎓 | Technical Writer . https://github.com/nphausg

Responses (1)