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:

Hello, Kotlin Developer!

Installation Options

💻

IntelliJ IDEA

Best IDE for Kotlin development

Built-in Kotlin Smart completion Debugging
🤖

Android Studio

For Android app development

Android tools Emulator Kotlin support
🌐

Online Playground

Try Kotlin in your browser

No installation Instant coding Share code

Command Line

Lightweight development setup

Kotlin compiler Text editor Terminal

🔹 Quick Start with Online Playground

The fastest way to start coding Kotlin:

Steps to get started:

  1. Visit play.kotlinlang.org
  2. Click "Create" to start a new program
  3. Write your Kotlin code
  4. 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:

Welcome to Kotlin!
10 + 5 = 15

🔹 Installing IntelliJ IDEA

For serious Kotlin development, IntelliJ IDEA is recommended:

🔸 Installation Steps

  1. Download: Visit jetbrains.com/idea
  2. Choose Version: Community (free) or Ultimate
  3. Install: Run the installer for your OS
  4. 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:

My first Kotlin project!
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")
}

🧠 Test Your Knowledge

What is the recommended IDE for Kotlin development?