Getting Started with IntelliJ IDEA - Kotlin

It’s easy to get started with Kotlin using the Kotlin plugin integrated in IntelliJ IDEA. Benefit from code highlighting, code completion, refactoring, debugging, and other features available for Kotlin.

If you want to start from scratch, you can create a basic Kotlin application. Once you’ve created the application, you can dive deeper into Kotlin syntax.

What is Kotlin?

Kotlin is an expressive and concise programming language that reduces common errors. Easily integrates into existing apps and is 100% interoperable with the Java language. Multiplatform. Code safely. Online courses. Easy to learn. Big community. Write less code.

IDEs?

IntelliJ IDEA IDE (Download, Install):

IntelliJ has a lot of versatility and stability. Kotlin was initially developed by the JetBrains team, which means there’s an extra level of compatibility between the two. Kotlin even has IntelliJ-specific tutorials and getting started guides.

Kotlin Playground (Online, Web Brower base):

You can try/ learn kotlin online without downloading or installing any ide on your computer.

Android Studio (Download, Install):

Android Studio provides the developers with fast tools for building apps on every type of Android device. Android Studio has had full support for Kotlin.

or

Text Editor (Download, Install)

Sublime Text

Getting Started with IntelliJ IDEA

Create an application

Once you've installed IntelliJ IDEA, it's time to create your first Kotlin application.

  1. In IntelliJ IDEA, select File | New | Project.
  2. In the panel on the left, select Kotlin.
  3. Enter a project name, select Console Application as the project template, and click Next.

    k01

    By default, your project will use the Gradle build system with Kotlin DSL.

  4. Go through and accept the default configuration, then click Finish.

    k02

    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.

  5. 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!.


  6. Modify the code so that it requests your name and says Hello to you specifically, and not to the whole world.

    • Introduce a local variable name with the keyword val. It will get its value from an input where you will enter your name – readLine().
    • Use a string template by adding a dollar sign $ before this variable name directly in the text output like this – $name.


Run the application

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'.

k03

You can see the result in the Run tool window.

k04

Enter your name and accept the greetings from your application!

k05

Congratulations! You have just run your first Kotlin application.

Source

← Back to Home

Comments

Post a Comment