Compile to Bytecode and Run
Let’s first create a small Hello World program in Kotlin. Using your favorite text editor create a file named Hello.kt, like so:
| fun main() = println("Hello World") |
Don’t worry about the syntax in the code at this time; let’s keep our focus on getting the code to run. We’ll discuss the language syntax and semantics in following chapters. You may specify the parameter for the main() function if you like, but starting with Kotlin 1.3, it’s optional. If you’re using a version prior to 1.3, then you’ll need to add the parameter, like so: fun main(args: Array<String>).
Running on the Command Line
To compile and run the code from the command line, first execute the following command:
| $ kotlinc-jvm ... |
Get Programming Kotlin now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.