Home Android Tutorial Creating Hello World Project in Kotlin

Creating Hello World Project in Kotlin

0

A “Hello, World!” is a simple program that outputs Hello, World! on the screen. Since it’s a very simple program, it’s often used to introduce a new programming language.

Only imports and declarations can exist at the top level of a Kotlin file. Therefore, “running” an individual file only makes sense if it contains an entry point, which must be a function called main with one argument called args of the type “array of strings”. args will contain the command-line arguments that the program is invoked with, similarly to sys.argv in Python; it can be omitted if your program does not need to accept command-line arguments and you are using Kotlin 1.3:

Kotlin was created by JetBrains. Kotlin is and object-oriented and functional programming language. Kotlin was designed to be a pragmatic, concise, safe, and interoperable programming language.

Any line starting with // is a comment in Kotlin (similar to Java). Comments are ignored by the compiler. They are intended for person reading the code to better understand the intent and functionality of the program. To learn more, visit Kotlin comments.

If you are using IntelliJ IDEA, go to Run > Edit Configurations to view this class. If you named your Kotlin file HelloWorld.kt, the compiler creates HelloWorldKt class.

The main() function is the entry point of every program. All functions in kotlin start fun keyword followed by the name of function(here main is the name), a list of parameters, an optional return type and the body of the function ( { ……. } ).
In this case, main function contains the argument – an array of strings and return units. Unit type corresponds to void in java means the function does not return any value.