Tutorial by Examples

All Kotlin programs start at the main function. Here is an example of a simple Kotlin "Hello World" program: package my.program fun main(args: Array<String>) { println("Hello, world!") } Place the above code into a file named Main.kt (this filename is entirel...
You can alternatively use an Object Declaration that contains the main function for a Kotlin program. package my.program object App { @JvmStatic fun main(args: Array<String>) { println("Hello World") } } The class name that you will run is the name of you...
Similar to using an Object Declaration, you can define the main function of a Kotlin program using a Companion Object of a class. package my.program class App { companion object { @JvmStatic fun main(args: Array<String>) { println("Hello World") ...
All of these main method styles can also be used with varargs: package my.program fun main(vararg args: String) { println("Hello, world!") }
As java provide two different commands to compile and run Java code. Same as Kotlin also provide you different commands. javac to compile java files. java to run java files. Same as kotlinc to compile kotlin files kotlin to run kotlin files.
The arguments passed from the console can be received in the Kotlin program and it can be used as an input. You can pass N (1 2 3 and so on) numbers of arguments from the command prompt. A simple example of a command-line argument in Kotlin. fun main(args: Array<String>) { println(&qu...

Page 1 of 1