Create a Kotlin Project

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

    • Double click the IntelliJ shortcut present in the Desktop or choose it from the start menu
    • Select Create New Project Option from the welcome screen


    • Choose Kotlin as your project and Kotlin JVM module


    • Choose the installed JDK at the place of Project SDK


    • Expand the Project and right-click on the src folder and select New->Kotlin File


    • Provide the name for the Kotlin File, this is not a class name we are just providing a file name


    • Place below code in the above-created file


    • Run the Script by Going to Run Tab and select Run <File Name>


    • You might see the output like below


Safe Call Operator [?.]

    First Program in Kotlin

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

      1. 1 & 8 Comments :

        Comments are nothing but informational lines for the user.

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

        There two types of comments :

        • Multi-line comments : Whatever is present inside /* and */ will be considered as a comments
        • Single line comments : whatever present after // will be considered as a 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, the main function is the place where the execution starts.

      4. 4 args :

        this is parameter name, a 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 the 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 the generic tutorial.

      7. 7 braces :

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

      8. 9 println() :

        println() is nothing but a function which will direct the given value into the 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

      0 results
      Comment / Suggestion Section
      Point our Mistakes and Post Your Suggestions