Kotlin Basic Syntax

Kotlin Basic Syntax

In this tutorial, we will learn the basic syntax of Kotlin language. We will go through the key components of a simple Kotlin program.

Kotlin Program

fun main() {
    println("Hello, World!")


Hello, World!

Basic Syntax of a Kotlin Program

  1. fun main()
    This line defines the main function, which is the entry point of a Kotlin program. The fun keyword is used to declare a function.
  2. {
    This opening brace marks the beginning of the main function's body.
  3. println("Hello, World!")
    This line prints the string "Hello, World!" to the standard output (usually the screen). The println function is a built-in function in Kotlin for outputting a line of text.
  4. }
    This closing brace marks the end of the main function's body.

Key Points to Remember

  • All Kotlin statements must end with a semicolon (;), but it is optional and often omitted due to Kotlin's smart semicolon inference.
  • The main function is the entry point of a Kotlin program.
  • Comments can be added using // for single-line comments or /* ... */ for multi-line comments.
  • Code blocks are enclosed in curly braces {}.
  • Kotlin is case-sensitive, meaning that Main and main would be considered different identifiers.