Kotlin Setup & Installation

Install the Kotlin compiler, configure IntelliJ IDEA, try the online Playground, and understand project layout

JDK 17+ IntelliJ IDEA Playground Gradle

Table of Contents

1Installing Kotlin

Kotlin runs on the JVM and requires a Java Development Kit (JDK). For most learners, installing IntelliJ IDEA or Android Studio is enough — Kotlin support is built in. For command-line use, install the standalone Kotlin compiler (kotlinc).

Prerequisites

RequirementMinimumRecommended
JDKJDK 8JDK 17 or JDK 21 (LTS)
RAM4 GB8 GB or more for IDE
Disk space2 GB4 GB+ (IDE + SDK)
OSWindows 10+, macOS 10.14+, or modern Linux

Option A — Install JDK first

Download a JDK from Adoptium (Eclipse Temurin), Oracle, or use your OS package manager. Verify installation:

Bash — Verify JDKjava -version javac -version # Example output: openjdk version "17.0.x"

Option B — Standalone Kotlin compiler (command line)

Download the latest Kotlin release from GitHub releases (kotlin-compiler-*.zip). Extract and add the bin folder to your PATH.

Windows PowerShell — Add to PATH (session)$env:PATH += ";C:\kotlin\kotlinc\bin" kotlinc -version
macOS / Linux — Extract and verifyunzip kotlin-compiler-*.zip -d ~/kotlin export PATH="$HOME/kotlin/kotlinc/bin:$PATH" kotlinc -version

Option C — SDKMAN (Linux / macOS)

Bash — Install via SDKMANcurl -s "https://get.sdkman.io" | bash source "$HOME/.sdkman/bin/sdkman-init.sh" sdk install kotlin kotlin -version

Compile and run your first file

Main.ktfun main() { println("Kotlin is installed!") }
Bash — Compile & runkotlinc Main.kt -include-runtime -d app.jar java -jar app.jar # Output: Kotlin is installed!
Easiest
IntelliJ IDEA (Kotlin built-in)
Android
Android Studio (includes Kotlin)
Quick try
Kotlin Playground (browser)
Tip

You rarely need a separate kotlinc install if you use IntelliJ or Gradle — the Kotlin plugin and Gradle plugin download the compiler automatically for your project.

2IntelliJ IDEA Setup

IntelliJ IDEA is the IDE from JetBrains — the same team that created Kotlin. Kotlin support is included out of the box in both Community and Ultimate editions.

EditionCostBest for
CommunityFree & open sourceKotlin/JVM, learning, CLI apps, basic Android
UltimatePaid (free for students)Spring, Ktor, full-stack, advanced tooling

Download and install

  1. Go to jetbrains.com/idea/download.
  2. Download IntelliJ IDEA Community for your OS (Windows, macOS, or Linux).
  3. Run the installer and follow the wizard (recommended: add launcher, associate .kt files).
  4. On first launch, choose a theme and optionally install the Kotlin plugin if prompted (usually pre-installed).

Create a new Kotlin JVM project

  1. File → New → Project
  2. Select Kotlin in the left panel, then JVM | IDEA (or Gradle if you prefer build scripts).
  3. Set JDK to 17 or 21, enter project name (e.g. HelloKotlin), click Create.
  4. Right-click src/main/kotlinNew → Kotlin File/Class → choose File, name it Main.kt.
  5. Add a main function and click the green Run arrow beside fun main().
Main.kt — Run in IntelliJfun main() { val name = readlnOrNull() ?: "World" println("Hello, $name from IntelliJ!") }

Useful IDE settings

  • Settings → Editor → Code Style → Kotlin — formatting rules
  • Settings → Plugins — ensure Kotlin is enabled
  • Settings → Build, Execution, Deployment → Build Tools → Gradle — JVM version for Gradle
  • View → Tool Windows → Gradle — run tasks like build and test
Android development: Use Android Studio instead — it is IntelliJ-based and ships with the Android SDK, emulator, and Kotlin plugin preconfigured.

3Kotlin Playground

Kotlin Playground is a free online editor at play.kotlinlang.org. Write Kotlin code in your browser, run it instantly, and share snippets — no installation required.

How to use the Playground

  1. Open play.kotlinlang.org in any modern browser.
  2. Replace the default code with your Kotlin snippet.
  3. Click the Run button (or press the run shortcut shown in the toolbar).
  4. View output in the panel below the editor.
  5. Use Share to generate a link you can send to others or embed in docs.
Playground examplefun main() { val numbers = listOf(1, 2, 3, 4, 5) val evens = numbers.filter { it % 2 == 0 } println("Evens: $evens") println("Sum: ${numbers.sum()}") }

Playground features

Instant Run

Compile and execute JVM Kotlin in the cloud — great for quick experiments.

Shareable URLs

Save and share code snippets with classmates or in tutorials.

Syntax Highlighting

Full Kotlin syntax support with error messages in the output panel.

Learning First

Ideal before installing an IDE — try concepts from this tutorial series online.

When to use Playground vs IDE

Use Playground for small snippets and sharing. Switch to IntelliJ or Android Studio when you need multi-file projects, Gradle builds, debugging, and Android emulators.

4Project Structure

A typical Kotlin JVM project created with Gradle in IntelliJ follows a standard layout. Understanding folders helps you navigate real-world apps and Android modules.

my-kotlin-app/ ├── .gradle/ # Gradle cache (auto-generated) ├── .idea/ # IntelliJ project settings ├── build/ # Compiled output (generated) ├── gradle/ │ └── wrapper/ # Gradle wrapper (gradle-wrapper.jar, .properties) ├── src/ │ ├── main/ │ │ ├── kotlin/ # Production Kotlin source files (*.kt) │ │ └── resources/ # Config files, images, application.properties │ └── test/ │ ├── kotlin/ # Unit test source files │ └── resources/ # Test resources ├── build.gradle.kts # Build script (Kotlin DSL) — plugins, dependencies ├── settings.gradle.kts # Project name and included modules ├── gradle.properties # JVM args, Kotlin options └── gradlew / gradlew.bat # Gradle wrapper scripts

Key files explained

Path / FilePurpose
src/main/kotlin/Your application Kotlin code; package folders mirror directory structure
src/test/kotlin/JUnit or Kotlin test files (e.g. MainTest.kt)
build.gradle.ktsDeclares Kotlin plugin, JDK target, libraries (dependencies)
settings.gradle.ktsRoot project name; lists submodules in multi-module apps
gradle/wrapper/Ensures everyone uses the same Gradle version

Sample build.gradle.kts

build.gradle.ktsplugins { kotlin("jvm") version "2.0.0" application } group = "com.example" version = "1.0-SNAPSHOT" repositories { mavenCentral() } dependencies { testImplementation(kotlin("test")) } kotlin { jvmToolchain(17) } application { mainClass.set("com.example.MainKt") }

Package naming convention

Kotlin packages use reverse domain notation. File path must match package declaration:

src/main/kotlin/com/example/app/Main.ktpackage com.example.app fun main() { println("Package: com.example.app") }

Android module (preview)

Android projects add an app/ module with a similar layout under app/src/main/ — Kotlin in kotlin/ or java/, layouts in res/layout/, and manifest at AndroidManifest.xml. You'll explore this in Kotlin Android Development.

Generated folders: Do not commit build/ or .gradle/ to Git — add them to .gitignore. Commit source, Gradle wrapper, and build scripts.

5Summary Cheatsheet

TopicKey Takeaway
Installing KotlinNeed JDK 17+; use IntelliJ, standalone kotlinc, or SDKMAN
IntelliJ IDEACommunity edition is free; New → Kotlin JVM project → run main
Kotlin PlaygroundBrowser-based at play.kotlinlang.org — no install, shareable links
Project Structuresrc/main/kotlin, build.gradle.kts, Gradle wrapper
Verify setupRun Hello World in IDE, Playground, or via kotlinc + java -jar
Next lessonKotlin Basics — variables, types, and operators

Kotlin Setup MCQ Practice

10 Basic MCQs 10 Advanced MCQs

10 Basic Kotlin Setup MCQs

1

What is required to run Kotlin on the JVM?

APython interpreter
BJava Development Kit (JDK)
CNode.js runtime
D.NET SDK
Explanation: Kotlin compiles to JVM bytecode and needs a JDK to compile and run on the JVM.
2

Which command verifies the standalone Kotlin compiler installation?

Akotlinc -version
Bkotlin --help
Cgradle -v
Djava -kotlin
Explanation: The kotlinc CLI prints the Kotlin compiler version when installed and on PATH.
3

Which IDE from JetBrains includes Kotlin support out of the box?

AVisual Studio Code
BIntelliJ IDEA
CEclipse
DNetBeans
Explanation: IntelliJ IDEA is made by JetBrains — the creators of Kotlin — with built-in Kotlin plugin.
4

Where is the official Kotlin Playground hosted?

Aplay.java.com
Bplay.kotlinlang.org
Ckotlinplay.io
Djetbrains.com/play
Explanation: play.kotlinlang.org is the free browser-based Kotlin editor with instant run and share links.
5

Where do production Kotlin source files live in a standard Gradle JVM project?

Asrc/main/kotlin
Bsrc/kotlin/main
Ckotlin/src/main
Dapp/kotlin/
Explanation: Gradle Kotlin JVM projects use src/main/kotlin for application source code.
6

Which file declares Kotlin plugins and dependencies in a modern Gradle project?

Abuild.gradle.kts
Bpom.xml
CCMakeLists.txt
DPackage.swift
Explanation: build.gradle.kts is the Kotlin DSL build script for plugins, repositories, and dependencies.
7

Which JDK versions are recommended for new Kotlin learners in this guide?

AJDK 8 only
BJDK 17 or JDK 21 (LTS)
CJDK 6
DNo JDK needed
Explanation: JDK 17 or 21 LTS is recommended for modern Kotlin and IDE tooling.
8

Which tool can install Kotlin on Linux or macOS from the command line?

ASDKMAN
Bnpm
Cpip
Dcargo
Explanation: SDKMAN manages JDK and Kotlin versions with sdk install kotlin on Unix-like systems.
9

How do you compile a Kotlin file to a runnable JAR from the command line?

Akotlinc Main.kt -include-runtime -d app.jar
Bkotlin run Main.kt
Cgradle compile Main.kt
Djava -kotlin Main.kt
Explanation: kotlinc with -include-runtime bundles the Kotlin runtime; run with java -jar app.jar.
10

Which IntelliJ IDEA edition is free and sufficient for learning Kotlin/JVM?

AUltimate only
BCommunity
CProfessional
DEnterprise
Explanation: IntelliJ IDEA Community is free, open source, and fully supports Kotlin JVM projects.

10 Advanced Kotlin Setup MCQs

11

What does the Gradle Wrapper (gradlew) ensure?

ASame Gradle version for all developers
BFaster Kotlin compilation only
CAutomatic Play Store upload
DIDE theme synchronization
Explanation: gradlew downloads the pinned Gradle version from gradle/wrapper/gradle-wrapper.properties.
12

What is the purpose of settings.gradle.kts?

ADeclare app dependencies only
BRoot project name and included modules
CStore IDE color scheme
DConfigure emulator settings
Explanation: settings.gradle.kts sets the root project name and lists submodules in multi-module apps.
13

kotlin { jvmToolchain(17) } in build.gradle.kts sets?

AJDK version used for Kotlin compilation
BAndroid minSdk level
CGradle wrapper version
DPackage namespace only
Explanation: jvmToolchain pins the JDK used to compile Kotlin and Java sources in the project.
14

Kotlin package declaration must match?

ADirectory structure under src/main/kotlin
Bbuild.gradle.kts filename
CGradle wrapper version
DIDE window layout
Explanation: Package folders mirror reverse-domain notation — e.g. com.example.app in path and declaration.
15

application { mainClass.set("com.example.MainKt") } specifies?

AEntry point class for runnable JVM apps
BJUnit test runner class
CGradle daemon name
DJDK install path
Explanation: The application plugin uses mainClass to know which class contains fun main() for run tasks.
16

gradle.properties typically stores?

AJVM args and shared Gradle/Kotlin build options
BMachine-specific SDK paths only
CCompiled bytecode output
DGit credentials
Explanation: gradle.properties holds JVM heap settings, Kotlin options, and other team-shared build flags.
17

For dedicated Android app development, you should use?

AIntelliJ Community only
BAndroid Studio
CKotlin Playground only
DStandalone kotlinc only
Explanation: Android Studio is IntelliJ-based and ships with Android SDK, emulator, and Kotlin preconfigured.
18

Which folders should NOT be committed to Git?

Abuild/ and .gradle/
Bsrc/main/kotlin/
Cgradle/wrapper/
Dbuild.gradle.kts
Explanation: build/ and .gradle/ are generated locally; commit source, wrapper, and build scripts instead.
19

When using IntelliJ with Gradle, do you usually need standalone kotlinc?

ANo — Gradle and the Kotlin plugin download the compiler
BYes, always required separately
COnly on Windows
DOnly for Android projects
Explanation: The Kotlin Gradle plugin resolves the compiler version automatically for your project.
20

Top-level main() in file Main.kt in package com.example becomes JVM class?

Acom.example.Main
Bcom.example.MainKt
CMain.main
DKotlinMain
Explanation: Kotlin generates a MainKt facade class for top-level functions — referenced in mainClass.set().
Click an option to select, then check answers.

Kotlin Setup Interview Q&A

15 topic-focused questions for interviews and revision.

1What are the main steps to set up Kotlin development on a new machine?easy
Answer: Install JDK 17+, choose IntelliJ IDEA or Android Studio, optionally install kotlinc or use SDKMAN, create a Kotlin JVM project, and verify by running a Hello World main() function.
2What is the difference between kotlinc and using Gradle for Kotlin builds?easy
Answer: kotlinc is the standalone compiler for single-file or script use; Gradle with the Kotlin plugin manages multi-file projects, dependencies, tests, and reproducible builds via build.gradle.kts.
3Why is JDK 17 or 21 recommended for Kotlin projects?medium
Answer: Modern IntelliJ, Gradle, and jvmToolchain settings target LTS JDK versions; older JDKs may cause IDE warnings, sync failures, or missing language features.
4How do you create a new Kotlin JVM project in IntelliJ IDEA?easy
Answer: File → New → Project, select Kotlin on the left, choose JVM | IDEA or Gradle, set JDK to 17+, name the project, then add a Main.kt under src/main/kotlin and click Run beside fun main().
5When should you use Kotlin Playground instead of an IDE?easy
Answer: Use Playground for quick snippets, learning concepts, and sharing code links without installation; switch to an IDE for multi-file projects, Gradle builds, debugging, and Android emulators.
6Explain the standard Kotlin Gradle project folder layout.medium
Answer: Source in src/main/kotlin and tests in src/test/kotlin; build.gradle.kts for plugins and dependencies; settings.gradle.kts for project name; gradle/wrapper for consistent Gradle version; build/ for generated output.
7What does kotlin("jvm") version "2.0.0" in build.gradle.kts do?medium
Answer: It applies the Kotlin JVM plugin at version 2.0.0, enabling Kotlin compilation, stdlib dependency resolution, and Kotlin-specific Gradle tasks for JVM targets.
8How does SDKMAN simplify Kotlin setup on macOS/Linux?easy
Answer: SDKMAN installs and switches JDK and Kotlin versions with commands like sdk install kotlin and sdk use kotlin, avoiding manual PATH and archive extraction steps.
9What is the purpose of the Gradle wrapper files (gradlew, gradle/wrapper/)?medium
Answer: They pin a specific Gradle version so every developer and CI machine builds with the same Gradle release without a global Gradle install.
10Why is mainClass.set("com.example.MainKt") needed in build.gradle.kts?hard
Answer: Top-level main() in Main.kt compiles to a JVM class named MainKt in the declared package; the application plugin needs this fully qualified name to run the project with gradle run.
11IntelliJ IDEA Community vs Ultimate for Kotlin — when is Ultimate worth it?medium
Answer: Community is enough for Kotlin/JVM learning and CLI apps; Ultimate adds Spring, Ktor, database tools, and advanced frameworks — useful for full-stack or enterprise Kotlin development.
12How do you verify JDK installation before writing Kotlin code?easy
Answer: Run java -version and javac -version in a terminal; both should report JDK 17+ (e.g. Temurin or OpenJDK) before installing Kotlin or opening IntelliJ.
13What goes in src/test/kotlin vs src/main/kotlin?easy
Answer: src/main/kotlin holds production application code; src/test/kotlin holds unit tests (e.g. JUnit or kotlin("test")) that Gradle runs via ./gradlew test.
14How do package names relate to folder paths in Kotlin projects?medium
Answer: Use reverse-domain notation (com.example.app); the file path under src/main/kotlin must match — com/example/app/Main.kt for package com.example.app.
15Describe troubleshooting when kotlinc is not recognized in the terminal.hard
Answer: Confirm the kotlin-compiler bin folder is on PATH, restart the terminal, verify with kotlinc -version, or skip standalone install and use IntelliJ/Gradle which download the compiler automatically.