Creating Hello World Programme

Open Intellij IDEA to create new project, go to file menu and select new project. It will display the following dialog box select kotlin and Kotlin/Jvm and click next.



The project details window will be opened



Project Name: Name of your project
Project Location:Path to save your project
Project Sdk: path of jdk installed in your machine i.e C:\Program Files\Java\jdk1.8.0_121
User Library:By default it will give Kotlin java runtime you can continue with this library .

The sdk path will com by default if it will come by default click on new and select the jdk path like bellow.



After completion jdk path settings select kotlinjavaruntime library and click finish. The project will be created successfully.

Select View =>Tool windows=>Project and expand the project.
Select src and right click on it. It will display a window like bellow, select new =>KotlinFile/Class.



give the file name like bellow and click ok. The kind must be the File type only.



Creating hello world program

fun main(args: Array<String>)
{
    println(
"My first kotlin programme")
}

Note: Kotlin is more expressive and concise language. There is no need to create class explicitly like
java.

By pressing Shift +F10 you can run the project.
The .kt is the extension of the kotlin file.

Execution of  kotlin file:
Like java kotlin also create .class files at runtime. kotlin creates class files with the filename suffixed with KT you can view this files in out folder in project.








Explanation of Program


fun main(args: Array<String>) {     println("My first kotlin programme") }
Note: Kotlin is more expressive and concise language. There is no need to create class explicitly like java.

The above program is equal to following program in java
Class MyClass
{
 public static void main(string[] args)
  {
    System.out.println();
  }
 }


Java Vs Kotlin


There is no need to create class explicitly like java in kotlin. 
Unit is a return type it is equal to void in java.
In the place of unit you can give a data type which you want to return from a method.
There is no static concept in kotlin language.
Semicolon is not needed at the end of statement in kotlin.



Comments