Skip to content
Learn Netverks

Lesson

Step 29/36 81% through track

packages-imports-kotlin

Packages and imports

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
intermediate

This lesson

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

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

You will apply Packages and imports 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.

Packages organize Kotlin source like Java packages: directory structure mirrors package names. Imports bring types and top-level functions into scope; use aliases to resolve name clashes.

Package declaration

package com.example.app

import kotlin.math.sqrt
import java.util.Locale as JLocale

Top-level functions in utils.kt compile to a JVM class—control Java names with @file:JvmName("Utils").

Visibility

public (default), internal (module), protected, privateinternal hides APIs inside a Gradle module.

Important interview questions and answers

  1. Q: Package vs folder?
    A: Convention requires matching paths; mismatches confuse tooling and reviewers.
  2. Q: import alias?
    A: import Foo as Bar disambiguates colliding class names from different packages.

Self-check

  1. What visibility is the default in Kotlin?
  2. How do you rename an import?

Tip: Directory structure should match package names in JVM projects—Gradle source sets enforce layout.

Interview prep

Package declaration?

package com.example at file top; folder should match on JVM.

Import alias?

import Foo as Bar for name clashes.

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

  • import alias?
  • Top-level functions?

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