A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Hello World in Kotlin page! Here, you'll find the source code for this program as well as a description of how the program works.
fun main(args: Array<String>) {
println("Hello, World!")
}
Hello World in Kotlin was written by:
This article was written by:
If you see anything you'd like to change or update, please consider contributing.
Let's get down to business, Hello World in Kotlin.
On the first line, we have the package
declaration. Like most
languages, this basically declares the package or module name
of this file. If anyone needed to use a function in this file,
they could access it via the package name.
Next, we have the function definition. In this first line, we
can see we define the main
function which receives an array of
String
s as input. In a lot of languages, types are declared in
type-var order, not in Kotlin. In Kotlin, we declare the variable
name before giving it a type.
Finally, we print Hello World in Kotlin. Like many languages,
we use a simple call to the println
function, so no surprises there.
At this point, we probably want to actually run the Hello World in Kotlin code snippet. Perhaps the easiest way to do so is to leverage the online Kotlin editor.
Alternatively, we can use the latest standalone compiler. Of course, we'll want to get a copy of Hello World in Kotlin while we're at it. With both in hand, all we need to do is navigate to the folder containing our files and run the following:
kotlinc HelloWorld.kt -include-runtime -d HelloWorld.jar
java -jar HelloWorld.jar
The standalone Kotlin compiler compiles Kotlin down to a
runnable Java Archive (jar
) which we can then execute using the Java Runtime
Environment.