Skip to main content
Browse topics

KDoc Comments in Kotlin

2 min read Updated June 30, 2026
Share

Introduction

KDoc Comments is a fundamental concept every Kotlin developer should understand. Start here with your first program, variables, comments and KDoc documentation basics.

KDoc is Kotlin’s documentation comment format, similar to Javadoc. In this tutorial you will learn the syntax, walk through a complete example program, study the sample output, and review best practices so you can apply the concept confidently in your own projects.

Definition

  • KDoc is Kotlin’s documentation comment format, similar to Javadoc.
  • KDoc comments start with /** and end with */ and support Markdown syntax.
  • Documentation tools and IDEs use KDoc to show inline help for functions and classes.

Syntax

kotlin
/**
 * Returns the sum of two integers.
 * @param a first number
 * @param b second number
 */
fun add(a: Int, b: Int): Int = a + b

KDoc Comments in Kotlin Example Program in Kotlin

kotlin
/**
 * KDoc example program
 */
fun greet(name: String): String = "Hello, $name"

fun main() {
    println(greet("Kotlin"))
}

Sample Output

plaintext
Hello, Kotlin

When to use

Start with basic programs before moving to classes, collections, or coroutines.

How it works

  1. The program starts with a main function — the entry point that runs when you execute the file.

  2. KDoc is Kotlin’s documentation comment format, similar to Javadoc.

  3. Run the program in IntelliJ IDEA, Android Studio, or with the Kotlin command-line compiler (kotlinc / kotlin). Compare your console output with the sample output shown below.

Best Practices

Common Mistakes

Key Points

  • KDoc is Kotlin’s documentation comment format, similar to Javadoc.
  • KDoc comments start with /** and end with */ and support Markdown syntax.
  • Documentation tools and IDEs use KDoc to show inline help for functions and classes.
  • Test the example locally and verify the output matches the sample.
  • Experiment by changing input values to see how behaviour changes.

Notes

  • Semicolons at the end of statements are optional in Kotlin.

Frequently Asked Questions

What is KDoc Comments in Kotlin?
KDoc is Kotlin's documentation comment format, similar to Javadoc.
When should I use KDoc Comments?
Start with basic programs before moving to classes, collections, or coroutines.
How is KDoc Comments different from Java?
Documentation tools and IDEs use KDoc to show inline help for functions and classes.
How do I practice this topic?
Copy the example program into IntelliJ IDEA or Android Studio, run it, then modify values or add print statements to confirm your understanding.

Related tutorials

Search tutorials