You can write Android apps in any language that can compile and run on the Java Virtual Machine (JVM), and your end users will be none the wiser. Java is one of the world’s most widely used programming languages. If you want to consider a different language then switch to one of the many modern programming languages that are designed to run on the JVM. While there’s no shortage of languages that compile to Java bytecode, there are a few factors that make Kotlin stand out from the crowd.
One of Kotlin’s greatest strengths as a potential alternative to Java is the sheer level of interoperability between Java and Kotlin. You can even have Java and Kotlin code existing side by side in the same project, and everything will still compile perfectly.
Kotlin fixes a series of issues that Java suffers from
- Null references are controlled by the type system.
One of the most common pitfalls in many programming languages, including Java, is that of accessing a member of a null reference, resulting in a null reference exception. In Java, this would be the equivalent of a NullPointerException or NPE for short.
In Kotlin, the type system distinguishes between references that can hold null and those that can not.
- Arrays in Kotlin are invariant
Unlike Java, arrays in Kotlin are invariant. This means that Kotlin does not let us assign an Array<String>to an Array<Any> which prevents a possible runtime failure.
- Kotlin has proper function types, as opposed to Java’s SAM conversions
- Kotlin does not have checked exceptions