Introduction to Kotlin & Setup
🎯 Goal: Understand what Kotlin is, why it’s used, and set up your environment to start coding.
What is Kotlin?
Kotlin is a modern, concise, and expressive programming language developed by JetBrains. It is:
✅ Statically typed (type safety at compile time).
✅ Interoperable with Java (can use existing Java libraries).
✅ Concise & expressive (less boilerplate code than Java).
✅ Null-safe (helps avoid NullPointerException).
✅ Functional & Object-Oriented (supports both paradigms).
Primary Uses of Kotlin:
- General-purpose backend development.
- Android development (but in this series we’re focusing on Kotlin only, not Android).
- Scripting and command-line tools.
- Kotlin/Native for cross-platform development.
Setting Up Kotlin
You have multiple ways to write and run Kotlin code:
Option 1: JetBrains Playground (Recommended for Quick Testing)
🚀 Website: https://play.kotlinlang.org
- No installation required — just start coding in your browser.
Option 2: IntelliJ IDEA (Recommended for Long-Term Learning)
1️⃣ Download IntelliJ IDEA (Community Edition) → https://www.jetbrains.com/idea/download
2️⃣ Install and open IntelliJ IDEA.
3️⃣ Create a new Kotlin project → Select Kotlin/JVM.
4️⃣ Write your first Kotlin program inside src/main/kotlin/Main.kt
💞I write these articles to help fellow developers. If you found this useful and want to support my work, you can do so here: Buy Me a Coffee ☕
Option 3: Command Line (For Minimal Setup)
1️⃣ Install Kotlin:
- macOS (via Homebrew): brew install kotlin
- Windows/Linux: Use Kotlin Compiler
2️⃣ Run Kotlin:
- Create a file main.kt, write your Kotlin code, and run:
kotlinc main.kt -include-runtime -d main.jar
java -jar main.jar
Writing Your First Kotlin Program
Hello, World!
fun main() {
println("Hello, World!")
}
Explanation:
- fun main() → The main function, the entry point of the program.
- println() → Prints text to the console.
Running Your Code
- In IntelliJ IDEA: Click the green play button
▶️
. - In JetBrains Playground: Click “Run”.
Understanding the Kotlin Compiler & REPL
🔹 Kotlin Compiler:
- Converts Kotlin code to Java bytecode (.class files) and runs it on the JVM.
🔹 Kotlin REPL (Read-Eval-Print Loop):
- Allows you to execute Kotlin statements interactively.
- Open it in IntelliJ IDEA → Tools→ Kotlin → Kotlin REPL
- Example:
>>> 5 + 3
8
>>> "Kotlin".length
6