Before we dive deep into Kotlin, let’s begin with a simple program that can print Hello world! In console. “Hello World!” printing program is a simple program that is often used to introduce a new programming language.
Let’s begin
You will find the following code written. If not you can write it on your own. This code will print Hello World!. To run the code right-click in any blank area inside your code and click on run.
fun main(args: Array) {
println("Hello World!")
}
At this point, you should have good information about IntelliJ IDEA and the process of writing and executing code in it. We wrote a code and executed it, but till now we haven’t seen the concept behind the program. Let’s understand the concepts and keywords used in Hello World Program.
fun main(args: Array) {
println("Hello World!")
}
The first line in the program defines a function main (). It is the entry point of the program in kotlin. It is the first function that is called during the execution of the Kotlin program. In Kotlin, function means the group of statements that are grouped to perform a specific task. The definition of function starts with the keyword The main() function takes an array of string as a parameter and returns Unit (i.e. does not return any value). If you are familiar with java, then the Unit is the same as the void in java. Declaring Unit is optional.
The second line prints the string “Hello World!”. The function println() prints the given message inside the quotation marks and moves the cursor to the new line.
Post a Comment
No Comments