androidengineers.Book a session

Kotlin Basics and Syntax

Kotlin Introduction and Setup (K2 compiler, IntelliJ/AS)

article15 minEasy

Start with a runnable program

Kotlin source files use the .kt extension. For these foundations, create a Kotlin/JVM console project in IntelliJ IDEA; Android Studio is useful when you move to an Android app. Let the project wizard choose a compatible Kotlin plugin and JDK, and record those choices in version control. K2 is the compiler frontend, not a separate programming language or a replacement for the JDK.

fun main() {
    val learner = "Asha"
    println("Welcome, $learner")
}

main is the console entry point. val creates a reference that cannot be reassigned. println writes one line to standard output. Run the file using the IDE's Run action; the result is Welcome, Asha. Android applications start through framework components instead, so do not add a console main to an Activity and expect Android to run it.

Exercise

Create a project, run this program, then change the greeting to print your name and one learning goal on separate lines. Introduce an unknown variable deliberately and read the compiler message before fixing it.

Check: you should be able to distinguish a compile error from a successfully running program that prints the wrong text. Commit the Gradle wrapper and source, excluding local IDE caches and credentials.

Reference: Kotlin IDE setup

YOUR LEARNING JOURNEY

0 of 110 available lessons completed

Progress saved in this browser. No account needed.
Kotlin Introduction and Setup (K2 compiler, IntelliJ/AS) | Kotlin Core Programming | Android Engineers