Learn to code the easier way! (KOTLIN)

in DTube3 years ago (edited)


This is the first video introducing you to the world of programming with Kotlin. There are less complicated steps to take and you can learn to code your first program right away. So even if you do not have any experience, you will literally gain confidence with my videos.

In this video, you are introduced to the Kotlin language, an Online IDE (Integrated Development Environment): which makes coding easier, the println key word and two variable types. In my next video, we will be going further to learn kotlin programming.

I'll attach a link to my Steemit Kotlin tutorials to making the next video class easier to relate with. Thank you!


▶️ DTube
▶️ IPFS

What is Kotlin?


Kotlin is a cross-platform programming language used especially in designing android applications. Everyday, people are switching from Java to Kotlin because of its simplicity and efficiency. This is a link to the online IDE we will be making use of: https://play.kotlinlang.org

Once the online IDE loads, clear the default codes so you can play around. Always remember that the best way to learn to code is to play around.


Introduction to Keywords used in this tutorial

Keywords used in this tutorial include: fun, var and println .

1: The fun keyword is used to declare a function, it is followed by the function name, a parenthesis () and curly brackets {}. Inside of the curly brackets are the series of code that will be executed.

Example:

fun main () {
>  }



Your function can have different names depending on what you intend the code it contains to do. For example:

 fun playMusic () {
 // codes to play a sound track
 }

 fun displayImage () {
 // codes to display an image and size
 }

 fun main () {
>}



However, it should be noted that when a compiles begins to compile, it starts with the main function. This means irrespective of the order of functions, only codes in the main function will be executed first. In the main function, you can then call the other functions so their codes can be executed.

For example:

 fun playMusic () {
 // codes to play a sound track
 }

 fun displayImage () {
 // codes to display an image and size
 }

 fun main () {
          playMusic ()
          displayImage ()
}



To call any function in the main, all you need is to input the function name and a parentheses, you do not need a fun keyword.



2: The var keyword is used to declare an variable. A variable is a data item that stores a value. Variables can contain values of different data types such as Integer (Int), Byte (Byte), Double (Double), Float (Float), Boolean (Boolean), Character (Char) and String (String). The variable types used in this tutorial are the String and Integer. The string contains sequence of characters /letters and sometimes numbers and special characters. However, the Integer contains strictly numbers. In further classes, we will discuss these data types to the fullest.

To declare a variable, you use the keyword var followed by the variable name. A Column :specify the datatype then an equal sign = to assign a value.

For example:

 fun main () {
         var numbers : Int = 200
         var year : Int = 1982
         var age : Int = 12

         var name : String = "Michael"
         var school : String = "Harvard"
}



Note that String values are stored in quotes.

It is not possible to apply a wrong value to a data type, for example. You can't characters to a variable specified as Int. You can experiment with this and see the error code produced during compilation. Example:

fun main () {
          var name : Int = "Joseph"
          var age : String = 76
 }



3: The println keyword which is used to display strings, integers or characters to the screen / console. It is a programmers best friend. There is a variety of the key word : print which only prints but doesn't add a new line to the next print. You can experiment with it.

What ever you want to print to the console must be in the println / print parenthesis. For example:

 fun main () {
        println (8)
        print ("Moses, Yussuff")
 }

Note that strings are placed in apostrophe to be printed, while integers do not necessarily need to be in quotes.

You can perform arithmetic operations in the println / print keyword:

fun main () {
         println (3 + 3 / 2)
}



And you can as well assign this arithmetic operation to a variable.

Example 1:

fun  main (){
         var num1 : Int = 10
         var num2 : Int = 11
         println (num1 + num2) //  this will display 22 to the console
}



Example 2:

fun  main (){
         var num1 : Int = 10
         var num2 : Int = 11
         var num3 : Int = num1 + num2

         println (num3) //  this will display 22 to the console
}


Bonus: For waiting till the end of this lecture, let me introduce to you to comment line. Line comment / Comment line are used to explain what a code does to make it easier for humans to read. They have been used in this lecture and are denoted using the forward slash. Lines written in the comment line are not executed.

fun  main (){

         // The following code calculates and prints the sum of num1 and num2
         var num1 : Int = 10
         var num2 : Int = 11
         println (num1 + num2) //  this will display 22 to the console

        // The following code calculates and prints the area of a circle
        var length : Int = 20
        var breadth : Int = 12
        var area : Int = length * breadth
        println (area)

       /// The following code calculates and prints the square of the area above
       var squareOfArea : Int = area * area
       println (squareOfArea)

  }



Till next time, thank you!

Sort:  

Your audio sucks. Can’t hear shit.

Get your speakers repaired!

Coin Marketplace

STEEM 0.17
TRX 0.16
JST 0.028
BTC 76457.44
ETH 2977.83
USDT 1.00
SBD 2.62