Skip to content
Learn Netverks

Lesson

Step 10/36 28% through track

functions-kotlin

Functions

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Functions: the syntax, patterns, and safety habits you need before advancing in Kotlin.

Teams still ship Functions in Kotlin codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Functions in contexts like: Android apps, Spring services, and shared KMP modules.

Write Kotlin in main.kt with fun main(), click Run on server—the dev runner kotlinc compiles to a JVM jar and java runs it; use println for output (requires JDK + kotlinc; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Functions are first-class in Kotlin—default parameters, named arguments, and single-expression bodies reduce boilerplate compared to Java.

Basics

fun greet(name: String, prefix: String = "Hello"): String =
    "$prefix, $name"

fun main() {
    println(greet("Ada"))
    println(greet(name = "Bob", prefix = "Hi"))
}

Important interview questions and answers

  1. Q: Default parameters?
    A: Kotlin generates overloads for Java with @JvmOverloads when needed.
  2. Q: Single-expression functions?
    A: Use = body when the function is one expression—return type can be inferred.

Self-check

  1. How do you call a function with named arguments?
  2. What keyword starts a function declaration?

Tip: Add @JvmOverloads when Java callers need overloads for default parameters.

Interview prep

Default parameters?

Reduce overloads; use @JvmOverloads for Java.

Single-expression functions?

Use = body when one expression.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Default args?
  • Single-expression fun?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump