Table of content

Create Kotlin Project

Follow below steps to create your first kotlin Project in intelliJ IDE.

  • Double click the IntelliJ shortcut present in the Desktop or choose it from start menu
  • Select Create New Project Option from the welcome screen
  • welcome-screen-intellij
  • Choose Kotlin as you project and Kotlin JVM module
  • choose-kotlin-kotlin-jvm-project
  • Choose the installed JDK at the place of Project SDK
  • kotlin-runtime-jvm
  • Expand the Project and right click on the src folder and select New->Kotlin File
  • new-kotlin-file
  • Provide the name for the Kotlin File, this is not class name we are just providing file name
  • first-kotlin-file
  • Place below code in the above created file
  • first-script-kotlin-function
  • Run the Script by Going to Run Tab and select Run <File Name>
  • run-first-kotlin-script
  • You might see the output like below
  • hello-mars-kotlin

Safe Call Operator [?.]

First Program in Kotlin

We have executed a program, lets discuss about the components in the programs, I have highlighted them below. first-script-kotlin-function-highlight

  1. 1 & 8 Comments :

    Comments are nothing but a informational lines for the user.

    Compiler doesn't count the comments as the member for compilation, so whatever is present in comment, compiler will ignore them.

    There two types of comments :

    • Multi-line comments : Whatever is present inside /* and */ will be considered as comments
    • Single line comments : whatever present after // will be considered as comment


  2. 2 fun ;

    fun is keyword used to denote that, this block is a function

  3. 3 main :

    this is nothing but a function name, it could contain any name, main function is the place where the execution starts.

  4. 4 args :

    this is parameter name, an function can accept n-number of parameters. Parameter follows all the variables properties

  5. 5 Array<> :

    this is nothing but the parameter type, unlike other languages, In kotlin variable comes first and then variable type. Types could be anything, here we are accepting Array with generic

  6. 6 <String> :

    this is nothing but the generic, here we are using the string type as generic. we will discuss more about generic on generic tutorial.

  7. 7 braces :

    braces are used to contains the elements inside the block, if we write outside anything then it belongs to other function or to class

  8. 9 println() :

    println() is nothing but a function which will direct the given value into console of the ide/terminal

  9. 10 input value for println() :

    this value could be any type, and this value will be redirected to console after resolving the values (as of this, we have not elements to resolve)

Parameters in Kotlin Functions

aaaaaaaaaaaaa
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions

Recent Addition

new tutorial Selenium Online Training : Our next online training course for Selenium with Java starts from 17th December 2018.

You can attend first 3 classes for free, the total course fee is INR 10,000

The course time would be 8.00 PM(IST) for the first three classes

If you are interested to learn, then you can join the course by sending email to chercher.tech@gmail.com

or Register below


 
Join My Facebook Group
Join Group