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, private—internal hides APIs inside a Gradle module.
Important interview questions and answers
- Q: Package vs folder?
A: Convention requires matching paths; mismatches confuse tooling and reviewers. - Q: import alias?
A:import Foo as Bardisambiguates colliding class names from different packages.
Self-check
- What visibility is the default in Kotlin?
- 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.