Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

A package declaration in Kotlin establishes the namespace for the contents of a source file, dictating the fully qualified name (FQN) of all classes, interfaces, functions, and properties defined within it.
package org.company.project.module

Technical Characteristics

Placement and Syntax The package directive must be placed at the top of a Kotlin source file (.kt), immediately following any file-level annotations (such as @file:JvmName(...) or @file:OptIn(...)). It must strictly precede all import directives and top-level declarations. Visibility and Access Control In Kotlin, packages are strictly used for namespacing and code organization; they do not provide encapsulation or access control. Unlike Java, Kotlin does not have “package-private” visibility, and packages do not dictate visibility boundaries. Access control is instead managed via visibility modifiers (private, protected, internal, public), where internal restricts visibility to the compilation module, completely independent of the package structure. File System Decoupling Kotlin does not enforce a strict mapping between the declared package name and the underlying directory structure. A file containing package org.example.network can technically reside in any directory path (e.g., src/main/kotlin/utils/). However, aligning the directory structure with the package name remains the standard convention for Java interoperability and project navigation. Default Package If a Kotlin source file omits the package declaration, all top-level declarations within that file are automatically assigned to the default, unnamed package. Namespace Scope The package declaration applies to all top-level constructs in the file, including variables and functions, rather than being limited to classes.
@file:JvmName("CoreUtils") // File-level annotations must precede the package

package com.system.core

// FQN: com.system.core.MAX_RETRIES
const val MAX_RETRIES = 3 

// FQN: com.system.core.initialize()
fun initialize() { } 

// FQN: com.system.core.Engine
class Engine { } 
Multiple Files A single package can be declared across multiple Kotlin source files. The compiler aggregates all top-level declarations sharing the same package declaration into a single logical namespace, regardless of their physical file distribution.
Master Kotlin with Deep Grasping Methodology!Learn More