HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to KotlinVariables (val / var)Data TypesStringsListsConditions (if / when)Loops (for / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables & Types
🔢 Numbers & Math
✍️ String
📚 Collection
🔀 Condition & Loop
🧩 Function
Kotlin›Introduction to Kotlin

Introduction to Kotlin

First Kotlin program: printing to the screen using the main function and println.

Simple enough for a 5-year-old to understand

Your first program

A Kotlin program starts from the main function. println prints the text you provide to the screen and moves to the next line.

Hello
1
fun main() {
The program starts here.
FunctionThe program starts here.
2
println("Hello!")
Prints the text inside the quotes to the screen.
Output / InputPrints the text inside the quotes to the screen.
3
}
End of the function.
FunctionEnd of the function.
FunctionOutput / Input
💡 Hint: In Kotlin, you don't have to put a semicolon at the end of the line.

Print multiple lines

Example code
1
fun main() {
2
println("First line")
Prints the first line.
Output / InputPrints the first line.
3
println("Second line")
Moves to the next line and prints the second one.
Output / InputMoves to the next line and prints the second one.
4
}
Output / Input

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (2 left)

1.Which function does a Kotlin program start from?
2.What is the difference between println and print?

About this topic

Kotlin is a modern programming language developed by JetBrains and running on the Java virtual machine. In 2019, Google declared Kotlin as the preferred language for Android development; today, the vast majority of new Android projects start with Kotlin.

Kotlin's raison d'être was to reduce Java's boilerplate and eliminate the most expensive type of error. In Java, the language does not know whether an object is null or not; in Kotlin, this information is part of the type. That is why the null pointer problem, known as the billion-dollar mistake, is caught at compile time in Kotlin.

Kotlin works seamlessly in the same project as Java. You can call your existing Java classes and use Kotlin classes from Java. This compatibility allowed large projects to change languages gradually and became the most important reason for Kotlin's rapid spread.

What you will learn

  • the entry point of a Kotlin program
  • printing to the screen with println
  • string template syntax
  • Writing comment lines
  • that semicolons are not required

Who is this for?

  • Those who want to develop Android apps
  • Those who know Java and are looking for a more concise language
  • Those who want to learn a modern language running on the JVM

When to use?

Kotlin is used for Android apps, server-side services, and multiplatform shared code; backend development with Ktor and Spring Boot is common.

There is no special advantage to using Kotlin for jobs outside the Java ecosystem; other languages are more suitable for systems programming or data science.

Common mistakes

Wrong

public static void main(String[] args) {
  System.out.println("Hello")
}

This is Java syntax, it does not compile in Kotlin. In Kotlin, the entry point is defined with fun main, it doesn't need to be placed inside a class, and println is enough to print to the screen. Those transitioning from Java write this pattern out of reflex in the first few days.

Correct

fun main() {
  println("Hello")
}

Wrong

fun main() {
  val name = "Ayşe"
  println("Merhaba name")
}

To include a variable's value in the text, you need a dollar sign at the beginning of its name; otherwise, literally "Hello name" is printed to the screen. In Kotlin, string templates are the standard way of concatenating text, and they are both more readable and more efficient than the plus operator.

Correct

fun main() {
  val name = "Ayşe"
  println("Merhaba $name")
}

Wrong

fun main() {
  print("one")
  print("two")
}

There is no compilation error here, but the output is different than expected: "onetwo" is printed to the screen because print does not add a newline. It is very common to confuse it with println, which wants a newline. That is the only difference between the two.

Correct

fun main() {
  println("one")
  println("two")
}

Frequently asked questions

Is knowing Java a must to learn Kotlin?

Not a must, Kotlin can be learned as a first language as well. But when developing Android, you will frequently encounter libraries and documentation written in Java; being able to read basic Java makes your job easier.

Should I use semicolons?

No, in Kotlin, a newline ends the statement. Semicolons are only needed if you write multiple statements on the same line, and even then, it is not a recommended style. Semicolons written out of habit from Java generate compiler warnings.

Does Kotlin code run slower than Java?

No. Kotlin compiles to the same bytecode and runs on the same virtual machine. Some language features may introduce small overheads, but in practice, the difference is not measurable.

Summary

The entry point is the fun main function.

println adds a newline, print does not.

In a string template, the variable is preceded by a dollar sign.

Semicolons are not required.

Kotlin can run in the same project as Java.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code