Kotlin came out of JetBrains, the company behind IntelliJ IDEA, in 2011. They were maintaining a very large Java codebase and wanted something less verbose that could still call every Java library they already depended on. That constraint - full interoperability with Java - shaped the whole language, and it is why Kotlin could be adopted by Android at all. An existing Java app can add one Kotlin file and keep working.
The headline features are worth naming up front, because the rest of this level is really about them:
- Null safety. Whether a value can be absent is part of its type, checked at compile time.
- Conciseness. A data class in one line replaces roughly fifty lines of Java boilerplate.
- Immutability by default. The idiomatic way to declare something is read-only.
- Expressions, not statements. Most constructs return a value, including if and when.
Every Kotlin program starts at a function called main. There is no enclosing class, no public static, and no String array parameter unless you want one. That is the whole program below, and it is a complete, compilable file.
The fastest way to run it is play.kotlinlang.org, which compiles in the browser against JetBrains' servers and needs no installation at all. Later, from level five, you will install Android Studio - but there is no reason to do that today.
fun main() {
println("Hello from Kotlin")
}
Discussion
No questions on this topic yet. Sign in to ask the first one.