Kotlin Tutorial

Kotlin Classes

Kotlin Syntax:

In the previous chapter, we created our first project and ran our Main.kt, and we used the code below to print “Hello World”.

				
					fun main() {
   println("Hello World!")
}

				
			

Code Explained:

An entry point of Kotlin is the main function. The fun keyword is used to declare a function. A function is a block of code that is written to perform a specific task. In the example above we declare main() function.

 

“An entry point of Kotlin is the main function”, This main function is the function you’ll see in every Kotlin program. This function is used to execute code. Curly brackets {} are used to open the body of a function and the code inside the body will be executed.


In the above code example, the println() is inside the main() function body, It means this will be executed. The println() function is used to print output in the console.

Main Arguments:

				
					fun main(args: Array<String>) {
   println("Hello World!")
}

				
			

After Kotlin 1.3, We can now RUN our Kotlin program without these main args (arguments), before Kotlin 1.3 this was required.