ProgramGuru

Set up Kotlin and the JVM

Set up Kotlin and the JVM

Local Kotlin/JVM work needs a compatible JDK and Kotlin tooling. A JDK supplies Java development tools and a runtime. IntelliJ IDEA can configure a Kotlin project, while the command-line compiler is useful for inspecting the compile-and-run steps directly.

Follow the official setup instructions for your operating system. Check java -version and kotlinc -version. Save the code as Main.kt, compile with kotlinc Main.kt -include-runtime -d school.jar, then run java -jar school.jar. The runtime flag includes the Kotlin runtime, not every third-party library.

What you’ll learn

  • Compile a file and run its JAR.
  • Distinguish source errors from missing tooling.

Set up Kotlin and the JVM in the example

  1. Install toolchain

    Local Kotlin/JVM work needs a compatible JDK and Kotlin tooling.

    Install toolchain
  2. Compile Main.kt

    Follow the official setup instructions for your operating system.

    Compile Main.kt
  3. Run the JAR

    The message appears only when the compiled application runs.

    Run the JAR
The message appears only when the compiled application runs. A missing kotlinc command concerns installation or the shell path. A diagnostic mentioning the source concerns compilation. Keeping these steps separate helps you investigate the actual problem.

Follow set up kotlin and the jvm

Save the complete source as Main.kt and use the Kotlin/JVM environment. No separate input file is needed.

Kotlin/JVM · complete program

fun main() { println("Kotlin setup ready") }

Expected output

Kotlin setup ready

Follow the execution

The message appears only when the compiled application runs. A missing kotlinc command concerns installation or the shell path. A diagnostic mentioning the source concerns compilation. Keeping these steps separate helps you investigate the actual problem.

Try this in the Kotlin compiler by pasting the complete program.

Practice: Set up Kotlin and the JVM

Your task: What should you check if kotlinc is not found?

Kotlin/JVM · complete program

fun main() { println("Kotlin setup ready") }

Worked answer

Check the compiler installation and shell path. Changing a string in the Kotlin file cannot make an absent compiler available.

Set up Kotlin and the JVM: the important boundary

These examples use stable Kotlin 2.x language features and are checked with Kotlin 2.2.0 on JDK 17. Newer stable toolchains also exist. Local packages, file storage and coroutine dependencies need their stated environment rather than assumptions about a single-file compiler.

Check your understanding

What should you check if kotlinc is not found?
Choose one answer. You can try again.

Answer and explanation

Check the compiler installation and shell path.

Check the compiler installation and shell path. Changing a string in the Kotlin file cannot make an absent compiler available.

Set up Kotlin and the JVM: what to keep in mind

Check the compiler installation and shell path. Changing a string in the Kotlin file cannot make an absent compiler available. These examples use stable Kotlin 2.x language features and are checked with Kotlin 2.2.0 on JDK 17.

Further reading: official Kotlin documentation for this topic.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: Hello World and console output →