Released · improving
Programming language · Since 2011
Kotlin is a statically typed language from JetBrains with concise syntax, null safety and full Java interoperability, widely used for Android and server apps.
Kotlin is a statically typed, general-purpose programming language first unveiled by JetBrains in 2011 and now developed as open source by JetBrains together with the Kotlin Foundation. It mainly targets the JVM, but it can also compile to JavaScript and WebAssembly and, through Kotlin/Native, to native executables. Type inference and null safety let you write shorter, safer code than in Java, while still mixing freely with existing Java code and libraries in the same project.
Kotlin's best-known home is Android development: Google recommends it as the preferred language for Android, and modern libraries such as Jetpack Compose are designed around it. On the server it is used to build web services with Spring Boot or Ktor, and Kotlin Multiplatform lets teams share business logic across Android, iOS, desktop and web. It is also widely used to write Gradle build scripts through the Kotlin DSL.
A good first step is the Kotlin Playground, which runs code in the browser with no setup, together with the Kotlin tour in the official documentation. Then practice the syntax with the short exercises in Kotlin Koans and build a small project in IntelliJ IDEA or Android Studio. If you already know Java, most of that knowledge carries over, so the transition is usually quick.
Type inference, data classes, extension functions and lambdas cut down on boilerplate and keep the intent of the code visible.
The type system distinguishes nullable types (String?) from non-nullable ones, catching most null pointer errors at compile time.
Kotlin calls Java classes directly and Java can call Kotlin code, so you can adopt it gradually in an existing project.
Suspending functions and coroutines let you write asynchronous and concurrent code that reads like sequential code, without callbacks.
The easiest route is IntelliJ IDEA, which supports Kotlin out of the box; its free version is enough to get started. For Android apps, install Android Studio instead. Both IDEs can create a Kotlin project straight from the new project wizard.
To compile from a terminal you need a JDK and the Kotlin compiler, kotlinc. On macOS and Linux, SDKMAN! installs both with the command below. Alternatively, run brew install kotlin with Homebrew, or scoop install kotlin with Scoop on Windows, in which case install a JDK separately.
sdk install java && sdk install kotlinOpen a new terminal and check that both the Kotlin compiler and the Java runtime print their versions.
kotlinc -version && java -versionA Kotlin program starts at the main function, and unlike Java there is no need to wrap it in a class: functions can be declared at the top level of a file. println is a standard library function that writes a line to standard output. The command above compiles hello.kt into hello.jar, bundling the Kotlin runtime, and then runs it with java -jar. In IntelliJ IDEA you can also click the run icon next to main.
hello.kt
fun main() {
println("Hello, world!")
}
kotlinc hello.kt -include-runtime -d hello.jar && java -jar hello.jarSix chapters that take you from installation to the core ideas of Kotlin.
Ask questions, share experience and trade opinions about Kotlin.
No discussions yet. Start the first one.
0 comments
Sign in · Sign in to leave a comment.
Be the first to comment.