Author: Shradheya Thakre
Kotlin is a general purpose, open source, statically typed programming language for the JVM and Android that combines object-oriented and functional programming features.
Highly reduces the amount of boilerplate code.
data class Customer(val name: String, val email: String, val company: String)
Kotlin
val quartile: Int
quartile = when (playPercentage) {
in 0..24 -> 0
in 25..49 -> 1
...
}
Java
int quartile;
if(playPercentage >= 0 && playPercentage <= 24) {
quartile = 0;
} else if(playPercentage >= 25 && playPercentage <= 49) {
quartile = 1;
}
...
Kotlin protects you from mistakenly operating on nullable types
val name: String? = null // Nullable type
println(name.length()) // Compilation error
import kotlin.browser.window
fun onLoad() {
window.document.body!!.innerHTML += "<br/>Hello, Kotlin!"
}
Hyperbolically, a programming language is only as good as what its tools can provide. This is why the advantage of using Kotlin is the built-in language support from IntelliJ. Any Java IDE for e.g. IntelliJ, Eclipse and Android Studio, can be used to write and compile Kotlin code. It also contains the aforementioned Java-to-Kotlin converter and code generators for Java and JavaScript from Kotlin code.
While Java is one of the world's most widely used programming languages and is pretty much the official language of Android development, there are many reasons why Java might not always be the best option for your Android projects.
The biggest issue is that Java isn’t a modern language, and although Java 8 was a huge step forward for the platform, introducing lots of features that developers had been waiting for (including lambda functions), at the time of writing Android only supports a subset of Java 8 features.
.apk