Algus

Basics of using IntelliJ IDEA

IntelliJ IDEA is for Kotlin created by JetBrains (which also created the Kotlin language). To get started, we could use the JetBrains Toolbox App that it’s an easy way to manage JetBrains IDEs.

Setting up a project

The steps for creating a project are very simple, we just need to create a new Project with the following information:

Project settings can be accessed from File>Project Settings in the menu bar. In this section, we can configure the SDK among other settings.

Folder/File Structure

├── .gradle
├── .idea
├── gradle
├── src
│   └── main
│       └── kotlin
│           └── Main.kt
├── build.gradle.kts
├── gradle.properties
├── settings.gradle.kts
└── External Libraries

Project Structure

// TODO

Running a Kotlin file

//Main.kt
fun main(args: Array<String>) {  
	println("Hello World!");
}

IntelliJ will display a green ▶️ icon, known as the “run button” to the left of the main function. The first option should be Run ‘MainKt’. After clicking this one, we should see a new console window at the bottom that should display a classic “Hello World!” message.

Internal steps on running the code

Kotlin REPL

IntelliJ provides a tool for testing code without having to create a file. It can be opened by selecting Tools > Kotlin > Kotlin REPL in the menu bar.

Inspecting Kotlin Bytecode

If curious about how Kotlin decisions from syntax sugar affect the resulting bytecode generated to run on the JVM, you can use the Kotlin bytecode tool window by selecting Tools > Kotlin > Show Kotlin Bytecode.

Since Bytecode can be hard to read/understand, there is a Decompile button that translates the bytecode into Java.

Why Use IntelliJ?

Well, that’s a good question. Although Kotlin can be installed without the need for IntelliJ and “there is support” for other IDEs; the experience is not the same. It makes sense as JetBrains, the company behind Kotlin, is a company that sells IDEs professionally ¯\_(ツ)_/¯