What file extension does EK9 use?
← Getting Started · Ref: Q20
EK9 source files use the .ek9 extension.
Key points about EK9 files:
1. Extension: .ek9
All EK9 source files must end with .ek9. The compiler will not process files with other extensions.
2. File name does NOT need to match the module name
Unlike Java (where MyClass.java must contain class MyClass), EK9 file names are independent of module names. You can name files descriptively: utilities.ek9, web_server.ek9, data_model.ek9.
3. One module per file
Each .ek9 file contains exactly one defines module declaration. This keeps the mapping between files and modules clear.
4. File structure
Every file starts with #!ek9, followed by optional comments or metadata headers, then defines module, then construct blocks (defines function, defines class, defines program, etc.).
5. Convention
Use lowercase names with underscores for descriptive file names. Group related files in directories that mirror your module hierarchy.
See Q5 for source file structure. See Q6 for organizing modules across files.
Example
defines module qa.getting.started.file.extension defines function fileInfo() <- info as String: "This file is named QA0020_file_extension.ek9" defines program FileExtension() stdout <- Stdout() stdout.println(fileInfo())
Common mistakes
E50060 — EK9 Stdout has println() for line output, not write(). Triggers E50060 — method not resolved. See ek9 -h Stdout for the full API.
Incorrect:
stdout.write(fileInfo())
Correct:
stdout.println(fileInfo())
Other ways to ask this
- What is the file extension for EK9 source code?
- Do EK9 files use .ek9 extension?
- Does the file name need to match the module name?
Coming from another language?
Java: .java with class name matching file name, Python: .py with no naming constraint, Rust: .rs with mod.rs convention, Go: .go with package declaration. EK9: .ek9 with no file-to-module name constraint. Simpler than Java's strict naming rule, similar flexibility to Python and Rust.
Keywords: structure, beginner, module, naming, extension, migrate, file, first, ek9, start, convention, intro, source