Skip to Content
Course content

1: Setting Up Kotlin and the Toolchain

Click on the "Edit" button in the top corner of the screen to edit your slide content.

Which IDE should I actually be using?

You'll see a few options out there, but let's be real: you want IntelliJ IDEA. Kotlin was created by JetBrains, and they also make IntelliJ. It's essentially the "home" for Kotlin. While you can technically use VS Code with plugins, you'll spend more time fighting the configuration than writing code. I've tried it, and it's just not worth the friction when you're learning.

Download the Community Edition. It's free, open-source, and has everything you need for the JVM side of Kotlin. If you're planning on doing Android development, you'll eventually move to Android Studio, which is actually built on top of IntelliJ, so the transition is seamless.

Wait, do I need to install the JDK and Kotlin separately?

This is where most people get tripped up. You don't actually need to go hunting for a standalone Kotlin compiler installer. All you really need is a Java Development Kit (JDK), because Kotlin compiles to JVM bytecode.

The easiest way to handle this now is right inside IntelliJ. When you create your first project, there's a "JDK" dropdown. If it's empty, just click "Download JDK". I usually recommend Amazon Corretto or Azul Zulu (Version 17 or 21), as they're stable and widely used in production. IntelliJ will download the JDK and hook up the Kotlin standard library for you. One click, and you're done. No messing around with PATH variables in your system settings.

What is Gradle and do I really need it for simple projects?

You'll see "Gradle" mentioned the moment you start a project. Think of Gradle as your project's manager. It handles your dependencies (the libraries you'll eventually want to use), your build versions, and how your code is packaged.

For a tiny script, it feels like overkill. But in the professional world, we never just "run a file." We build projects. Learning to navigate the build.gradle.kts file now will save you a massive headache later when you want to add something like a JSON parser or a database driver. I highly recommend using the Kotlin DSL (the .kts extension) for your Gradle files rather than the Groovy version—it gives you autocomplete and type safety, which makes the build file much less intimidating.

How do I verify the toolchain is actually working?

Instead of the usual "Hello World," let's actually check if the environment is talking to the JVM correctly. Create a new Kotlin project, and in your main function, try running something that touches the system properties. This proves the compiler is working and the JVM is executing the code.

fun main() {
    val os = System.getProperty("os.name")
    val version = KotlinVersion.CURRENT
    
    println("Toolchain Verified!")
    println("Running on: $os")
    println("Kotlin Version: ${version.major}.${version.minor}")
}

If you hit the green play button and see your OS and the current Kotlin version in the console, your toolchain is healthy. If you get a "JDK not found" error, go back to the Project Structure settings (Cmd+; or Ctrl+Alt+Shift+S) and make sure your SDK is pointed to the one you downloaded.




📋 Practical Task

Exercise: Configuring a Custom JDK and Build Version

Now that you have the basics installed, it's time to make sure you can actually manipulate the toolchain. Follow these steps to configure a specific environment:

  • Create a new Kotlin project named ToolchainTest.
  • Open the Project Structure settings and explicitly change the JDK to a different version than the one you initially installed (e.g., if you have 17, download and switch to 21).
  • Open your build.gradle.kts file. Locate the kotlin version or the jvmTarget setting and change it to "17" or "21" to match your JDK.
  • Create a file that prints the current Java version using System.getProperty("java.version").
  • Run the program and verify that the output matches the JDK version you manually selected in the settings.
Rating
0 0

There are no comments for now.

to be the first to leave a comment.