Introduction
Kotlin is a modern, statically typed programming language developed by JetBrains. It runs primarily on the Java Virtual Machine (JVM), which means it can use existing Java libraries and frameworks, but it can also compile to JavaScript (Kotlin/JS) or to native binaries (Kotlin/Native). Kotlin was designed to be more concise and safer than Java while remaining fully interoperable with it, allowing developers to mix Kotlin and Java code in the same project without friction.
Cricket analogy: Like a cricketer who can play under different boards (IPL, county cricket, international) using the same core skillset, Kotlin runs on the JVM using Java libraries, but also compiles to JavaScript or native code.
Syntax
fun main() {
val message: String = "Hello, Kotlin!"
println(message)
}Explanation
Every Kotlin program starts execution from a top-level main function, which does not need to belong to a class as it does in Java. The val keyword declares a read-only (immutable) variable, and its type can often be inferred by the compiler, so writing : String is optional here. The built-in println function prints text to standard output followed by a newline, similar to System.out.println in Java but far less verbose.
Cricket analogy: Like a match starting directly at the toss without needing a franchise ceremony first, Kotlin's main function runs standalone without belonging to a class, and val strikeRate = 135.5 lets the compiler infer the type just like a scoreboard infers a number's format.
Example
fun greet(name: String): String {
return "Hello, $name! Welcome to Kotlin."
}
fun main() {
val names = listOf("Ava", "Ben", "Cy")
for (n in names) {
println(greet(n))
}
}
/* Output:
Hello, Ava! Welcome to Kotlin.
Hello, Ben! Welcome to Kotlin.
Hello, Cy! Welcome to Kotlin.
*/Key Takeaways
- Kotlin is a statically typed language created by JetBrains that runs on the JVM.
- It is 100% interoperable with Java, so existing Java code and libraries can be reused.
- Kotlin also targets JavaScript (Kotlin/JS) and native platforms (Kotlin/Native).
- Programs start from a top-level
mainfunction, not a class. - String templates like
$namemake string building concise and readable.
Practice what you learned
1. Which company originally developed Kotlin?
2. On which platform does Kotlin primarily run?
3. What keyword is used to declare a read-only (immutable) variable in Kotlin?
4. What is a defining characteristic of Kotlin regarding Java?
5. Where does execution begin in a standalone Kotlin program?
Was this page helpful?
You May Also Like
History and Evolution of Kotlin
How Kotlin evolved from a JetBrains research project in 2011 to Google's preferred language for Android development.
Features of Kotlin
An overview of Kotlin's core language features, including null safety, concise syntax, and multi-paradigm support.
Setting Up a Kotlin Environment
A practical guide to installing Kotlin and running your first program using IntelliJ IDEA, the command-line compiler, or an online playground.
Kotlin-Java Interoperability
Explore how Kotlin and Java code can call each other seamlessly on the JVM, and the nuances that come with it.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics