Writing Your First Kotlin Program
Create a file named Hello.kt. In Kotlin, the filename is flexible, but it’s a good practice to use a name that matches the class or function inside.
fun main() {
println("Hello, World!")
}
Hello, World!
Create a file named Hello.kt. In Kotlin, the filename is flexible, but it’s a good practice to use a name that matches the class or function inside.
fun main() {
println("Hello, World!")
}
Hello, World!
If you are using the command line, save the file as Hello.kt and run:
kotlinc Hello.kt -include-runtime -d Hello.jar
The kotlinc command invokes the Kotlin compiler:
.kt source file — written in Kotlin code..jar file, e.g., Hello.jar.To run the compiled program, use the following command:
java -jar Hello.jar
The Java Virtual Machine (JVM) executes the compiled Kotlin bytecode:
Hello.jar file into memory.main function.Hello, World! to the console.Hello, World!
You’ve now compiled and executed your first Kotlin program — a foundational step in learning the Kotlin programming language.
main entry point.main and Main are different..jar.