Lesson 3: Steps to create first program in Kotlin

Lesson 3: Steps to create first program in Kotlin

Hello viewer, You can now have our Tutorial Lessons in your android mobile device and read it offline.
Download kotlin Programming APP on PlayStore
Download Website SEO Lessons APP on PlayStore

We saw in the previous concept that when we started IntelliJ IDEA and not yet created a project the following screen appears:

Lesson 3: Steps to create first program in Kotlin - Lesson 3: Steps to create first program in Kotlin - Lesson 3: Steps to create first program in Kotlin - Steps to create first program in Kotlin coding180

First we can create a folder where we will store all the projects that we will develop in Kotlin, I propose the folder:

 C:\programaskotlin

Let’s create our first project in Kotlin, choose the option “Create New Project” and then the dialogue appears:

Lesson 3: Steps to create first program in Kotlin - Lesson 3: Steps to create first program in Kotlin - Lesson 3: Steps to create first program in Kotlin - Steps to create first program in Kotlin coding180
Steps to create first program in Kotlin coding180.com

Now we must indicate the name of the project and the folder where it will be stored (we indicate the folder that we created previously from Windows) and a subfolder that will be created by the same IntelliJ IDEA called codingproject:

Lesson 3: Steps to create first program in Kotlin - Lesson 3: Steps to create first program in Kotlin - Lesson 3: Steps to create first program in Kotlin - Steps to create first program in Kotlin coding180.com
Steps to create first program in Kotlin coding180.com

If the SDK does not appear we should look for the folder where the Java SDK was installed that we installed as a first step in the previous concept.

Now if we have the IntelliJ IDEA environment open and ready for our “codingProject”:

Lesson 3: Steps to create first program in Kotlin - Lesson 3: Steps to create first program in Kotlin - Lesson 3: Steps to create first program in Kotlin - Steps to create first program in Kotlin coding180.com
Steps to create first program in Kotlin coding180.com

In the “Project” window in the “src” folder is where we need to create the source files in Kotlin, right click on this folder and select “New -> Kotlin File/Class“:

Lesson 3: Steps to create first program in Kotlin - Lesson 3: Steps to create first program in Kotlin - Lesson 3: Steps to create first program in Kotlin - Steps to create first program in Kotlin coding180.com
Steps to create first program in Kotlin coding180.com

A dialog appears where we indicate that we want to create a file “File” with the name “coding180project”:

Lesson 3: Steps to create first program in Kotlin - Lesson 3: Steps to create first program in Kotlin - Lesson 3: Steps to create first program in Kotlin - Steps to create first program in Kotlin coding180.com
Steps to create first program in Kotlin coding180.com

After confirming the file “coding180project.kt” has been created where we will store our first program in Kotlin:

Lesson 3: Steps to create first program in Kotlin - Lesson 3: Steps to create first program in Kotlin - Lesson 3: Steps to create first program in Kotlin - Steps to create first program in Kotlin coding180.com
Steps to create first program in Kotlin coding180.com

The IntelliJ IDEA generates a comment in the file automatically:

 / **
  * Created by Robort on 06/24/2017.
  * /

The comments then the Kotlin compiler does not take them into account and are intended to document the program by the developer (comments are enclosed between the characters / ** * /)

Problem: Create a simple Hello world Program

Create a minimal program in Kotlin that displays a message on the console.

Project1 – coding180project.kt

 

/ **
  * Created by robort on 05/20/2017.
  * /
 fun main (parameter: Array <String>) {
     print ("Hello World")
 }

 

Every program in Kotlin starts in the main function. Then we will see the objective of the data that receives the function main in parentheses (parameter: Array <String>), for now we will write it and we will not use it.

A function starts with the keyword fun then in parentheses the parameters arrive and between keys we have the algorithm that solves our problem.

If we want to display a message through the Console we must use the function “print” and double quotation marks the message that we want to appear:

print ("Hello World")

To run the program we have several possibilities, one is to press the icon next to the main function and choose “Run coding180project.kt”:

Lesson 3: Steps to create first program in Kotlin - Lesson 3: Steps to create first program in Kotlin - Lesson 3: Steps to create first program in Kotlin - Steps to create first program in Kotlin coding180.com

After this appears the Console window with the result of the program execution:

Lesson 3: Steps to create first program in Kotlin - Lesson 3: Steps to create first program in Kotlin - Lesson 3: Steps to create first program in Kotlin - Steps to create first program in Kotlin coding180.com

We can also run the program by selecting from the menu “Run -> Run …”

Every time we develop a program we have to make clear all the steps we took to create the project, create the file “Coding180project.kt”, codify it, compile it and see if the results are the desired ones.

About The Author

Related posts

1 Comment

  1. Pingback: essayforme

Leave a Reply