Last Updated | 7 July 2020 |
To get started, first download and install the latest version of IntelliJ IDEA.
Once you've installed IntelliJ IDEA, it's time to create your first Kotlin application.
Enter a project name, select Console Application as the project template, and click Next.
By default, your project will use the Gradle build system with Kotlin DSL.
Go through and accept the default configuration, then click Finish.
Your project will open. By default, you see the file build.gradle.kts
, which is the build script created by the Project Wizard based on your configuration. It includes the kotlin("jvm")
plugin and dependencies required for your console application.
Open the main.kt
file in src/main/kotlin
.
The src
directory contains Kotlin source files and resources. The main.kt
file contains sample code that will print Hello World!
.
Modify the code so that it requests your name and says Hello
to you specifically, and not to the whole world.
name
with the keyword val
. It will get its value from an input where you will enter your name – readLine()
.$
before this variable name directly in the text output like this – $name
.fun main() { println("What's your name?") val name= readLine() println("Hello $name!") }
Now the application is ready to run. The easiest way to do this is to click the green Run icon in the gutter and select Run 'MainKt'.
You can see the result in the Run tool window.
Enter your name and accept the greetings from your application!
Congratulations! You have just run your first Kotlin application.
Once you’ve created this application, you can start to dive deeper into Kotlin syntax:
© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/docs/tutorials/jvm-get-started.html