Kotlin Get Started
Setting up your Kotlin development environment
🚀 Getting Started with Kotlin
Learn how to set up your development environment and write your first Kotlin program. We'll cover installation, IDE setup, and creating your first project step by step.
// Your first Kotlin program
fun main() {
println("Hello, Kotlin Developer!")
}
Output:
Installation Options
IntelliJ IDEA
Best IDE for Kotlin development
Android Studio
For Android app development
Online Playground
Try Kotlin in your browser
Command Line
Lightweight development setup
🔹 Quick Start with Online Playground
The fastest way to start coding Kotlin:
Steps to get started:
- Visit play.kotlinlang.org
- Click "Create" to start a new program
- Write your Kotlin code
- Click "Run" to execute
// Try this in Kotlin Playground
fun main() {
val greeting = "Welcome to Kotlin!"
println(greeting)
// Simple calculation
val result = 10 + 5
println("10 + 5 = $result")
}
Output:
10 + 5 = 15
🔹 Installing IntelliJ IDEA
For serious Kotlin development, IntelliJ IDEA is recommended:
🔸 Installation Steps
- Download: Visit jetbrains.com/idea
- Choose Version: Community (free) or Ultimate
- Install: Run the installer for your OS
- Setup: Launch and configure preferences
🔸 Creating Your First Project
// File: Main.kt
fun main() {
println("My first Kotlin project!")
// Variables
val name = "Developer"
var score = 100
println("Hello, $name!")
println("Your score: $score")
}
Output:
Hello, Developer!
Your score: 100
🔹 Command Line Setup
For minimal setup, use the Kotlin compiler directly:
🔸 Installation
Using SDKMAN (Recommended):
# Install SDKMAN
curl -s "https://get.sdkman.io" | bash
# Install Kotlin
sdk install kotlin
Manual Installation:
- Download from kotlinlang.org/docs/command-line.html
- Extract and add to PATH
-
Verify:
kotlinc -version
🔸 Compile and Run
// hello.kt
fun main() {
println("Hello from command line!")
}
# Compile
kotlinc hello.kt -include-runtime -d hello.jar
# Run
java -jar hello.jar
🔹 Project Structure
Understanding a typical Kotlin project layout:
my-kotlin-project/
├── src/
│ └── main/
│ └── kotlin/
│ └── Main.kt
├── build.gradle.kts
└── README.md
🔸 Basic build.gradle.kts
plugins {
kotlin("jvm") version "1.8.0"
application
}
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib"))
}
application {
mainClass.set("MainKt")
}