First Program IDE

This step-by-step guide walks you through creating and running your first Kotlin program using IntelliJ IDEA, the official recommended IDE for Kotlin development.

Prerequisites

  • IntelliJ IDEA installed (Community or Ultimate Edition)
  • JDK 8 or later installed and configured
  • Basic familiarity with IDE navigation
  • Step 1: Launch IntelliJ IDEA

  1. Open IntelliJ IDEA
  2. You'll see the Welcome Screen with several options
  3. Step 2: Create New Project

    Option A: From Welcome Screen

  4. Click New Project
  5. The New Project wizard opens
  6. Option B: From Menu Bar

  7. Go to File → New → Project
  8. The New Project wizard opens
  9. Step 3: Configure Project Settings

    Select Project Type

  10. In the left sidebar, select Kotlin
  11. Choose Kotlin/JVM (for console applications)
  12. Click Next
  13. Project Configuration

Name:

Example

HelloKotlin

Location: Choose where to save the project:

Example

C:\Users\YourName\IdeaProjects\HelloKotlin

Build System: Select one:

  • Gradle (Kotlin DSL) - Recommended for larger projects
  • Maven - Alternative build tool
  • IntelliJ - Simple, no build tool (good for learning)

JDK: Select your installed JDK:

  • Choose from dropdown
  • Or click Download JDK to install automatically

Example configuration:

Example

Name: HelloKotlin
Location: C:\Users\YourName\IdeaProjects\HelloKotlin
Build System: IntelliJ
JDK: 17 (corretto-17)

Click Create

Step 4: Understanding Project Structure

IntelliJ creates this structure:

Example

HelloKotlin/
├── .idea/              # IDE configuration
├── out/                # Compiled output
├── src/                # Source code
│   └── Main.kt         # Your Kotlin files go here
└── HelloKotlin.iml   # Project module file

Step 5: Create Kotlin File

Method 1: Quick Creation

  1. Right-click on src folder in Project view (left sidebar)
  2. Select New → Kotlin Class/File
  3. In the dialog:
  • Choose File (not Class)
  • Enter name: HelloWorld
  • Press Enter
  • Method 2: Using Menu

  1. Click on src folder
  2. Go to File → New → Kotlin Class/File
  3. Follow same steps as Method 1
  4. Result

A new file HelloWorld.kt is created and opened in the editor.

Step 6: Write Your First Kotlin Code

In HelloWorld.kt, type:

Example

fun main() {
    println("Hello, Kotlin!")
    println("Welcome to IntelliJ IDEA!")
}

Code Explanation

  • fun main: Entry point function
  • println: Prints text with newline
  • Strings in double quotes
  • No semicolons needed
  • IntelliJ Features While Typing

Auto-completion:

  • Start typing fun - IntelliJ suggests fun
  • Press Tab to complete

Auto-closing:

  • Type ( - IntelliJ adds ) automatically
  • Type { - IntelliJ adds } automatically

Syntax highlighting:

  • Keywords appear in color
  • Strings appear in different color
  • Errors underlined in red
  • Step 7: Run the Program

    Method 1: Green Play Button

  1. Look for the green ▶ (play) icon next to fun main
  2. Click the play button
  3. Select Run 'HelloWorldKt'
  4. Method 2: Context Menu

  5. Right-click anywhere in the editor
  6. Select Run 'HelloWorldKt'
  7. Method 3: Keyboard Shortcut

Windows/Linux:

Example

Ctrl + Shift + F10

macOS:

Example

Control + Shift + R

Method 4: Top Menu Bar

  1. Click Run in menu bar
  2. Select Run 'HelloWorldKt'
  3. Step 8: View Output

    Run Tool Window

The Run window opens at the bottom showing:

Example

Hello, Kotlin!
Welcome to IntelliJ IDEA!

Process finished with exit code 0

Understanding the Output

  • First two lines: Your program output
  • exit code 0: Program ran successfully
  • exit code != 0: Program had an error
  • Step 9: Modify and Re-run

Let's make the program interactive:

Example

fun main() {
    println("=" .repeat(40))
    println("Welcome to Kotlin Programming!")
    println("=" .repeat(40))
    
    val language = "Kotlin"
    val year = 2024
    
    println("\nLanguage: $language")
    println("Year: $year")
    println("$language is awesome!")
}

Run again to see the new output:

Example

========================================
Welcome to Kotlin Programming!
========================================

Language: Kotlin
Year: 2024
Kotlin is awesome!

Process finished with exit code 0

Useful IntelliJ IDEA Features

1. Code Formatting

Auto-format your code:

Windows/Linux: Ctrl + Alt + L

macOS: Cmd + Option + L

2. Code Completion

Type pri and press Ctrl + Space to see suggestions:

  • println
  • print
  • private

Select with arrow keys and press Enter.

3. Quick Documentation

Hover over println and press Ctrl + Q (Windows/Linux) or F1 (macOS) to see documentation.

4. Rename Refactoring

To rename a variable:

  1. Right-click variable name
  2. Select Refactor → Rename
  3. Or press Shift + F6
  4. Type new name
  5. Press Enter (renames everywhere)
  6. 5. Run Configuration

After first run, you can:

  • Click play button in toolbar (top-right)
  • Use shortcut Shift + F10 (Windows/Linux) or Control + R (macOS)
  • Common Issues and Solutions

    Issue 1: No Run Button Visible

Cause: Kotlin plugin not enabled

Solution:

  1. File → Settings → Plugins
  2. Search "Kotlin"
  3. Enable if disabled
  4. Restart IDE
  5. Issue 2: Cannot Find JDK

Cause: JDK not configured

Solution:

  1. File → Project Structure (Ctrl + Alt + Shift + S)
  2. Project Settings → Project
  3. Project SDK: Select or add JDK
  4. Click OK
  5. Issue 3: Red Underline Under Code

Cause: Syntax error or missing import

Solution:

  1. Hover over red text to see error
  2. Press Alt + Enter for quick fixes
  3. Select suggested fix
  4. Issue 4: Program Doesn't Run

Cause: Wrong file selected or no main function

Solution:

  1. Ensure file contains fun main
  2. Right-click on correct file
  3. Select Run
  4. Practice Exercises

    Exercise 1: Personal Info

Create a program that prints:

Example

Name: [Your Name]
Age: [Your Age]
Location: [Your City]

Exercise 2: Simple Calculator

Example

fun main() {
    val a = 10
    val b = 5
    
    println("$a + $b = ${a + b}")
    println("$a - $b = ${a - b}")
    println("$a * $b = ${a * b}")
    println("$a / $b = ${a / b}")
}

Exercise 3: Multiple Lines

Print a simple pattern:

Example

fun main() {
    println("*****")
    println("*   *")
    println("*   *")
    println("*****")
}

Keyboard Shortcuts Cheat Sheet

Action Windows/Linux macOS
Run program Ctrl + Shift + F10 Control + Shift + R
Run (after config) Shift + F10 Control + R
Code completion Ctrl + Space Control + Space
Format code Ctrl + Alt + L Cmd + Option + L
Rename Shift + F6 Shift + F6
Quick fix Alt + Enter Option + Enter
Find Ctrl + F Cmd + F
Duplicate line Ctrl + D Cmd + D
Delete line Ctrl + Y Cmd + Delete

Next Steps

  • Experiment with different print statements
  • Try using variables (val and var)
  • Learn about Kotlin data types
  • Explore IntelliJ debugging features
  • Create more complex programs
  • Tips for Beginners

  1. Use code completion: Saves time and reduces typos
  2. Read error messages: They tell you exactly what's wrong
  3. Experiment freely: Can't break anything, easy to undo
  4. Use shortcuts: Much faster than mouse clicking
  5. Save often: Ctrl + S (though IntelliJ auto-saves)

Congratulations! You've created and run your first Kotlin program in IntelliJ IDEA. Keep practicing and exploring Kotlin's features!

Input Required

This code uses input(). Please provide values below:

🤖 Coding Mentor
🤖

Hi! I'm your coding mentor

Ask me anything about programming:

• Python, Java, C++, JavaScript

• Algorithms & Data Structures

• Debugging & Code Help