CodeGym /Courses /Kotlin SELF /Creating your first project in IntelliJ IDEA

Creating your first project in IntelliJ IDEA

Kotlin SELF
Level 5, Lesson 3
Available

1. Step-by-step creation of a new project

A project in IntelliJ IDEA is not just a folder with files, but a whole container where the IDE stores everything related to your future program. A project contains:

  • source code, files with the .kt extension;
  • project settings, for example, which version of the Java Virtual Machine to use for running;
  • external libraries;
  • auxiliary files and resources.

Inside a project, there is usually a src folder — this is the main place for your Kotlin files. Everything that is not related to code is stored separately and does not get in the way.

Launching IntelliJ IDEA

On the start screen, click the big blue New Project button. If another project is already open, click File-New Project

Configuring project parameters

Pay attention to the left menu of the window: the Kotlin language must be selected there; by default it is set to Java. Now let’s go through the main fields:

  • Name: the name of your project. This name will also be used to create a folder on disk. You can leave untitled1 or enter another one; for example, MyFirstProject.
  • Location: the path where the project will be stored on your computer. By default, IDEA suggests its IdeaProjects folder. Leave it as is.
  • Create Git repository: lets you initialize Git version control right away. At this stage, to avoid extra complexity, leave this checkbox unchecked.
  • Build system: a build system is a tool that automates the process of compiling code:
    • IntelliJ: the built-in, simplest build system in IDEA. Our choice for starting out.
    • Gradle: a powerful build system, the de facto standard in the Kotlin world. But for learning right now, it’s overkill. Using it now is like hammering nails with a microscope.
  • Add sample code: IDEA will automatically create a basic file for us with the main function and sample code.
  • Use compact project structure: keeps the folder structure simple and flat, without excessive nesting.

Installing a JDK from IntelliJ IDEA

If the JDK list is empty, our task is to download it right from here.

1. Click the drop-down list and select Download JDK...

2. A small window will open:

  • Version: choose the Java version. Our course works great with modern LTS versions; choose 25.
  • Vendor: the distribution vendor. As agreed, choose Amazon Corretto, but you can use another one as well.
  • Location: the path where IDEA will download and install this JDK. Leave the default.

3. Click the Select button or Download.

All settings are done. Click Create.

IntelliJ IDEA will start downloading the selected JDK, then create the project structure and open the main editor window. At the bottom of the screen, you may see Indexing... — the IDE is reading files to provide you with hints. Just wait a minute.

On the first run on Windows, you may see a notification: "Microsoft Defender may affect IDE performance". Feel free to click Automatically or Exclude folders. IDEA will add the project folder to antivirus exclusions so code builds run fast.

Ultimate trial period

The first time you open the editor, you may see a large window or banner: "Your free Ultimate subscription trial is active".

Don’t worry, you don’t need to pay anything. The new unified IDEA version gives you access to all features for 30 days. For our course, the free capabilities are more than enough, so you can just close this window.

2. Quick overview and first code

In IntelliJ IDEA, you can quickly change the zoom level of the entire interface without digging through settings: Alt + Shift + = or in Settings -- View -> Appearance -> Zoom IDE .

The code editor has opened with the Main.kt file.

1. Side menu

2. Project is the main window for navigating the project structure.

3. The currently open file Main.kt

4. Buttons for Run ▶ running and Debugging the program

IDEA generated sample code for us with useful hints — TIPs. Let’s take a look at it:

Code walkthrough

The code looks a bit more complex than just “Hello World”, but it demonstrates Kotlin’s power really well:

  • //TIPs ... — these are tips and shortcuts.
  • val name = "Kotlin" — we created a variable name. Notice that we didn’t have to specify the variable type; Kotlin inferred it.
  • println(...) — prints text to the screen.
  • for (i in 1..5) — this is a loop. The code inside the curly braces will run 5 times (for numbers from 1 to 5).
  • println("i = $i") — Kotlin magic! The $ symbol lets you insert the value of variable i directly into a string.

The red circle in the left gutter or an icon in the code is a breakpoint for the debugger. We’ll talk about it later. If you accidentally set one, just click it again to remove it.

Top-level functions

Just be aware of it; no need to dive in right now.

Notice: the main function is not wrapped in any class. In Kotlin, this is called a Top-Level Function. If a function does not belong to a specific object, it can live directly in a .kt file.

Since the JVM requires classes, the Kotlin compiler will automatically create an invisible class at runtime (usually MainKt), so all technical requirements are satisfied.

3. Project structure

Let’s take a closer look at the project structure on the left.

  • .idea — the IntelliJ IDEA service folder with project settings. You should not edit it manually.
  • src — the most important folder! Short for “sources”. This is where all your Kotlin code will be.
    • Main.kt — since we asked to add “sample code”, IDEA created this file. Inside it is the fun main() function. This is the “entry point” — execution of any program starts from it.
  • External Libraries — a virtual folder that shows connected libraries. Right now it contains our JDK and the standard Kotlin/JVM library.

4. Running the program

The best part is running the code and seeing the result. In Kotlin, there is a great and safe way to run a specific file.

Find the fun main() function in the code editor. To the left of it, in the line-number area (the so-called gutter), there is a green triangle ▶. Click it and choose Run 'MainKt'.

At the bottom, the Run/Console window will open, and you will see the program output:

Let’s break down the output:

Run command (the gray service line at the very beginning) — this is the path to the JVM that IDEA assembled to run your compiled code.

Program output (regular text) — this is the result of your println() calls.

Exit code: Process finished with exit code 0. This is the final report. By convention, exit code 0 means the program successfully executed all instructions and finished without errors. Any other code means the program “crashed” during execution.

In addition, after the first run, a hidden out folder will appear in the project. It contains compiled .class files — the Kotlin bytecode that the JVM executes.

What happens when you press Run?

  1. Code compilation — the Kotlin compiler turns your .kt files into .class bytecode.
  2. JVM start — the Java virtual machine starts and looks for the entry point: fun main().
  3. Execution — the instructions run, and the result is printed to the console window.

5. Alt + Enter and keyboard shortcuts

When working in IntelliJ IDEA, you will notice gray hint text right in the editor: "Press Alt Enter... to see how IntelliJ IDEA suggests fixing it".

The Alt + Enter shortcut (or Option + Enter on macOS) is your main magic wand. If the IDE underlines code in red (error) or yellow (warning), place the cursor there and press these keys. IDEA will not only explain the problem, but also offer automatic fix options.

The IDE also supports many other shortcuts for navigation and debugging. You can find them in the JetBrains documentation or directly in the IDEA menu: Help -> Keyboard Shortcuts PDF.

6. Common mistakes and how to avoid them

The “frozen program” illusion

If you wrote the readln() function in your code, when you run it, no text will appear in the console — you will just see a blinking cursor. Beginners often think IDEA has frozen. In reality, the program is simply waiting for your input. Click inside the Run console window, type text, and press Enter.

The “wrong” main is being launched (Run Configurations)

If you create a second file Test.kt in the project and write another fun main() there, you will have two entry points. After that, if you press the big Run button at the very top of the window, IDEA may run the previous file. To always run exactly the code you are editing right now, click the green triangle ▶ to the left of the desired fun main() directly in the code editor.

Code is not in the src folder

The src folder is the source root. The IDE expects to find Kotlin code there. If you create a .kt file outside this folder (for example, in the project root), the Run button will not appear and the code will not compile.

Missing or incorrectly written fun main()
If you forget to write fun main() or name the function fun myMain(), the program will not start because the JVM will not find the entry point.

No JDK selected for the project
If, when creating the project, you accidentally skipped the JDK step, IDEA will show an error: "Project SDK is not defined". This is easy to fix in settings: File → Project Structure → Project SDK.

Non-Latin letters and spaces in the project path
Although modern systems are more tolerant of names, the programmer’s golden rule says: project paths should not contain non-Latin letters, spaces, or special characters (for example, C:\My Projects\Projects 1 is a bad idea). Use only Latin letters and underscores (C:\IdeaProjects\project_one).

1
Task
Kotlin SELF, level 5, lesson 3
Locked
Sending notifications
Sending notifications
1
Task
Kotlin SELF, level 5, lesson 3
Locked
Text validation
Text validation
1
Task
Kotlin SELF, level 5, lesson 3
Locked
Countdown timer
Countdown timer
1
Task
Kotlin SELF, level 5, lesson 3
Locked
Password Rules
Password Rules
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION