<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Daniel Brian</title>
    <description>The latest articles on DEV Community by Daniel Brian (@dbriane208).</description>
    <link>https://dev.to/dbriane208</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F852656%2F1a6474d8-e153-4ec7-a98f-79ae79c7f800.jpeg</url>
      <title>DEV Community: Daniel Brian</title>
      <link>https://dev.to/dbriane208</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dbriane208"/>
    <language>en</language>
    <item>
      <title>Mastering Nullability and Collections in Kotlin: Unleash the Full Power of Your Code.</title>
      <dc:creator>Daniel Brian</dc:creator>
      <pubDate>Mon, 24 Apr 2023 20:17:50 +0000</pubDate>
      <link>https://dev.to/dbriane208/mastering-nullability-and-collections-in-kotlin-unleash-the-full-power-of-your-code-4o9g</link>
      <guid>https://dev.to/dbriane208/mastering-nullability-and-collections-in-kotlin-unleash-the-full-power-of-your-code-4o9g</guid>
      <description>&lt;p&gt;In this article, we're going to look at two important concepts in Kotlin OOP;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;1. Nullability&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;2. Collections&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Nullability
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;NullPointer Exceptions are thrown by the program at runtime and sometimes cause application failure or system crashes.&lt;/li&gt;
&lt;li&gt;NullPointer exceptions are caused by:&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Explicit call to throw NullPointer()&lt;/li&gt;
&lt;li&gt;Use of the null assertion operator !!&lt;/li&gt;
&lt;li&gt;Data inconsistency with regard to initialization&lt;/li&gt;
&lt;li&gt;Java interoperations eg attempts to access a member on a null reference.&lt;/li&gt;
&lt;li&gt;Kotlin is designed to avoid errors due to null values. The code below demonstrates this design choice;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
   var message : String = "Hello world"
    message = null
    println(message)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;When you try to run the above code you will realize that it is not possible to assign a null value to the message variable and the compiler will display an error.&lt;/li&gt;
&lt;li&gt;To allow a variable to hold null, we can declare a variable as nullable string, written as &lt;code&gt;String?&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
   var message : String? = "Hello world"
    message = null
    println(message)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If you try to access the length property of the message variable while the message variable is null, the exception will be thrown.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
   var message : String? = "Hello world"
   message = null
   var length = message.length
    println(length)

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To avoid these errors, you will need to check for a null value before accessing the property. Here's the update for the above code in using the length method.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
   var message : String? = "Hello world"
   message = null
    if (message != null){
        var length = message.length
        println(length)
    }else {
        println(null)
    }    
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We can deal with nulls in the following ways:&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Smart casting&lt;/strong&gt; - It is used if you add a condition and it allows for treating a variable as not null after you check that it is not null.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Safe call&lt;/strong&gt; - It means calling the right side, if the left side is not null.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Elvis Operator&lt;/strong&gt; - It is used to provide a default value when a value could be null.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not null insertion&lt;/strong&gt; - The "Not null assertion" is an unsafe option, as it throws an exception when a value is null.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  1. Smart - Casting
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Kotlin compiler tracks conditions inside the &lt;code&gt;if expression&lt;/code&gt;. If the compiler founds a variable is not null or type nullable then the compiler will allow to access the variable.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
   var message : String? = "Hello world"
    //Smart cast
    if (message != null){
        var length = message.length
        println(length)
    }else {
        println(null)
    }    
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;While using &lt;code&gt;is&lt;/code&gt; and &lt;code&gt;!is&lt;/code&gt; for checking the variable the compiler tracks this information and internally cat the variable to the target type.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
   var message : Any? = "Hello world"
    //Smart cast using is
    if (message is String){
        var length = message.length
        println("The string length is $length")
    }    
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This is done inside the scope if &lt;code&gt;is&lt;/code&gt; or &lt;code&gt;!is&lt;/code&gt; returns true.&lt;/li&gt;
&lt;li&gt;In addition we can use !is for smart cast.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
   var message : Any? = 67
    //Smart cast using is
    if (message !is String){
      println("Object is not String")
    } else {
         var length = message.length
        println("The string length is $length") 
    }   
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Not null insertion : !! Operator
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The not null assertion (!!) operator converts any value to non-null type and throws an exception if the value is null.&lt;/li&gt;
&lt;li&gt;If anyone want NullPointer Exception then he can ask explicitly using this operator.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
   var message : String? = "Meercedes Benz"
    //using the not null assertion
    println(message!!.length)  
    // Using a null 
    // The length method we throw an error
    message = null
    println(message!!.length)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Elvis Operator
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;It returns a non- null value  or a default value, when the original variable is null.&lt;/li&gt;
&lt;li&gt;In other words, if left expression is not null then elvis operator returns it, otherwise it returns the right expression.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
 val str: String? = null
val length = str?.length ?: -1
println("Length of the string is $length")
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;we can also throw and return expressions on the right side of the elvis operator and it is very useful infunctions. Hence, we can throw an exception instead of returning a default value in theright side of the elvis operator.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;val name = firstname?: throwIllegalArgumentsExceptions("Enter valid name")&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Safe call
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A safe call is when &lt;code&gt;?.&lt;/code&gt; is used instead of&lt;code&gt;. syntax&lt;/code&gt; between an object and its function or property.&lt;/li&gt;
&lt;li&gt;A safe call calls the right side if the left side is not null. Otherwise, It does nothing and returns null.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
 var str: String? = "Happy Birthday"
    println(str?.length)
    str = null
    println(str?.length)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of the first pritnln will be the length  of our string ,14, the last println will be null.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We can use the safe call operator with let(), also() and run() if value is not null.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;let() method&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The lambda expression present inside the let is executed only if the variable firstName is not null. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;val firstName: String? = null&lt;/code&gt;&lt;br&gt;
&lt;code&gt;firstName?.let { println(it.toUpperCase()) }&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Here, the variable firstName is null, so the lambda expression is not executed to convert the string to Upper Case letters.
Kotlin program of using let.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main(args: Array&amp;lt;String&amp;gt;) {
    // created a list contains names
    var stringlist: List&amp;lt;String?&amp;gt; = listOf("Geeks","for", null, "Geeks")
    // created new list
    var newlist = listOf&amp;lt;String?&amp;gt;()
    for (item in stringlist) {
        // executes only for non-nullable values
        item?.let { newlist = newlist.plus(it) }
    }
    // to print the elements stored in newlist
    for(items in newlist){
        println(items)
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;also() method chain with let()&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If we want to apply some additional operation like printing the non-nullable items of the list we can use an &lt;code&gt;also()&lt;/code&gt; method and chain it with a &lt;code&gt;let()&lt;/code&gt; or &lt;code&gt;run()&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main(args: Array&amp;lt;String&amp;gt;) {
    // created a list contains names
    var stringlist: List&amp;lt;String?&amp;gt; = listOf("Geeks","for", null, "Geeks")
    // created new list
    var newlist = listOf&amp;lt;String?&amp;gt;()
    for (item in stringlist) {
        // executes only for non-nullable values
        item?.let { newlist = newlist.plus(it) }
        item?.also{it -&amp;gt; println(it)}
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;run() method&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Kotlin has a run() method to execute some operation on a nullable reference. &lt;/li&gt;
&lt;li&gt;It seems to be very similar to let() but inside of a function body, the run() method operates only when we use this reference instead of a function parameter:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main(args: Array&amp;lt;String&amp;gt;) {
    // created a list contains names
    var stringlist: List&amp;lt;String?&amp;gt; = listOf("Geeks","for", null, "Geeks")
    // created new list
    var newlist = listOf&amp;lt;String?&amp;gt;()
    for (item in stringlist) {
        // executes only for non-nullable values
        item?.run { newlist = newlist.plus(this) } // this reference
        item?.also{it -&amp;gt; println(it)}
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Collections in Kotlin
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A collection usually contains a number of objects of the same type called elements or items.&lt;/li&gt;
&lt;li&gt;In Kotlin collections can be either &lt;em&gt;mutable&lt;/em&gt; or &lt;em&gt;immutable&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Immutable collections&lt;/strong&gt; supports read-only functionalities and cannot be modified whereas mutable collections supports both read and write functionalities.&lt;/li&gt;
&lt;li&gt;We will look at several collections which include:&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Lists&lt;/li&gt;
&lt;li&gt;Sets&lt;/li&gt;
&lt;li&gt;Map&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Lists
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;It is an ordered collection in which we can access elements using indices.&lt;/li&gt;
&lt;li&gt;In a list, we can have repeating elements.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
 var groceries = listOf("carrots","onions","kales")
 println(groceries)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The result type is &lt;code&gt;list&amp;lt;T&amp;gt;&lt;/code&gt; where &lt;code&gt;T&lt;/code&gt; is the type of the elements in the list. In the code above our lists consists of string hence its type is &lt;code&gt;list&amp;lt;String&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;We add elements to alist using the plus sign (+). You can add a single element to a list or you can add two lists together.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
 var groceries : List&amp;lt;String&amp;gt; = listOf("carrots","onions","kales")
 var numbers : List&amp;lt;Int&amp;gt; = listOf(12,45,78)
 println(groceries + numbers)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We can check the number of items in a list using the &lt;code&gt;size&lt;/code&gt; property.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
 var groceries : List&amp;lt;String&amp;gt; = listOf("carrots","onions","kales")
 var numbers : List&amp;lt;Int&amp;gt; = listOf(12,45,78)
 val shopping = groceries + numbers
 println(shopping.size)//6
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We can use the isEmpathy method or compare the size of a list to zero to check if the list is empty.&lt;/li&gt;
&lt;li&gt;You can get an element at a certain position using the index that is the box brackets.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
 var groceries : List&amp;lt;String&amp;gt; = listOf("carrots","onions","kales")
 var numbers : List&amp;lt;Int&amp;gt; = listOf(12,45,78)
 // using the + adding sign
 val shopping = groceries + numbers
 //using the size property
 println(shopping.size)//6
 // Using the isEmpty() property
 println(shopping.isEmpty())//false
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We use the &lt;code&gt;contains method&lt;/code&gt; or &lt;code&gt;in operator&lt;/code&gt; to check if a set contains a certain element. In the above code we can add the following code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;println("carrots" !in list)//true&lt;/code&gt;&lt;br&gt;
&lt;code&gt;println("apple" in list)// false&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With mutable lists you can use methods like add or remove to add or remove a certain element.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
    val mutableList = mutableListOf("apple", "banana", "cherry")

    // adding an element to the list
    mutableList.add("date")

    // removing an element from the list
    mutableList.remove("banana")

    // updating an element in the list
    mutableList[0] = "apricot"

    // printing the contents of the list
    println(mutableList)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Set
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;It is a collection of unordered elements which are unique. It does not support duplicate elements.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
    val setList = setOf("apple", "banana", "cherry")
    for (items in setList){
        println(items)
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;With mutable sets you can use methods like add or remove an element. Set preserve the order of the elements.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
   // create a mutable set
val mutableSet = mutableSetOf&amp;lt;Int&amp;gt;()

// add elements to the mutable set
mutableSet.add(1)
mutableSet.add(2)
mutableSet.add(3)

// remove an element from the mutable set
mutableSet.remove(2)

// check if an element is in the mutable set
val containsOne = mutableSet.contains(1)

// iterate over the mutable set
for (element in mutableSet) {
    println(element)
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Map
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Map keys are unique and hold only one value for each key. Each key maps to exactly one value.&lt;/li&gt;
&lt;li&gt;Maps are used to store logical connections between two objects. The values in a  map can be duplicate with unique keys.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
    // create an immutable map
val immutableMap = mapOf(
    "apple" to 1,
    "banana" to 2,
    "orange" to 3,
    "pear" to 4,
    "grape" to 5
)

// access values in the map
val bananaValue = immutableMap["banana"]

// add a new element to the map
val newMap = immutableMap + ("kiwi" to 6)

// remove an element from the map
val removedMap = immutableMap - "pear"

// iterate over the map using restructuring
for ((key, value) in immutableMap) {
    println("$key -&amp;gt; $value")
 }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Maps do not allow duplicates so when you add a new association, it removes the old one.&lt;/li&gt;
&lt;li&gt;You can remove certain elements from a map using the minus sign.&lt;/li&gt;
&lt;li&gt;Kotlin supports the restructuring of a map in a for loop.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
    // Create a mutable map
    val myMap = mutableMapOf&amp;lt;String, Int&amp;gt;()

    // Add items to the map
    myMap["apple"] = 3
    myMap["banana"] = 5
    myMap["orange"] = 2

    // Print the map
    println("My map: $myMap")

    // Update an item in the map
    myMap["banana"] = 6

    // Print the updated map
    println("My updated map: $myMap")

    // Remove an item from the map
    myMap.remove("orange")

    // Print the updated map
    println("My final map: $myMap")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;You can add new associations to a map using the bracket and assignment. In addition, we can also remove an association by using the remove method.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Exploring Kotlin's Abstract Classes and Specialized Class Types: A Guide to Object-Oriented Programming Concepts.</title>
      <dc:creator>Daniel Brian</dc:creator>
      <pubDate>Fri, 21 Apr 2023 21:53:35 +0000</pubDate>
      <link>https://dev.to/dbriane208/exploring-kotlins-abstract-classes-and-specialized-class-types-a-guide-to-object-oriented-programming-concepts-2hpl</link>
      <guid>https://dev.to/dbriane208/exploring-kotlins-abstract-classes-and-specialized-class-types-a-guide-to-object-oriented-programming-concepts-2hpl</guid>
      <description>&lt;p&gt;In this article, we are going to look at two concepts that are crucial in Modern Android development.&lt;br&gt;
By the end of this article, Our aim will be to dive into:&lt;br&gt;
&lt;em&gt;1. Abstract classes&lt;/em&gt;&lt;br&gt;
&lt;em&gt;2. Special kinds of classes in Kotlin&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  I. Abstract Classes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Abstract classes can be thought of as a hybrid of an open class and an interface.&lt;/li&gt;
&lt;li&gt;An abstract class is declared using the abstract keyword in front of the class.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;abstract&lt;/code&gt; &lt;code&gt;class&lt;/code&gt; &lt;code&gt;className&lt;/code&gt; &lt;code&gt;{}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Efhu3hJ7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qtzgslk294vm6pwgs3tl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Efhu3hJ7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qtzgslk294vm6pwgs3tl.png" alt="Image" width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Abstract classes can contain both abstract and non-abstract member properties in an abstract class. These properties are marked with the abstract modifier and they do not have a body as shown below.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract class className(val x : String) //non-abstract property
 {
    abstract var y : Int //Abstract property
    abstract fun method () //Abstract property
    fun method () //non-abstract method property
                 {
    println("Non abstract function")
                  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Abstract classes cannot be used to create objects. However, you can inherit subclasses from them but they need to be overridden.&lt;/li&gt;
&lt;li&gt;The key advantage of abstract classes is that they can have non-open methods and non-abstract properties.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract class Employee (val name : String,val experience : Int){
    //abstract property
    abstract var salary : Double 
    abstract fun dateOfBirth(date : String)
    //non-abstract property
    fun employeeDetails() {
        println("Name of the employee : $name")
        println("Experience in years : $experience")
        println("Annual salary : $salary")
    }
}
//derived class
class Engineer (name: String, experience: Int): Employee(name, experience) {
    override var salary = 5000.00
    override fun dateOfBirth(date : String){
        println("Date of Birth is: $date")
    }
}
fun main () {
    val eng = Engineer("Praveen",2)
    eng.employeeDetails()
    eng.dateOfBirth("02 December 1994")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Abstract classes are mainly used when you want to specify a set of generic operations for multiple classes. An abstract member of the abstract class can be overridden in all the derived classes.&lt;/li&gt;
&lt;li&gt;In the below class we override the cal function in three derived classes of the calculator.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract class Calculator {
    abstract fun cal (firstNum : Int, secondNum : Int): Int
}
//Addition of two numbers
class Add : Calculator () {
    override fun cal (firstNum : Int, secondNum : Int) : Int{
        return firstNum + secondNum
    }
}
//Division of two numbers
class Divide : Calculator () {
    override fun cal (firstNum : Int, secondNum : Int) : Int{
        return firstNum / secondNum
    }
}
//Multiplication of two numbers
class Multiply : Calculator () {
    override fun cal (firstNum : Int, secondNum : Int) : Int{
        return firstNum * secondNum
    }
}
//Subtraction of two numbers
class Subtract : Calculator () {
    override fun cal (firstNum : Int, secondNum : Int) : Int{
        return firstNum - secondNum
    }
}

fun main () {
    var add : Calculator = Add()
    var add1 = add.cal(4,3)
    println("Addition of two numbers $add1")

    var subtract : Calculator = Subtract()
    var add2 = subtract.cal(4,3)
    println("Subtraction of two numbers $add2")

    var multiply : Calculator = Multiply()
    var add3 = multiply.cal(4,3)
    println("Multiplication of two numbers $add3")

    var divide : Calculator = Divide()
    var add4 = divide.cal(24,3)
    println("Division of two numbers $add4")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;In kotlin, we can override the non-abstract open member function of the open class using the &lt;code&gt;override keyword&lt;/code&gt; followed by an abstract in the abstract class.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;open class vertebrates {
     open fun Backbone () {
        println("All vertebrates have a backbone")
    }
}

abstract class Animal : vertebrates () {
    override abstract fun Backbone ()
}   

class Birds : Animal () {
    override fun Backbone () {
        println("Birds have a backbone")
    }
}

fun main () {
    val animals = vertebrates ()
    animals.Backbone()
    val birds = Birds()
    birds.Backbone()

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  II. Special Kind of Classes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;There are different classes each with a dedicated purpose. These classes include:&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Data classes&lt;/li&gt;
&lt;li&gt;Enum classes&lt;/li&gt;
&lt;li&gt;Exception classes&lt;/li&gt;
&lt;li&gt;Sealed classes&lt;/li&gt;
&lt;li&gt;Annotation classes&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  1. Data classes
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Data classes are a special kind of class dedicated to serving as a holder of data. They help to compare, display, read, and modify this data more easily.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U2CaEFVi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/opgu7kj9rvqp15agc8ou.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U2CaEFVi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/opgu7kj9rvqp15agc8ou.jpg" alt="Image" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basic values like strings can be compared using the double equality sign.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class superCars (val name : String,val year : Int)
fun main () {
    var car1 = superCars("volvo",2020)
    var car2 = superCars("BMW" ,2021)
    var car3 = superCars("volvo",2020)
    var car4 = superCars("Benz",2019)

    println(car1 == car2)//false
    println(car1 == car1)//true
    println(car3 == car4)//false
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;The result is true if the values are alike and false if the values vary.&lt;/li&gt;
&lt;li&gt;When we use the dot syntax in our main function to call the properties of the class as shown below.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class superCars (val name : String,val Modelyear : Int)
fun main () {
    var car1 = superCars("volvo",2020)
    var car2 = superCars("BMW" ,2021)
    var car3 = superCars("volvo",2020)
    var car4 = superCars("Benz",2019)

    println(car1.name)
    println(car1.Modelyear)

    println(car4.name)
    println(car4.Modelyear) 

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output of the code will &lt;code&gt;volvo&lt;/code&gt; &lt;code&gt;2020&lt;/code&gt; and &lt;code&gt;Benz&lt;/code&gt; &lt;code&gt;2019&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When we call the instances of our class without specifying the keyword data, the output gives the memory location of where the instance is stored in the class.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class superCars (val name : String,val Modelyear : Int)
fun main () {
    var car1 = superCars("volvo",2020)
    var car2 = superCars("BMW" ,2021)
    var car3 = superCars("volvo",2020)
    var car4 = superCars("Benz",2019)

    println(car1)//superCars@37f8bb67
    println(car2)//superCars@439f5b3d
           }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output of the code above is &lt;code&gt;superCars@37f8bb67&lt;/code&gt; for car1 and &lt;code&gt;superCars@439f5b3d&lt;/code&gt; for car2 respectively.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When we specialize the &lt;code&gt;keyword data&lt;/code&gt; before class the output of the code changes. This is because the behavior of equality has changed.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;data class superCars (val name : String,val Modelyear : Int)
fun main () {
    var car1 = superCars("volvo",2020)
    var car2 = superCars("BMW" ,2021)
    var car3 = superCars("volvo",2020)
    var car4 = superCars("Benz",2019)
println(car1)
println(car2)
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Data classes have a &lt;code&gt;copy method&lt;/code&gt; that creates a copy of an object. It allows you to specify what modifications you would like to introduce to an object.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;data class Person(val firstName: String, val familyName:String) {
var age = 0
}
fun main() {

val person1 = Person("John", "Doe").apply { age = 25 }
val(firstName,familyName) = person1

println(person1.copy(familyName = "Maye"))
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;You use data modifiers for classes that are used to represent a bundle of data.&lt;/li&gt;
&lt;/ul&gt;
&lt;h5&gt;
  
  
  Pair and Triple
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;This is a data class with two constructor properties, you don't need to define it, as it is distributed with Kotlin.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pair&lt;/strong&gt; is used to keep two values on properties first, and second.&lt;/li&gt;
&lt;li&gt;You can use &lt;code&gt;first&lt;/code&gt; and &lt;code&gt;second&lt;/code&gt; properties when working with pair and triple.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {

    val fruits = Pair ("orange","Banana")

    //Using the first property 
    println(fruits.first)

     //Using the second property 
    println(fruits.second)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;We can use &lt;code&gt;to function&lt;/code&gt; between two values using the pair property.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {

    val Pair = 10 to "A"

    //Using the first property 
    println(Pair.first)

     //Using the second property 
    println(Pair.second)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Triple&lt;/strong&gt; is used to keep three values on properties first, second, and third.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {

    val pair = Triple("Daniel",45, 'M')

    //Using the first property 
    println(pair.first)

     //Using the second property 
    println(pair.second)

    //Using the third property 
    println(pair.third)  
           }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;we can also get the same output using the below code
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {

    val pair = Triple("Daniel",45,'M')
    val(name,age,gender) = pair

    //Getting the first property 
    println(name)

     //Getting the second property 
    println(age)

    //Getting the third property 
    println(gender)  
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  2. Enum classes
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;An enum has its own specialized type, indicating that something has a number of possible values. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HUPR_LyD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t680aayqvm8msiq2g40p.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HUPR_LyD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t680aayqvm8msiq2g40p.jpg" alt="Image" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enums are defined by using the &lt;code&gt;enum keyword&lt;/code&gt; in front of a class.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;enum class days {
sunday,
monday,
tuesday,
wednesday,
thursday,
friday,
saturday
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Enum have a constructor. Their constants are instances of an enum class. The constants can be initialized by passing specific values to the primary constructor.&lt;/li&gt;
&lt;li&gt;we can access the colour of the ripe banana using an instance that we create in our main function.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;enum class bananas (val color : String) {
    ripe("yellow"),
    unripe("green")
}
fun main () {

   val colour = bananas.ripe.color
    println(colour)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Kotlin enum classes has some inbuilt properties and functions which can be used by a programmer.&lt;/li&gt;
&lt;li&gt;In properties we have &lt;code&gt;ordinal&lt;/code&gt; and &lt;code&gt;name&lt;/code&gt;. The &lt;code&gt;ordinal&lt;/code&gt; property stores the ordinal value of the constant, which is usually a zero-based index. The &lt;code&gt;name&lt;/code&gt; property stores the name of the constant.&lt;/li&gt;
&lt;li&gt;In methods we have &lt;code&gt;values&lt;/code&gt; and &lt;code&gt;valueOf&lt;/code&gt;. The &lt;code&gt;values&lt;/code&gt; property returns a list of all constants defined within the enum class.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;valueOf&lt;/code&gt; property returns the enum constant defined in enum, matching the input string. If the constant, is not present in the enum, then an illegalArgumentException is thrown.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;enum class HalfYear {
    January,
    February,
    March,
    April,
    May,
    June
}
fun main () {
    for(month in HalfYear.values()){
        println("${month.ordinal} = ${month.name}")
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;We can access the individual month from the class using the valueOf property in the main function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;println("${HalfYear.valueOf("April")}")&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enum classes can be combined with when expression. Since enum classes restrict the value a type can take, so when is used with the when expression and the definitions for all the constants provided, then the need for the else clause is completely eliminated.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;enum class Planets {
    Mercury,
    Venus,
    Earth,
    Mars,
    Jupiter,
    Saturn,
    Uranus
}

fun main() {
    for (planet in Planets.values()) {
        when (planet) {
            Planets.Mercury -&amp;gt; println("The Swift Planet")
            Planets.Venus -&amp;gt; println("The Morning and evening star")
            Planets.Earth -&amp;gt; println("The Goldilocks Planet")
            Planets.Mars -&amp;gt; println("The Red Planet")
            Planets.Jupiter -&amp;gt; println("The Gas giant Planet")
            Planets.Saturn -&amp;gt; println("The Ringed Planet")
            Planets.Uranus -&amp;gt; println("The Ice giant Planet")
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Enum constants also behave as anonymous classes by implementing their own functions along with overriding the abstract functions of the class.&lt;/li&gt;
&lt;li&gt;The most important thing is that each enum constant must be overridden.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;enum class seasons (var weather : String) {

    Summer ("hot") {
        override fun foo () {
            println("Hot days of the year")
        }
    },

     Winter ("cold") {
        override fun foo (){
            println("Cold days of the year")
        }
    },

     Rainny ("rain") {
        override fun foo (){
            println("Rainny days of the year")
        }
    };

 abstract fun foo ()
}

fun main () {
    seasons.Winter.foo()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;In enum classes functions are usuallly defined within the companion object so that they do not depend on specific instances of the class.&lt;/li&gt;
&lt;li&gt;However, they can be defined without companion objects also.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;enum class DAYS(val isWeekend: Boolean = false){
    SUNDAY(true),
    MONDAY,
    TUESDAY,
    WEDNESDAY,
    THURSDAY,
    FRIDAY,
    SATURDAY(true);

    companion object{
        fun today(obj: DAYS): Boolean {
            return obj.name.compareTo("SATURDAY") == 0 || obj.name.compareTo("SUNDAY") == 0
        }
    }
}

fun main(){
    for(day in DAYS.values()) {
        println("${day.ordinal} = ${day.name} and is weekend ${day.isWeekend}")
    }
    val today = DAYS.MONDAY;
    println("Is today a weekend ${DAYS.today(today)}")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  3. Exception classes
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Exceptions are the errors which comes at the runtime and disrupts your flow of execution of the program.&lt;/li&gt;
&lt;li&gt;We have two types of execution;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R_9jg_Z5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ekbz65dud9qor5vdrgc9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R_9jg_Z5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ekbz65dud9qor5vdrgc9.jpg" alt="Image" width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
i. &lt;strong&gt;Checked Exception&lt;/strong&gt; - these are exceptions that occur at the compile time eg IOException.&lt;br&gt;
ii. &lt;strong&gt;Unchecked Exception&lt;/strong&gt; - these are exceptions that occur at runtime eg OutOfBoundException. In kotlin we use unchecked exceptions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We have some keywords which help us to handle exceptions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;i. &lt;em&gt;&lt;strong&gt;Try&lt;/strong&gt;&lt;/em&gt; - It helps us to find the exceptions.&lt;br&gt;
 ii. &lt;em&gt;&lt;strong&gt;Throw&lt;/strong&gt;&lt;/em&gt; - If the exception is found it throws the exception.&lt;br&gt;
iii. &lt;em&gt;&lt;strong&gt;Catch&lt;/strong&gt;&lt;/em&gt; - After throwing it will catch the exception and &lt;br&gt;
             execute the body.&lt;br&gt;
iv. &lt;em&gt;&lt;strong&gt;Finally&lt;/strong&gt;&lt;/em&gt; - It will always execute  either we get &lt;br&gt;
             exception or not.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If the program exit by &lt;code&gt;exitProcess(int)&lt;/code&gt; or &lt;code&gt;absort()&lt;/code&gt;, then the &lt;code&gt;finally&lt;/code&gt; will not be executed.&lt;/li&gt;
&lt;li&gt;The syntax :
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try {
    // your code
    // may throw an exception
}
catch (ex : ExceptionName)
{
    // Exception handle code
}
finally
{
    //This will execute everytime
    //It will execute whether we find an exceptiion or not
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;We can use the above syntax to create an exception class to divide a number by zero.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {

 try {

 divide (10,0)

    }
catch (ex : Exception)
{
    println(ex.message)
  }
}

fun divide (a : Int, b : Int){

    if(b == 0)
    throw Exception("Divide by Zero")
    println("Division is :" +a /b)
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;We can add the finally block in our code above. In the below below finally is executed in both cases either exceptions occur or not.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; fun main()
   {
    try
    {
    divide(20, 10)
    }
    catch (ex : Exception)
    {
    println(ex.message)
    }
    finally
    {
    println("I'm executed")
    }

    // 2nd try block
    try
    {
    // throw an exception
    divide(10, 0)
    }
    catch (ex : Exception)
    {
    println(ex.message)
    }
    finally
    {
    println("I'm executed")
    }
}

fun divide(a : Int, b : Int)
{
    if (b == 0)
        throw Exception("Divide by zero")
    println("Division is :" + a / b)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  4. Sealed classes
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;A sealed class defines a set of subclasses within it. Sealed classes ensure type safety by restricting the types to be matched at compile-time rather than at runtime.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BYSP4KNr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lr04cuxaq7ys9mt3yxt3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BYSP4KNr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lr04cuxaq7ys9mt3yxt3.png" alt="Image" width="800" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The syntax declaration of sealed classes is as shown below :
&lt;code&gt;sealed class NameOfTheClass&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Sealed classes constructors are protected by default. Sealed class is implicitly abstract and hence it cannot be instantiated.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sealed class DemoClass
    fun main () {
        var InstanceDemo = Demo ()
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt; The above code would not run because of compile error as sealed classes cannot be instantiated.&lt;/li&gt;
&lt;li&gt;All subclasses of a sealed class must be defined within the same kotlin file.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sealed class School {
    class Public:School(){
        fun display(){
            println("They are funded by the government")
        }
    }
    class Private:School(){
        fun display(){
            println("They are funded by individuals")
        }
    }
}

fun main(){
    val obj = School.Public()
    obj.display()
    val obj1= School.Private()
    obj1.display()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt; You cannot define a subclass of a sealed class inside a subclass because the sealed class woukd not be visible.&lt;/li&gt;
&lt;li&gt;Sealed classes mostly uses when and eliminates the else clause.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// A sealed class with a string property
sealed class Fruit(val x : String)
{
    // Two subclasses of sealed class defined within
    class Apple : Fruit("Apple")
    class Mango : Fruit("Mango")
}

// A subclass defined outside the sealed class
class Pomegranate: Fruit("Pomegranate")

// A function to take in an object of type Fruit
// And to display an appropriate message depending on the type of Fruit
fun display(fruit: Fruit)
{
    when(fruit)
    {
        is Fruit.Apple -&amp;gt; println("${fruit.x} is good for iron")
        is Fruit.Mango -&amp;gt; println("${fruit.x} is delicious")
        is Pomegranate -&amp;gt; println("${fruit.x} is good for vitamin d")
    }
}
fun main()
{
    // Objects of different subclasses created
    val obj = Fruit.Apple()
    val obj1 = Fruit.Mango()
    val obj2 = Pomegranate()

    // Function called with different objects
    display(obj)
    display(obj1)
    display(obj2)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  5. Annotation classes
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Annotations allows the programmer to embed supplemental information into the source file. The information does not change the actions of the program.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ePn7ASjA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0lpxh1rqfy8br9tuy5fy.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ePn7ASjA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0lpxh1rqfy8br9tuy5fy.jpg" alt="Image" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Annotations contains compile-time constants parameters which include;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;em&gt;primitive types(Int,Long etc)&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;strings&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;enumerations&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;class&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;other annotations&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;arrays of the above-mentioned types&lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We can apply annotation by putting its name prefixed with the &lt;code&gt;@ symbol&lt;/code&gt; in front of a code element.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; `@Positive val i : Int`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;A parameter can be passed in parenthesis to an annotation similar to function call.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; `@Allowedlanguage("Kotlin")`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;When an annotation is passed as parameter in another annotation, then we should omit the @ symbol. Here we have passed Replacewith() annotation as parameter.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;` @Deprecated("This function is deprecated, use === instead", ReplaceWith("this === other"))`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;When an annotation parameter is a class object, we should add ::class to the class name as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Throws(IOException::class) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To declare an annotation, the class keyword is prefixed with the annotation keyword. &lt;/li&gt;
&lt;li&gt;By their nature, declarations of annotation cannot contain any code.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;While declaring our custom annotations, we should specify to which code elements they might apply and where they should be stored. &lt;br&gt;
The simplest annotation contains no parameters &lt;/p&gt;

&lt;p&gt;&lt;code&gt;annotation class MyClass&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;An annotation that requires parameter is much similar to a class with a primary constructor &lt;/p&gt;

&lt;p&gt;&lt;code&gt;annotation class Suffix(val s: String)&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We can also annotate the constructor of a class. It can be done by using the constructor keyword for constructor declaration and placing the annotation before it.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MyClass@Inject constructor(dependency: MyDependency) {  
//. . .   
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We can annotate the properties of class by adding an annotation to the properties.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Lang (
    @Allowedlanguages(["Java","Kotlin"]) val name: String)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Kotlin also provides certain in-built annotations, that are used to provide more attributes to user-defined annotations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;@Target&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This annotation specifies the places where the annotated annotation can be applied such as classes, functions, constructors, type parameters, etc.&lt;/li&gt;
&lt;li&gt;When an annotation is applied to the primary constructor for a class, the constructor keyword is specified before the constructor.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Target(AnnotationTarget.CONSTRUCTOR, AnnotationTarget.LOCAL_VARIABLE)
annotation class AnnotationDemo2

class ABC @AnnotationDemo2 constructor(val count:Int){
    fun display(){
        println("Constructor annotated")
        println("Count is $count")
    }
}
fun main(){
    val obj =  ABC(5)
    obj.display()
    @AnnotationDemo2 val message: String
    message = "Hello"
    println("Local parameter annotated")
    println(message)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;@Retention&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This annotation specifies the availability of the annotated annotation i.e whether the annotation remains in the source file, or it is available at runtime, etc.&lt;/li&gt;
&lt;li&gt;Its required parameter must be an instance of the AnnotationRetention enumeration that has the following elements: &lt;/li&gt;
&lt;li&gt;SOURCE&lt;/li&gt;
&lt;li&gt;BINARY&lt;/li&gt;
&lt;li&gt;RUNTIME
Example to demonstrate @Retention annotation:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Specifying an annotation with runtime policy
@Retention(AnnotationRetention.RUNTIME)
annotation class AnnotationDemo3

@AnnotationDemo3 fun main(){
    println("Main function annotated")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;@Repeatable&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This annotation allows an element to be annotated with the same annotation multiple times. &lt;/li&gt;
&lt;li&gt;As per the current version of Kotlin 1.3, this annotation can only be used with the Retention Policy set to SOURCE.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Repeatable
@Retention(AnnotationRetention.SOURCE)
annotation class AnnotationDemo4 (val value: Int)

@AnnotationDemo4(4)
@AnnotationDemo4(5)
fun main(){
    println("Repeatable Annotation applied on main")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💫💫Thank you for taking the time to read my article, I appreciate your interest and support. I hope you enjoyed😇😇🥳🥳&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GxzqokeO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f35qw3t6ygbn2ruyy73w.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GxzqokeO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f35qw3t6ygbn2ruyy73w.jpeg" alt="Image " width="270" height="187"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Mastering Kotlin's Object-Oriented Programming 101: Unleashing the Full Potential of Your Code.</title>
      <dc:creator>Daniel Brian</dc:creator>
      <pubDate>Mon, 10 Apr 2023 14:44:22 +0000</pubDate>
      <link>https://dev.to/dbriane208/mastering-kotlins-object-oriented-programming-101-unleashing-the-full-potential-of-your-code-kbf</link>
      <guid>https://dev.to/dbriane208/mastering-kotlins-object-oriented-programming-101-unleashing-the-full-potential-of-your-code-kbf</guid>
      <description>&lt;p&gt;&lt;code&gt;Hellooooo🥳️🥳️🥳️I am glad🤗 that you have joined me again in this Android development journey🚀. I am glad that you have decide to join me again on this exciting journey as we explore the world of kotlin for Android development.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;🚀Kotlin is a programming language that's gaining popularity due to its ability to combine object-oriented and functional programming paradigms.&lt;br&gt;
🚀In this article, we'll explore Kotlin's object-oriented programming features and how they can be used to build efficient software applications. Whether you're a seasoned developer or just starting out, come with us on this journey to discover why Kotlin is worth learning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In this article, we are going to deep dive into one of the most important concepts of Kotlin:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;1. Functions&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;2. Classes and Objects&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;3. Interfaces and Inheritance&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;4. Class Inheritance&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Functions
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Functions help in writing the code once and re-using it in other parts of your code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcarnz2tjywdj3z40lci7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcarnz2tjywdj3z40lci7.png" alt="kt functions"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Functions are used to break the code into smaller, more understandable, and reusable parts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Variable scope and local functions&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Variables defined inside of a function are called local variables. They are visible only in their defined scope. &lt;/li&gt;
&lt;li&gt;These variables can be used in the functions they are defined.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun firstFunction () {
val name = "Google Office Zurich"
    println(name)
}
fun CarType () {
    val car = "Bently"
    firstFunction()
    println(car)
}
fun main () {
    CarType()
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of the above code after calling the function &lt;code&gt;CarType()&lt;/code&gt; in the main function is &lt;code&gt;Google Zurich Office&lt;/code&gt; and &lt;code&gt;Bently&lt;/code&gt;. &lt;code&gt;firstFunction&lt;/code&gt; cannot be used to access the type of car becaude it is mentioned outside its scope.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Local functions are defined inside other functions. They can only be used in their scope of the definition.&lt;/li&gt;
&lt;li&gt;Top-level functions do not have such limitations they can be used everywhere even in functions defined earlier in a file.&lt;/li&gt;
&lt;li&gt;Below is an example of a top-level function
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun calculateCircleArea(radius: Double): Double {
    return Math.PI * radius * radius
}
fun main () {
val area = calculateCircleArea(2.0)
println("The area of the circle is $area")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of the above code is &lt;code&gt;12.566370614359172&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Functions with Parameters and result&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Parameters&lt;/code&gt; are named variables that is defined as part of a function. They are specified using parenthesis after the function name.&lt;/li&gt;
&lt;li&gt;When you declare or write a function and you use as a parameter, when you want to call this function, you must supply the parameter with a value. The value supplied for this parameter is called &lt;code&gt;Argument&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun calculateCircleArea(radius: Double): Double {
    return Math.PI * radius * radius
}
fun main () {
val area = calculateCircleArea(2.0)
println("The area of the circle is $area")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code sample the name &lt;code&gt;radius: Double&lt;/code&gt; is the parameter of the function &lt;code&gt;calculateCircleArea&lt;/code&gt;. The Argument supplied for the &lt;code&gt;calculateCircleArea&lt;/code&gt; function is &lt;code&gt;2.0&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An &lt;em&gt;absolete function&lt;/em&gt; is a function that returns an integer value without a sign so this doesn't change positive values, but it returns all negative values into positive.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun absolete(value : Int) :Int {
    if(value &amp;gt;= 0){
        return value
    }else{
        return -value
    }
}
fun main () {
    println(absolete(123)) // output 123 
    println(absolete(-1)) // output 1
    println(absolete(9)) // output 9
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Single expression functions&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In Kotlin, there is a special syntax for single expressions functions. Instead of braces with the body, you can use the equality sign, which specifies what should be returned.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun triangleArea(width : Double, height : Double) : Double = width * height/2
fun main () {
val area = triangleArea(12.0,56.0)
println(area)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The ouput of the above code is &lt;code&gt;336.0&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Recursion&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;These are functions that call themselves.&lt;/li&gt;
&lt;li&gt;A factorial function is an example of a recursive function. To implement such a function we might define a variable called &lt;code&gt;accumulator&lt;/code&gt; with an initial value of 1, which will be used to accumulate all the numbers. Then, for each number from 1 to the number you calculate the factorial, you will modify the value by multiplying it by the next number.&lt;/li&gt;
&lt;li&gt;After that, all you need to do is to return the accumulator variable.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun factorial(number : Int) : Int {
    var accumulator = 1
    for(i in 1..number){
       accumulator = accumulator * i 
    }
   return accumulator 
}
fun main () {
    println(factorial(5))
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Default and Named arguments&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Default arguments that need not specify explicitly while calling a function. When a function is called without passing arguments the parameters become the default arguments.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun student(name: String="Praveen", standard: String="IX" , roll_no: Int=11) {  
    println("Name of the student is: $name")
    println("Standard of the student is: $standard")
    println("Roll no of the student is: $roll_no")
}
fun main() {
    student()        
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of the above code is &lt;code&gt;Praveen&lt;/code&gt; &lt;code&gt;IX&lt;/code&gt; &lt;code&gt;11&lt;/code&gt; since we have not passed any arguments in our student function in the main function.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Named arguments allows to specify arguments while calling a function. With named arguments, you can pass arguments to a function in any order, as long as you specify the name of each argument.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun student( name: String="Praveen", standard: String="IX" , roll_no: Int=11 ) {
    println("Name of the student is: $name")
    println("Standard of the student is: $standard")
    println("Roll no of the student is: $roll_no")
}

fun main(args: Array&amp;lt;String&amp;gt;) {
    val name_of_student = "Gaurav"
    val standard_of_student = "VIII"
    val roll_no_of_student = 25
student(name=name_of_student,roll_no=roll_no_of_student)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For this code to work we pass arguments with names as defined in function.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Classes and Objects
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;code&gt;class&lt;/code&gt; is like a template that defines what an object looks like and how it can be used.&lt;/li&gt;
&lt;li&gt;It specifies how the objects should be created and which methods and properties it consists of.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd4yrzu8imapbmsyvmfbb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd4yrzu8imapbmsyvmfbb.png" alt="Image kt obj"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An &lt;code&gt;object&lt;/code&gt; is an instance of a class. A type represents a category of objects eg an integer represents all integers.&lt;/li&gt;
&lt;li&gt;To define a class in kotlin you use the keyword &lt;code&gt;class&lt;/code&gt; and specify the &lt;code&gt;name&lt;/code&gt; of the class.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Car {
    var brand = ""
    var model = ""
    var year = 0
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;You will realize that when we use curly braces to define a class we must initialize the objects, we cannot leave them open but when we use brackets we don't have to initialize the class we only specify the type.&lt;/li&gt;
&lt;li&gt;When we use brackets to enclose the class we should use commas to separate different properties inside it.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Car (
   var brand : String,
    var model : String,
    var year : Int
         )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Creating an object&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We can create an object of the &lt;code&gt;Car&lt;/code&gt; class above called &lt;code&gt;objCar&lt;/code&gt;, and then we can access the properties of objCar by using the dot &lt;code&gt;syntax (.)&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Car (
   var brand : String,
    var model : String,
    var year : Int
         )
 fun main () {
     var objCar = Car(
     "Bently",
     "Mustang",
     2013
     )
      println( objCar.brand)
     println( objCar.model)
     println( objCar.year)
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;When we use the brackets to define the class we use the primary constructor property when specifying a value for a regular property.&lt;/li&gt;
&lt;li&gt;When we use the curly braces we define the properties of the class not as parameters as shown below.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Car {
    var brand : String = ""
    var model : String = ""
    var year : Int = 0
         }
 fun main () {
     var objCar = Car()

     objCar.brand = "Bently"
     objCar.model = "Mustang"
     objCar.year = 2013

     println( objCar.brand)
     println( objCar.model)
     println( objCar.year)
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We can also specify the property of a class inside a class body. First, we use curly brackets as shown below.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Car (
    var brand : String,
    var model : String
          )
{
    var ObjCar : String = "$brand($model)"
}
 fun main () {
     var CarType = Car( brand = "Bently", model = "Mustang")
     println(CarType.ObjCar)
            }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of the above code will be &lt;code&gt;Bently(Mustang)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Methods&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A method is a function associated with a class, for example a defined class. They are defined inside the class body. In other words, they are defined inside the curly braces.&lt;/li&gt;
&lt;li&gt;Methods have direct access to all the properties of a class as shown below
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Subject (val name : String)

{
    fun Teacher (course : String, grade : String) : Teaches {
        println("$name teaches $course well I got $grade grade")
        return Teaches(course,grade)
                             }
    fun TeachesWell (course : String, grade : String){
        println("Congratulations")
    //Methods can be used to call other methods    
        Teacher(course, grade)
               }
}

class Teaches (
    var course : String,
    var grade : String
              )

fun main () {
    val read = Subject ("Daniel")
    read.TeachesWell(course = "Physics", grade = "A")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The output of the above code is&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;Congratulations&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Daniel teaches Physics well I got A grade&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In order to call a method, you need to have an object. For instance, when you have a &lt;code&gt;class Dog&lt;/code&gt; with a &lt;code&gt;method feed&lt;/code&gt;, to call this method outside the class, you need to first have an object of type Dog.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Dog (var name: String)
{
    var hunger : Int = 62

    fun feed (){
        println("Feeding $name")
        hunger = 0
    }

}

fun main () {
    var dog = Dog ("Rex")
    dog.feed()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of the above code is &lt;code&gt;feeding Rex&lt;/code&gt;. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inside the method, we use the &lt;code&gt;name&lt;/code&gt;and &lt;code&gt;hunger&lt;/code&gt; properties from the object that was used during the call. In a way, It is similar to defining &lt;code&gt;feed&lt;/code&gt; as a top-level function and parsing &lt;code&gt;Dog&lt;/code&gt; as an argument.&lt;/li&gt;
&lt;li&gt;In methods, you can access members implicitly. For instance in the below code use just &lt;code&gt;name&lt;/code&gt;, not &lt;code&gt;dog.name&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Dog (var name : String)
{
    var hunger : Int = 62
}

fun feed (dog : Dog){
     println("Feeding ${dog.name}")
     dog.hunger = 0
    }

fun main () {
    var dog = Dog ("Rex")
    feed(dog)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of the above code is &lt;code&gt;feeding Rex&lt;/code&gt;. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When you call methods, the object of their class is passed to their class body. This is called a &lt;strong&gt;receiver&lt;/strong&gt;. &lt;/li&gt;
&lt;li&gt;A receiver can be accessed using &lt;code&gt;this keyword&lt;/code&gt; also known as &lt;em&gt;reciever reference&lt;/em&gt;. So if you want to reference an object used to call a method inside this method, use &lt;code&gt;this keyword&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Dog(var name : String){
    var hunger = 62

    fun feed (){
      //Receiver
      var currentDog : Dog = this
        println("Feeding ${currentDog.name}")
        currentDog.hunger = 0
    }
}

fun main (){
    var dog = Dog("Rex")
    dog.feed()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;when you call methods or properties inside methods, such as when  you call name, you are calling methods or properties in the receiver, so its like calling &lt;code&gt;this.name&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Dog(var name : String){
    var hunger = 62

    fun feed (){
      //Receiver
      //var currentDog : Dog = this
        println("Feeding ${this.name}")
        this.hunger = 0
    }
}

fun main (){
    var dog = Dog("Rex")
    dog.feed()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;this&lt;/code&gt; keyword can be used to call methods or properties and sometimes it can be used explicitly.&lt;/li&gt;
&lt;li&gt;One example might be when you have a method parameter and class property with the same name. Like in the below class, there is a property &lt;code&gt;name&lt;/code&gt; and a method &lt;code&gt;changeName&lt;/code&gt; with a parameter &lt;code&gt;name&lt;/code&gt;. So if you see &lt;code&gt;name&lt;/code&gt; inside the class, you will have a value of the parameter. To access the property use &lt;code&gt;this.name&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class User (var name : String) {
    fun changeName (name : String){
        println("Change name from ${this.name} to $name")
        this.name = name
    }
}

fun main () {
    val user = User("Alpha")
    user.changeName("Beta")
    println(user.name)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Interfaces and Inheritance
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;An &lt;em&gt;interface&lt;/em&gt; is a collection of abstract methods and properties that define a common contract for classes that implement the interface.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fktgsbf2tgpc9fb82i1pg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fktgsbf2tgpc9fb82i1pg.png" alt="Image kt interface"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Interfaces cannot be instantiated directly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Creating interfaces&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Interface is defined by the keyword &lt;code&gt;Interface&lt;/code&gt; followed by the name of the interface and curly braces.&lt;/li&gt;
&lt;li&gt;Functions and properties of the interface reside inside the curly braces.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface Fruit {
  fun  BitterFruit()
  fun SweetFruit()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Implementing Interfaces&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Interfaces are implemented by classes or objects.&lt;/li&gt;
&lt;li&gt;Classes or objects implementing the interface should be followed by a colon and the name of the interface which is to be implemented. eg
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface Fruit {

   fun BitterFruit()
   fun SweetFruit()

}

class TypeFruit: Fruit {

    override fun BitterFruit() {
        println("Lemon is a bitter fruit")
    }
    override fun SweetFruit() {
        println("Apple is sweet fruit ")
    }
}

fun main () {
    val fruit = TypeFruit ()

    fruit.BitterFruit()
    fruit.SweetFruit()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We are using the keyword override in our functions because they were specified in the interface.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Default values and Default methods&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Methods can have default values as parameters which are used when no value is passed during the function call.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface Sum {
    // 10 and 20 are default values
    fun add( firstNum : Int = 10,secondNum : Int = 20)
    fun output () {
        println("This is an example of an addition of numbers")
    }
}
class Addition (): Sum {
    override fun add (firstNum : Int, secondNum : Int){
        val SumOfNumbers = firstNum + secondNum
        println("The sum of $firstNum and $secondNum is $SumOfNumbers")
    }
    override fun output () {
        super.output()
        println("Sum of two numbers")
    } 
}
fun main () {
    val addition = Addition()
    //We are overriding the default values with new arguments
    addition.add(30,30)
    addition.output()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output is &lt;code&gt;60&lt;/code&gt; and not &lt;code&gt;30&lt;/code&gt;. In our main function, we have changed our default values to hold &lt;code&gt;30&lt;/code&gt; in both firstNum and secondNum.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The super keyword is used to call the default implementation of print specified in the inheritance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Inheritance properties in interface&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Interfaces can contain properties that cannot be instantiated hence no backfield to hold their values. The fields in the interface are either left abstract or are provided an implementation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fum78mxpu7bto0xncmi70.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fum78mxpu7bto0xncmi70.png" alt="Image inheritance"&gt;&lt;/a&gt;&lt;br&gt;
-Interfaces can also inherit others interfaces adding its own properties and methods in both the interfaces.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An interface can inherit more than interface.&lt;/li&gt;
&lt;li&gt;The value of &lt;code&gt;length&lt;/code&gt; and &lt;code&gt;breadth&lt;/code&gt; are the properties of the interface dimensions.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface Dimensions {
    val length : Double
    val breadth : Double
}
interface CalculateParameters : Dimensions {
    fun area ()
    fun perimeter ()
}
class Calculations () : CalculateParameters {
    override val length : Double
    get() = 40.0
    override val breadth : Double
    get() = 60.0

    override fun area () {
        println("The area is ${length * breadth}")
    }
    override fun perimeter () {
        println("The perimeter is ${2*(length + breadth)}")
    }
}
fun main () {
    var obj = Calculations ()
    // The area is 2400.0
    obj.area()
    // The perimeter is 200.0
    obj.perimeter()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Kotlin has multiple interface implementations. A class can implement more than one interface provided that it has a definition for all the numbers of the interface.&lt;/li&gt;
&lt;li&gt;A class can only inherit one class.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface Dimensions {
    val length : Double
    val breadth : Double
}
interface CalculateParameters {
    fun area ()
    fun perimeter ()
}
class Calculations () : Dimensions, CalculateParameters {
    override val length : Double
    get() = 40.0
    override val breadth : Double
    get() = 60.0

    override fun area () {
        println("The area is ${length * breadth}")
    }
    override fun perimeter () {
        println("The perimeter is ${2*(length + breadth)}")
    }
}
fun main () {
    var obj = Calculations ()
    // The area is 2400.0
    obj.area()
    // The perimeter is 200.0
    obj.perimeter()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Class Inheritance
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;During class inheritance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv5osgh14380hiy78fpzf.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv5osgh14380hiy78fpzf.jpg" alt="Image kt inh"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;1.  One must define a class that extends from another class.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;2.  The class to be inherited must be open.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;3.  One must introduce the same modifications to the behavior.&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When one class inherits from another, it takes all the previous class methods and properties. It becomes its subclass, which means that it can be used wherever its parent is expected.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;open class Klass () {
    fun students () {
        println("There are 50 students in the class")
    }
    fun subject () {
        println("The class takes chemistry as a compulsory subject")
    }
   }
class Teacher () : Klass() {
    fun teaches () {
        println("The teacher teaches all the 50 students chemistry")
    }

}
fun main () {
    val teach = Teacher ()
    teach.students()
    teach.subject()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;class Klass is the super or the primary class while class Teacher is the subclass or the secondary class.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Visibility Modifiers in Classes&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To make encapsulation possible you need to hide some properties and methods so that they can be used inside of a class but not outside of it. To do that you use the private visibility modifier before a function or a property you want to hide.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Private&lt;/strong&gt; means that a particular property or a function can only be used in that class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Protected&lt;/strong&gt; means that a property can be used inside classes that are open or abstract.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Internal&lt;/strong&gt; means that an element will be visible throughout the same module. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;💫💫Thank you for taking the time to read my article, I appreciate your interest and support.😇😇🥳🥳&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F45oa31ygulwblc2vzmhp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F45oa31ygulwblc2vzmhp.jpg" alt="Thank you"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>beginners</category>
      <category>mobile</category>
    </item>
    <item>
      <title>MODULE ONE: INTRODUCTION TO KOTLIN PROGRAMMING 101.</title>
      <dc:creator>Daniel Brian</dc:creator>
      <pubDate>Sun, 26 Mar 2023 19:54:56 +0000</pubDate>
      <link>https://dev.to/dbriane208/module-one-introduction-to-kotlin-programming-101-3ed0</link>
      <guid>https://dev.to/dbriane208/module-one-introduction-to-kotlin-programming-101-3ed0</guid>
      <description>&lt;p&gt;Hellooooo🥳️🥳️🥳️I am glad🤗 that you have joined me again in this Android development journey🚀. I am glad that you have decide to join me again on this exciting journey  as we explore the world of kotlin for Android development. Here is one of the three articles we will be interacting with🥳️🥳️.Do not forget to 👍like, comment👍 and share with your friends👨‍👨‍👦‍👦🥳️.&lt;/p&gt;

&lt;p&gt;Before we start here is a great saying by the Kotlin inventor:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;"I wanted a better language than Java, so I started experimenting with one which could run on a JVM but which would be less syntactically verbose, more expressive, and which would remove some of the error-proneness of the Java type system. The result of this experimentation was the Kotlin programming language."&lt;/code&gt;&lt;/strong&gt; &lt;br&gt;
&lt;strong&gt;&lt;code&gt;JetBrains co-founder and Kotlin inventor, Andrey Breslav.&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Programming&lt;/code&gt; is a fascinating scale that allows you to talk to computers.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;program&lt;/code&gt; is simply a set of instructions created using a programming language that a computer must follow.&lt;/li&gt;
&lt;li&gt;A programming language is a little like a bridge that we use to talk to computers and people.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Programming languages are classified into levels;&lt;/p&gt;

&lt;p&gt;i. &lt;em&gt;&lt;strong&gt;Low-level programming language&lt;/strong&gt;&lt;/em&gt;: This is a machine language with zeros and ones. It is clear to be understood by a computer CPU.&lt;/p&gt;

&lt;p&gt;ii. &lt;em&gt;&lt;strong&gt;High-level programming language&lt;/strong&gt;&lt;/em&gt;: This language needs to be interpreted that is converted to binary code that a CPU will be able to work with.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Kotlin is one of the high-level languages that need to be interpreted. Since its announcement by Google as the official language for developing android native apps, Kotlin has gained and continues to gain popularity in the field over the previously used Java programming language. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcwb014r3lyqzn2os3wbf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcwb014r3lyqzn2os3wbf.png" alt="Imagekvj"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;&lt;strong&gt;Some of the reasons Kotlin is preferred over Java include :&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
1.It is concise and standardized hence low code errors.&lt;br&gt;
2.Easier to maintain complex projects due to low code.&lt;br&gt;
3.It is compatible with java hence easy to convert java&lt;br&gt;
code to Kotlin.&lt;br&gt;
4.Kotlin handles errors that crash Android apps better&lt;br&gt;
than java.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In addition, you might be wondering what else Kotlin could do apart from developing Android apps. Here are some of the fields Kotlin is gaining popularity :&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Back-end web development&lt;/strong&gt;: modern features that have been &lt;br&gt;
       added to kotlin have enabled the language to be used on &lt;br&gt;
       the server side since applications can scale quickly. &lt;br&gt;
       Kotlin also uses Spring frameworks used in java which &lt;br&gt;
       makes it easy for developers to work well with it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Freygotmve3a325y3hq29.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Freygotmve3a325y3hq29.png" alt="kotr"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Full-stack web development&lt;/strong&gt;: Kotlin/JS allows developers to &lt;br&gt;
       access powerful browsers and web APIs in a type-safe &lt;br&gt;
       fashion. They can write front-end code in the same language &lt;br&gt;
       that they used for back-end code, and it’ll be compiled &lt;br&gt;
       into JavaScript to run in the browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftwc2rd431uur4akq2c8f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftwc2rd431uur4akq2c8f.png" alt="full stack"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Data Science&lt;/strong&gt;: Data Scientists have always used Java to 
   crunch numbers, detect trends, and make predictions — so it 
   only makes sense that Kotlin would find a home in data 
   science as well.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftuh7o3wbi45rgmzhuv7o.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftuh7o3wbi45rgmzhuv7o.jpg" alt="data"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Multi-platform mobile development&lt;/strong&gt;: In the coming future 
   one Kotlin code base would be used to compile and run apps 
   not only in Android but also in iPhones and Apple watches. 
   This project is currently in the alpha testing stage.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx21u4fyrpgjwva5uq3ck.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx21u4fyrpgjwva5uq3ck.png" alt="km icon"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;In this module, we will cover the following objectives :&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Variables, values, and type in kotlin&lt;/li&gt;
&lt;li&gt;Numbers in kotlin&lt;/li&gt;
&lt;li&gt;Using texts in kotlin&lt;/li&gt;
&lt;li&gt;Boolean values and Operations&lt;/li&gt;
&lt;li&gt;Conditional statements in Kotlin.&lt;/li&gt;
&lt;li&gt;Loops in Kotlin&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  1.Variables, values, and type in kotlin
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Variables are containers used to store data values in Kotlin. Variables can change the values that it stores. They are abbreviated as &lt;code&gt;var&lt;/code&gt;. Variables can be reassigned.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main (){
    //Ok! val cannot be reassigned
   var name = "John"
   name = "Sharon"
              }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Val&lt;/code&gt; is an abbreviation of value. You can use this modifier to specialize variables that cannot be changed. In other words code will not start if you try to assign new value.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main (){
    //Error! val cannot be reassigned
   val name = "John"
   name = "Sharon"
              }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Values are grouped into types:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;i. &lt;em&gt;Strings&lt;/em&gt; - represent values in texts. eg mountain&lt;br&gt;
ii. &lt;em&gt;Integer&lt;/em&gt; - represents real numbers. eg 56&lt;br&gt;
iii. &lt;em&gt;Double&lt;/em&gt; - represents numbers with decimal places. eg 45.0&lt;br&gt;
iv. &lt;em&gt;Boolean&lt;/em&gt; - represents a true or a false value. eg 5 == 6 is false&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Some of the reasons we explicitly use &lt;code&gt;val&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Val is used for readability such that the reader can understand the written code.&lt;/li&gt;
&lt;li&gt;With val it is enough to view its declaration to know which value it is.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Val minimizes the number of unnecessary variable changes which increases the readability of your code.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     fun main () {
     val age : String = "" + 42 + ""
       }
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;/ol&gt;

&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;There are a few reasons to use the explicit variable type. One is readability. Sometimes the right side of the assignment might be complicated and specifying a type to makes it easier to understand your code.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
var x : Any = "ABC"
println(x) // ABC
x = 123
println(X) // 123
x = true
println(x) // true
           }
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;&lt;p&gt;One of the reasons you specify type is when you need a value to include multiple subtypes.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;For instance &lt;code&gt;Any&lt;/code&gt; is a data type that includes all other types. So &lt;code&gt;String&lt;/code&gt;, &lt;code&gt;Int&lt;/code&gt;, and &lt;code&gt;Boolean&lt;/code&gt; are all subtypes of Any. With the type of Any, you can assign it any value you've learned about so far.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Numbers in Kotlin
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;There are four basic types of operations used in kotlin which include :&lt;br&gt;
i.&lt;code&gt;Int&lt;/code&gt;&lt;br&gt;
ii. &lt;code&gt;Float&lt;/code&gt;&lt;br&gt;
iii.&lt;code&gt;Double&lt;/code&gt;&lt;br&gt;
iv. &lt;code&gt;Long&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Integer&lt;/strong&gt;: it represents real whole numbers that can either be positive or negative. We add a minus sign in front of an integer to make it negative. Integers have a limited size of over two billion.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Long&lt;/strong&gt;: represents a number type that can accommodate numbers over nine quintillions to create a long value. We add a suffix L after the number.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Double&lt;/strong&gt;: It contains a number that operates with a decimal part. It holds a number made up of two parts. It contains the integer part and a decimal. It can hold up to 15 to 16 decimal places. A double is more precise than a float. This is because a double occupies twice memory as an integer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Float&lt;/strong&gt;: It holds up to 7 to 8 decimal places. We create this number by using the suffix F after the number. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Kotlin can be used to can be used for basic math operations. eg&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; println(1+3*2) output = 7
 println((1+3)*2) output = 8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Parenthesis are used to override the normal math precedents to create a particular calculation.&lt;/li&gt;
&lt;li&gt;Transformational functions are used to transform one number type to another. We use the &lt;code&gt;to&lt;/code&gt; prefix and the type you want. eg
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; fun main () {
val num1 : Int = 10
val num2 : Long = num1.toLong()
val num3 : Double = num2.toDouble()
val num4 : String = num3.toString()
val num5 : Float = num3.toFloat()
println(num1)
println(num2)
println(num3)
println(num4)
println(num5)
              }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The output of the first print statement is 10&lt;/li&gt;
&lt;li&gt;The output of the second print statement is 10&lt;/li&gt;
&lt;li&gt;The output of the third print statement is 10.0&lt;/li&gt;
&lt;li&gt;The output of the fourth print statement is 10.0&lt;/li&gt;
&lt;li&gt;The output of the fifth print statement is 10.0&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;In kotlin, the remainder operation is represented by a modulus sign(%). It represents what would be left if you divide an integer by another integer.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; fun main () {
println(10%3)// 1
println(12%4)// 0
println(17%5)// 2
// The sign of the result is always the same as the sign of the left side.
println(-1%3) // -1
println(1%-3) // 1
println(-1%-3) // -1
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;When you carry out operations between;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;Integer&lt;/code&gt; and &lt;code&gt;Integer&lt;/code&gt;  the result will be an &lt;code&gt;Integer&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Integer&lt;/code&gt; and &lt;code&gt;Long&lt;/code&gt;  the result will be a &lt;code&gt;Long&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Decimal&lt;/code&gt; and &lt;code&gt;Integer&lt;/code&gt; or &lt;code&gt;Decimal&lt;/code&gt;  the result will be an &lt;br&gt;
   &lt;code&gt;Decimal&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Float&lt;/code&gt; and &lt;code&gt;Integer&lt;/code&gt;  the result will be an &lt;code&gt;Float&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Float&lt;/code&gt; and &lt;code&gt;Double&lt;/code&gt;  the result will be an &lt;code&gt;Double&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Division operation between two integers results into an integer. If the calculation results in a decimal part of this operation is lost.&lt;/li&gt;
&lt;li&gt;To ensure fractions are retained, transform one of the values to a double or float before the math operation.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; fun main () {
       val a = 5
       val b = 2
       println(a/b)
       println(a.toDouble()/b)
              }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;The output of the first print is 2&lt;/li&gt;
&lt;li&gt;The output of the second print is 2.5&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Augmented Assignment&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Variables defined with var can have their value changed.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
var num = 10
println(num)
//reassigning num
num = 20
println(num)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output of the first print is 10&lt;br&gt;
The output of the second print is 20&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We can also increase value through different operations. Instead of using &lt;code&gt;a = a + b&lt;/code&gt; we can use &lt;code&gt;a += b&lt;/code&gt;. This implies to all the other operations that we increment by using the operation sign next to an equals sign.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
var num = 10
num += 20
println(num)
num -= 5
println(num)
num *= 4
println(num)
num /= 50
println(num)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;The output of the first print is 30 because we are adding 10 to our initial value which was 20 resulting in 30.&lt;/li&gt;
&lt;li&gt;The output of the second print is 25 because we are subtracting 5 from the result of the above operation which was 30 resulting in 25.&lt;/li&gt;
&lt;li&gt;The output of the third print is 100 because we are multiplying 4 by the result of the above operation which was 25 resulting in 100.&lt;/li&gt;
&lt;li&gt;The output of the fourth print is 2 because we are dividing 50 by the result of the above operation which was 100 resulting in 2.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Prefix and postfix operation&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In Kotlin there are different ways to add and subtract. We can either use a postfix or a prefix to do an increment. In postfix, the execution is done after the operations are evaluated.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
var a = 5
var num = 6 + a++
println(num)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output will be &lt;code&gt;11&lt;/code&gt; because &lt;code&gt;num&lt;/code&gt; takes the value of &lt;code&gt;a&lt;/code&gt; and adds it before &lt;code&gt;a++&lt;/code&gt; increments &lt;code&gt;5&lt;/code&gt; to &lt;code&gt;6&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In Prefix operation works differently. The prefix operation is executed before the equation is evaluated.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
var a = 5
var num = 6 + ++a
println(num)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output will be &lt;code&gt;12&lt;/code&gt; because &lt;code&gt;a++&lt;/code&gt; takes the value of &lt;code&gt;a&lt;/code&gt; then add &lt;code&gt;1&lt;/code&gt; to it such that now &lt;code&gt;a++&lt;/code&gt;holds &lt;code&gt;6&lt;/code&gt; as a value which is added to&lt;code&gt;6&lt;/code&gt; stored in the variable &lt;code&gt;num&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  3. Using texts in Kotlin
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Char&lt;/code&gt; is an abbreviation of character. In kotlin character is defined by placing it inside a &lt;em&gt;set of single quotes&lt;/em&gt;.
&lt;code&gt;var mychar : Char = 'a'&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;In programming characters are represented by numbers because a computer understands binary codes which are made up of zeros and ones.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Unicode&lt;/code&gt;&lt;/strong&gt; is a special table that is used to map each character to a unique number. It supports 144,697 characters.&lt;/li&gt;
&lt;li&gt;A &lt;em&gt;string _is a sequence of characters. It can be empty or have one or more characters including spaces and commas. String value is specified through _double quotes&lt;/em&gt;. Strings are immutable.&lt;/li&gt;
&lt;li&gt;If your text contains multiple lines, it is also possible to define this in a string variable in kotlin by delimiting the text with tripple quotes.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
val myString = """Hello world! My name is Daniel Brian. 
I love android development with kotlin."""
println(myString)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output of the print statement is: &lt;br&gt;
&lt;code&gt;Hello world! My name is Daniel Brian. &lt;br&gt;
I love android development with kotlin.&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;String has built-in code which can be used to access the information about them such as the keyword &lt;strong&gt;&lt;code&gt;length&lt;/code&gt;&lt;/strong&gt;. The length keyword is used to access the number of characters in a string.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
val name = "Simpsonville"
println(name.length)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;The output of the print is 12 showing that the string Simpsonville has 12 characters.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;String template&lt;/em&gt; allows you to include a variable in a string. To do this you use a dollar sign in the variable name.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
val name = "Simpsonville"
val age = 20
println("My name is $name I am $age years old.")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output of the print statement is: &lt;code&gt;My name is Simpsonville I am 20 years old.&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When you use $(dollar sign) without brackets you only inline a variable value not the rest of an expression.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
val num1 = 50
val num2 = 20
println(" $num1 + $num2 = ${num1 + num2}")
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output of the print statement is &lt;code&gt;50 + 20 = {num1 + num2}&lt;/code&gt; but after we put the dollar sign the output changes to &lt;code&gt;50 + 20 = 70&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To convert a &lt;code&gt;Char&lt;/code&gt; to a &lt;code&gt;String&lt;/code&gt; using the &lt;code&gt;toString()&lt;/code&gt; function.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
val myChar = "H"
val myLongStrong = myChar.toString()
println(myLongStrong)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output is: H&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Appending to string&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To add additional text to the end of a string, we use the plus operator(+). This does not change the existing string variable but creates new string variable.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
val name1 = "Google!!"
val name2 = "I love " + name1
println(name2)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output of the code is &lt;code&gt;I love Google!!&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Searching Strings&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The string type has multiple functions for searching its content. We can search the first letters of a word or the last letters.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
val name = "Google"
val startWithGo = name.startsWith("Go")
val endWithMe = name.endWithMe("me")
println(startWithGo)
println(endWithMe)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output of the first println is &lt;code&gt;true&lt;/code&gt; because the name Google start with the character &lt;code&gt;Go&lt;/code&gt; else the output will be &lt;code&gt;false&lt;/code&gt;.&lt;br&gt;
The output of the second println is &lt;code&gt;false&lt;/code&gt; because the name Google doesn't end with the letters "me". It could be &lt;code&gt;true&lt;/code&gt;if the last letters indicated would be &lt;code&gt;le&lt;/code&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We can use &lt;code&gt;variable name.first()&lt;/code&gt; to get the first character of a variable or &lt;code&gt;variable name.last()&lt;/code&gt; to get the last character of a variable.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
val name = "Google"
val nameIsFirst = name.first()
val nameIsLast = name.last()
println(nameIsFirst)
println(nameIsLast)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output of the code will be &lt;strong&gt;&lt;code&gt;G&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;e&lt;/code&gt;&lt;/strong&gt; respectively.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Manipulating Strings&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We can use the uppercase and the lowercase methods to manipulate strings to capital letters and small letters.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
val name = "Google"
val nameIsFirst = name.uppercase()
val nameIsLast = name.lowercase()
println(nameIsFirst)
println(nameIsLast)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output of the first println is &lt;code&gt;GOOGLE&lt;/code&gt; while the output of the second println is &lt;code&gt;google&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We can also get the position of all the letters in string through the substring function.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
val name = "Google"
val nameIsLast = name.substring(1)
println(nameIsLast)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output of the code above is &lt;code&gt;oogle&lt;/code&gt; because the substring prints from the index referenced inside the function which is 1.&lt;/p&gt;
&lt;h2&gt;
  
  
  4. Boolean values and Operations
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Boolean has two possible values true and false and can be used to tell whether something is true or not.&lt;/li&gt;
&lt;li&gt;When you compare two values, the result is of either the &lt;code&gt;== operator&lt;/code&gt; or the &lt;code&gt;equals()&lt;/code&gt; when comparing strings.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
val num = 45
val num1 = 56
val output = num.equals(num1)
println(output)
// when using the == operator
println(45 == 56)
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output of the above code is &lt;code&gt;false&lt;/code&gt; because &lt;code&gt;45&lt;/code&gt; is not equal to &lt;code&gt;56&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To check if two values are not equal we can use exclamation mark and equals sign(!=)
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
// when using the != operator
println(45 != 56)
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;The output of the above code is &lt;code&gt;true&lt;/code&gt; because &lt;code&gt;45&lt;/code&gt; is not equal to &lt;code&gt;56&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;In addition we can use other operators such as the greater and the less than signs followed by an equal sign to check if certain numbers are equal or not.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;em&gt;The output of the below code is given in boolean next to the println statement.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
println(45 &amp;lt; 56) // true  
println(45 &amp;gt; 56) //false
println(45 &amp;lt;= 56) //true
println(45 &amp;gt;= 56) //false
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Logical operations : Boolean&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;The and operator (&amp;amp;&amp;amp;)&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The and-operator returns &lt;code&gt;true&lt;/code&gt; when the conditions given are both &lt;code&gt;true&lt;/code&gt; else it returns &lt;code&gt;false&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;The or operator (||)&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The or operator returns &lt;code&gt;false&lt;/code&gt; when both of the conditions given are &lt;code&gt;false&lt;/code&gt; else it returns &lt;code&gt;true&lt;/code&gt;.
&lt;code&gt;The not operator(!)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;It negates the boolean value. It turns true into false and false into true.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
val isAmazing = true
println(!isAmazing)//false
val isBoring = false
println(!isBoring)//true
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of the above code is &lt;code&gt;false&lt;/code&gt; for the first print statement and &lt;code&gt;true&lt;/code&gt; for the second statement.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A good analogy for the logical operator not is a minus before a number. It turns a number into a positive and a positive to a negative.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
val num = 1
println(-num)//-1
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output is a negative integer &lt;code&gt;-1&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In programming, you can use negation multiple times. Even number of negations returns the boolean being negated while odd number of negations returns the opposite of the boolean provided.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main () {
println(!true)//false
println(!!true)//true
println(!!!true)//false
println(!!!!true)//true
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Conditions in Kotlin
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;If condition&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The syntax for the if condition is &lt;/p&gt;

&lt;p&gt;&lt;code&gt;if(condition){&lt;br&gt;
  println(specify what to be printed)&lt;br&gt;
        }&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Every line in the body of a statement starts with four additional spaces known as indent and the whitespaces which improves code readability.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; fun main () {
val accountType = "free"
    if(accountType == "free")
    println("show adds")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of the above code will be &lt;code&gt;showing adds&lt;/code&gt; since the the condition is met.&lt;br&gt;
&lt;strong&gt;If - else condition&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An if-else statement can be used as an expression in other words, to return a value that can be stored in a variable. The returned value is the value returned by the  body block that was chosen.&lt;/li&gt;
&lt;li&gt;Inside if else bodies you can include more than one statement. The value returned by the body is the last expression it has.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
    val accountMoney = true
    val tip: Double = if (accountMoney) {
        println("You can withdraw")
        89.0
        90.0
        100.0
    } else {
        println("Sorry, I am broke")
        0.0
    }
    println(tip)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output will be &lt;code&gt;You can withdraw 100.0&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If- else- if&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is a structure that checks condition one after the other until it finds the  first one that is fulfilled, and calls its body.&lt;/li&gt;
&lt;li&gt;It is not popular in Kotlin because there is better alternative, called the when statement.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
 println("Is it going to rain?")
    val probability = 70
    if (probability &amp;lt;= 40) {
        println("Unlikely")

    } else if (probability &amp;lt;= 80){
        println("Likely")
             }
    else if(probability &amp;lt;100){
        println("Yes")
    }
   else{
       println("what?")
   } 
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output of the code is &lt;code&gt;likely&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;When condition statement&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It starts with the keyword when then open the curly braces. Inside the curly braces, write a condition and the body that should be executed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;when {&lt;/code&gt;&lt;br&gt;
&lt;code&gt;condition -&amp;gt; {body to be executed}&lt;/code&gt;&lt;br&gt;
&lt;code&gt;condition -&amp;gt; {body to be executed}&lt;/code&gt;&lt;br&gt;
&lt;code&gt;else -&amp;gt; {body to be executed}&lt;/code&gt;&lt;br&gt;
&lt;code&gt;}&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The when statement can be used as an expression inprder to produce a value. When statement must have an else block so that it can have something to return incase no other block is chosen.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
    println("Is it going to rain?")
    val probability = 70
    val text = when{
        probability &amp;lt;= 40 -&amp;gt; "unlikely"
         probability &amp;lt;= 80 -&amp;gt; "unlikely"
         probability &amp;lt;= 100 -&amp;gt; "unlikely"
        else -&amp;gt; "what?"
    }
    println(text)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output of the above code is &lt;code&gt;Unlikely&lt;/code&gt;. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you add a value in brackets after the when keyword, then in each branch, kotlin compares this value to others.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
    val number = 80
    when(number){
         70-&amp;gt; {println("missed hit") }
         80,90,100-&amp;gt; {println("Hit with value $number") }
         110-&amp;gt; {println("critical hit") }
    }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output of the code is &lt;code&gt;Hit with value 80&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We can use the when statements with the range check. The syntax starts with the in keyword, and then specify either a collection or a range that might contain the value or not.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
   val number = 99
   val text = when(number){
         70-&amp;gt; {println("missed hit") }
         in 80..100-&amp;gt; {println("Hit with value $number") }
         110-&amp;gt; {println("critical hit") }
         else -&amp;gt; "unsupported"
    }
  println(text)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  6. Loops in Kotlin
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Loops allow the execution of one or more statements until a condition is met. It can be used multiple times.&lt;/li&gt;
&lt;li&gt;If the path of execution steps into an if condition, it checks the predicate. If it returns true the control flow continues to the next line.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Predicate&lt;/em&gt; is a function or an expression that returns a boolean.&lt;/li&gt;
&lt;li&gt;The difference between a loop and the if conditions is that loops can be executed more than once.&lt;/li&gt;
&lt;li&gt;There are three types of loops;

&lt;ul&gt;
&lt;li&gt;While loop&lt;/li&gt;
&lt;li&gt;For loop&lt;/li&gt;
&lt;li&gt;Nested loop&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;While loop&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The while loop is similar to the if statement but you use the while keyword instead of if. &lt;/li&gt;
&lt;li&gt;The syntax for the while loop
&lt;code&gt;//initialize the counter&lt;/code&gt;
&lt;code&gt;while(condition){&lt;/code&gt;
&lt;code&gt;//put the code here&lt;/code&gt;
&lt;code&gt;// increment or decrement counter&lt;/code&gt;
               &lt;code&gt;}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The difference between the while loop and the if condition is that the while loop can call its body more than once. If condition will never call its body more than once.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
    var number = 99
   while(number &amp;lt;= 120){
      if(number%2 == 0)
          println(number)
          number++;
      }
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The code above prints the even numbers between &lt;code&gt;99&lt;/code&gt; and &lt;code&gt;120&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We can also use the while loop to print a sequence.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; fun main() {
    var number = 99
   while(number &amp;lt; 120){
          println("$number")
          number = number+3;
      }
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The sequence created increases by &lt;code&gt;3&lt;/code&gt; until the maximum number set is reached.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For loop&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For loops are mostly used to iterate over group of elements.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; fun main() {
    var listOfnumber = listOf(99,102,105,108,111,114,117) 
   for(number in listOfnumber){
       println("On of the numbers in the list is $number")
   }
 } 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output of the code above is;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;On of the numbers in the list is 99&lt;/li&gt;
&lt;li&gt;On of the numbers in the list is 102&lt;/li&gt;
&lt;li&gt;On of the numbers in the list is 105&lt;/li&gt;
&lt;li&gt;On of the numbers in the list is 108&lt;/li&gt;
&lt;li&gt;On of the numbers in the list is 111&lt;/li&gt;
&lt;li&gt;On of the numbers in the list is 114&lt;/li&gt;
&lt;li&gt;On of the numbers in the list is 117&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;The for loop can be used to iterate over numbers in both a closed and open range.&lt;/li&gt;
&lt;li&gt;In closed range, we use &lt;code&gt;..&lt;/code&gt; to print the numbers given. The last value given in a loop is printed. It shows the range.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
    //closed range 
for(number in 91..100){
       println(number)
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output of code will print numbers between &lt;code&gt;91&lt;/code&gt; to &lt;code&gt;100&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In open range, we use &lt;code&gt;until&lt;/code&gt; to print the numbers given. The last value given in a loop is not printed.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
    //open range 
for(number in 91 until 100){
       println(number)
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output of code will print numbers between &lt;code&gt;91&lt;/code&gt; to &lt;code&gt;99&lt;/code&gt;. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The for loop can be used to increment and decrement an iteration through &lt;code&gt;step&lt;/code&gt; keyword and &lt;code&gt;downTo&lt;/code&gt; keyword.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
    //closed range 
for(number in 91 until 100  step 3){
       println(number)
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output of the above code is &lt;code&gt;91&lt;/code&gt;,&lt;code&gt;94&lt;/code&gt;,&lt;code&gt;97&lt;/code&gt;. The step keyword increases a number by three after every iteration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
    for(number in 100 downTo 90){
       print(number)
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of the above code will be printed from &lt;code&gt;100&lt;/code&gt; backward to &lt;code&gt;90&lt;/code&gt;. We can also move backward with a certain number of steps using the step keyword as shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
    for(number in 100 downTo 90 step 3){
       println(number)
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of the code will be &lt;code&gt;100&lt;/code&gt;,&lt;code&gt;97&lt;/code&gt;,&lt;code&gt;94&lt;/code&gt;,&lt;code&gt;91&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nested Loop&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is a loop inside another loop.&lt;/li&gt;
&lt;li&gt;The outer loop prints the number of rows while the inner loop prints the body.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
    for(i in 1..5){
    for(j in 1..i){
        print("*")
    }
    println()
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of the above code will print a triangle of stars.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*
**
***
****
*****
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Thank you for taking the time to read my article. I hope the ending left you with a lasting impression and that you will return for more thought-provoking content in Android and Kotlin in the future.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhnyzlzwx7onci7zoeajd.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhnyzlzwx7onci7zoeajd.jpg" alt="Imagekk"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Be on the watch for modules two and three where we will deep dive into functions, classes and advanced classes in Kotlin. See you soon&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs099i6qvar53rnxygm1f.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs099i6qvar53rnxygm1f.jpg" alt="syn"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>android</category>
      <category>kotlin</category>
      <category>mobile</category>
    </item>
    <item>
      <title>Introduction to Android Studio, Project Structure, and Emulation.</title>
      <dc:creator>Daniel Brian</dc:creator>
      <pubDate>Thu, 01 Dec 2022 12:22:55 +0000</pubDate>
      <link>https://dev.to/dbriane208/introduction-to-android-studio-project-structure-and-emulation-5d0j</link>
      <guid>https://dev.to/dbriane208/introduction-to-android-studio-project-structure-and-emulation-5d0j</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;code&gt;I am very happy about Android obviously. I use Android, and it’s actually made cellphones very usable.”&lt;br&gt;
              ~ Linus Torvald.&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hellooooo🥳️🥳️🥳️I am glad🤗 that you have joined me again in this Android development journey🚀. If you haven't read the &lt;a href="https://dev.to/dbriane208/the-fundamentals-of-android-development-1ffi"&gt;The Fundamentals of Android Development article&lt;/a&gt; ensure you go through it to caught up with us. Do not forget to 👍like, comment👍 and share with your friends👨‍👨‍👦‍👦🥳️.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;strong&gt;&lt;u&gt;Article Objectives&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this article, we're going to look at:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Emulators and Android OS images and their role in Android app development.&lt;/li&gt;
&lt;li&gt;Main activity and manifest code in relation to the project structure of Android apps.&lt;/li&gt;
&lt;li&gt;Gradle and its role in project building in Android Studio&lt;/li&gt;
&lt;li&gt;The folder structure of an Android project, and its contents including the res and layout folders.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;u&gt;Emulators&lt;/u&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt; An &lt;strong&gt;emulator&lt;/strong&gt; is a computer program that's designed to imitate another kind of device.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwxxx3mo934zwjfwp7udd.png" alt="Emulator"&gt;
&lt;/li&gt;
&lt;li&gt; While different types of emulators have unique ways of operating, the overall goal remains the same;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;em&gt;It allows you to test your app without having to install them on the physical devices you designed them for.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;It imitates the Android devices your App is designed for&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;It replicates the experience of different hardware or software&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Emulation requires high computing resources therefore it's important to ensure your machine has &lt;em&gt;enough storage space&lt;/em&gt; and &lt;em&gt;random access memory&lt;/em&gt; for it to run effectively.&lt;/li&gt;
&lt;li&gt;There are several commercial and open-source emulators available for most of the operating systems in the market. eg&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Blue stacks:&lt;/strong&gt; allows you to run Android Apps on operating systems like Windows and Mac. It is also free to use.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Appetite.io:&lt;/strong&gt; is a web-based emulator that allows you to use iOS applications on any PC. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Super Nintendo Entertainment System(SNES):&lt;/strong&gt;It makes gaming possible through playing old video games on modern HD televisions.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;u&gt;Android Virtual Device&lt;/u&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Android Virtual Device makes it possible for you to test and optimize different mobile apps developed for different devices and operating systems.&lt;/li&gt;
&lt;li&gt;It allows you to define the various features of a physical device, such as an android phone that you want to create and simulate in the android emulator.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F98wzg41c2ck89sqqmpip.png" alt="Avd"&gt;
&lt;/li&gt;
&lt;li&gt;To access the AVD interface in Android Studio click the three-dotted menu in the top right for more actions. Select virtual device manager which opens in a new window. In this window, there are two major features:
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F472xdrcfru8dq92ruwgz.png" alt="avdmenu"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Create a new device button&lt;/code&gt;: this will allow you to add another device to the list of previously created virtual devices. &lt;/li&gt;
&lt;li&gt;There are also other icons in the top right hand used for various actions.

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Play button&lt;/code&gt;: it will run the emulator in a virtual device.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Pencil button&lt;/code&gt;: clicking it allows you to edit and save 
changes made to the properties of the virtual device.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq27gbl4kczckbjb75gcn.png" alt="newavd"&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;If you click on the &lt;code&gt;triangular drop-down menu&lt;/code&gt; on the top right hand, actions range from duplicating to deleting a selected virtual device display. &lt;/li&gt;

&lt;li&gt;In case you don't see the three-dotted menu you can click the more action menu in the center of the displayed window. &lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;u&gt;Mobile CPU architecture&lt;/u&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;In order to develop and deploy apps for different mobile devices, the Central Processing Unit (CPU) architecture must be considered.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;What is a CPU?&lt;/em&gt;&lt;br&gt;
A &lt;em&gt;CPU&lt;/em&gt; is a translator between the hardware and software of a device that translates high-level software instructions to native machine language.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The are three major CPU components used in smartphones which include;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ARM&lt;/strong&gt;: It is the most common and properly optimized for 
its battery use.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsiylmyfrj1gi9b1vn2x2.jpeg" alt="Arm1"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ARM64&lt;/strong&gt;: is an evolution of the original ARM architecture 
that supports 64-bit processing for more powerful computing 
and it’s quickly becoming the standard in newer devices.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6xpn3drzzk0um1hdzx2x.jpeg" alt="arm"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;x86&lt;/strong&gt;: it is a bit more powerful than the ARM CPUs, but 
not quite as battery-friendly.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh89guogvf6c2cos0uwfb.jpeg" alt="Intel86"&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt; ARM better embodies a mobile-first mentality, with simple instruction sets, efficiency, and low power consumption. It requires fewer transistors and frees up that hardware space more than makes up for the use of RAM in a mobile device.&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;u&gt;Operating System Images&lt;/u&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Android OS images help you leverage features of any Operating system to give your users the best experience with your app.&lt;/li&gt;
&lt;li&gt;OS images help you to enjoy the built-in features of any Operating system using the API level which uniquely identifies new features released for a particular OS.&lt;/li&gt;
&lt;li&gt;Currently the most recent Android OS images available for developers in Android Studio range from version 8, code name Oatmeal Cookie released in 2017 to version 13, code-named Tiramisu. More specifically, after the release of Oatmeal Cookie in 2017 came Pistachio Ice Cream in 2018, Quince Tart in 2019, and Red Velvet Cake in 2020. These were followed by Snow Cone in 2021, Snow Cone V2 in March 2022, and Tiramisu.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Farrjp52dodqzwbcllyhd.png" alt="avdmenu"&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To access the Android OS images, click the &lt;code&gt;Three dotted menu icon&lt;/code&gt; on the upper right-hand side to access more actions. Then click on &lt;code&gt;Virtual Device Manager&lt;/code&gt;. On the Device Manager page, click &lt;code&gt;Create Device.&lt;/code&gt; This opens the virtual device configuration where you can create an emulator.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9pc53mpqcvj1w75yl1un.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9pc53mpqcvj1w75yl1un.png" alt="avd"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;u&gt;Configuring an Emulator&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Emulators are a safe place to test your code, especially at the beginning of the design. Nevertheless, emulators require some configuration in order to function properly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Avid properties required to configure an AVD to an emulator in Android Studio.&lt;br&gt;
 &lt;em&gt;- Specify what you want the device to be called&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;- Select the landscape or portrait mode&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;- State the number of processor cores to be used&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;- Override the default RAM value&lt;/em&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To access the virtual device manager in Android Studio click the &lt;code&gt;three-dotted menu&lt;/code&gt; in the top right corner then click the &lt;code&gt;new device&lt;/code&gt; which will open a new window enabling you to choose the device you want to emulate. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In this window, you have the option to change the device and system, choose the device portrait or landscape and specify RAM and additional memory from the advanced settings.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;u&gt;Common Libraries and Packages&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Why use libraries?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Libraries extend the capabilities of the Android software development kit (SDK), allowing you to use code written by other developers.&lt;br&gt;
These open-source libraries are hosted on an external server and are downloaded by the build system, Gradle, when you are building a project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Types of Libraries&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Image loading&lt;/strong&gt;: It helps to avoid high memory consumption caused by loading multiple images at the same time. eg &lt;em&gt;Fresco&lt;/em&gt; provides a smooth scrolling experience while an image is loading due to smart caching to minimize storage overhead.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Videos&lt;/strong&gt;: ExoPlayers offers an alternative to Android's MediaPlayer API due to its ease of customization when playing Audio and Video locally or online.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Networking&lt;/strong&gt;: Mobile apps need some sort of network to communicate with each other. &lt;em&gt;Retrofit&lt;/em&gt; provides you with a great way to make internet calls within your application. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;u&gt;Android Studio and Project Structure&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Project Structure&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;New projects in Android Studio generate files and folders that contain everything that is required for an app to run from source code and assets to test code and build configurations.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;These basic folders and files consist of:                           &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Navigation bar&lt;/strong&gt;: It allows you to access the project 
   folders and files.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sample app folder&lt;/strong&gt;: It is the root directory for 
  project folders and files.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;.gradle folder&lt;/strong&gt;: This is the toolkit that guides the 
   project-building process of Gradle. It contains all 
   configurations and files used by Gradle to build your 
   project. Though they are automatically generated they 
   can be deleted.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4kdrf3vvyz3dyspjov92.png" alt="project struct"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;.idea folder&lt;/strong&gt;: It is used to store specific project 
   metadata which tells the app how to use the data it 
   describes. It contains configuration files and data for 
   specific functional areas.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;App folder&lt;/strong&gt;: It contains the source code related to 
   the project. Here you write your code, create the user 
   interface, and store assets eg images.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gradle folder&lt;/strong&gt;: It consists of a set of tools for 
   developers to build, test, and run applications.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;The Gradle folder contains subfolders and files which include;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;.gitignore file&lt;/code&gt;: It specifies which files to be 
   excluded from your repository systems eg GitHub.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;build.gradle&lt;/code&gt;: It is used to specify and manage the 
 configuration options common to all sub-projects folders.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnjcxw5gm2bbzj2yfljv7.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnjcxw5gm2bbzj2yfljv7.jpeg" alt="Gradle"&gt;&lt;/a&gt;&lt;br&gt;
       - &lt;code&gt;Gradlew&lt;/code&gt;: It is used by the Gradle Android studio build &lt;br&gt;
         system. It is created once and is updated whenever a new &lt;br&gt;
         feature or plugin is required to build a project.&lt;br&gt;
       - &lt;code&gt;local.properties file&lt;/code&gt;: It contains information specific &lt;br&gt;
         to your local configuration. It is not pushed to GitHub &lt;br&gt;
         because it contains sensitive information.&lt;br&gt;
       - &lt;code&gt;settings.gradle file&lt;/code&gt;: It handles the various settings &lt;br&gt;
         for projects and modules. It also displays third part &lt;br&gt;
         libraries.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;u&gt;Main Activity&lt;/u&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;One of the most fundamental parts of an Android App is the main activity class. It is generated together with other folders and files in Android Studio. An app will always have one activity class no matter how small in terms of code and scalability. &lt;/li&gt;
&lt;li&gt;
&lt;em&gt;&lt;code&gt;MainActivity.kt file&lt;/code&gt;&lt;/em&gt; is the entry point for your app where kotlin code is displayed which is integral to the behavior of your app.&lt;/li&gt;
&lt;li&gt;An Android app is usually made of multiple activities, sometimes called screens, that together form the user experience. These activities are represented by an activity class whose function is to respond to user input.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4c2b6tmrrehczt4qbwx5.png" alt="mainActivity"&gt;
&lt;/li&gt;
&lt;li&gt;Each activity class contains a layout that holds different pieces of a user interface or UI together so that the user can interact with an app. This means that the activity class is the gateway through which a user can interact dynamically with an Android app's UI. &lt;/li&gt;
&lt;li&gt;The main Activity class is the first screen that displays when a user displays an App.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;Oncreate()&lt;/code&gt; function is the entry point for your app to run successfully. Its role is to create the view and initialize the actions of the activity. This function is necessary to create an app successfully.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;u&gt;Gradle&lt;/u&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It enables Android Studio to run an application project and compile many different files and folders.&lt;/li&gt;
&lt;li&gt;The set of build configuration files defines:

&lt;ul&gt;
&lt;li&gt;How the project is developed&lt;/li&gt;
&lt;li&gt;Dependencies for the project&lt;/li&gt;
&lt;li&gt;Results or results of the compilation process.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;For every Android project, two build.gradle files are generated. The first Gradle settings apply to every module in the project. The second module-level settings apply to app modules.&lt;/li&gt;

&lt;li&gt;A module is a collection of the source file and build settings that allow you to divide your projects into different units of functionalities.&lt;/li&gt;

&lt;li&gt;Lets examine the build.gradle file.&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

1. apply plugin: 'com.android.application'

2. android{
3. default Config{...}
4. build Types{...}
        }
5. dependencies{...}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;android block&lt;/code&gt; in 2 above contains information about your project eg the OS version of your app.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;default Config&lt;/code&gt; in 3 above allows you to specify the minimum OS version, version number, application unique ID and other configuration settings.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;dependencies&lt;/code&gt; in 4 above specifies what the third party you wish to include in your app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Gradle can be started manually through the commandline tool. The commands issued include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;./gradlew build&lt;/code&gt;- It is used to build projects when read 
  to run an app.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;./gradlew clean&lt;/code&gt; - It is used to delete contents
  of building directory.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;./gradlew wrapper&lt;/code&gt; - It allows you to see gradle 
   operations in the background.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;u&gt;Android Manifest&lt;/u&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It is generated once a new project is launched. AndroidManifest.xml file contains essential information which includes, your activity, your receiver, and the service and providers. This defines the permissions that you need to access protected parts of the OS.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxv5knyk1h2rjdcohj87y.jpg" alt="Android manifest"&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Application tag&lt;/strong&gt;: It specifies the theme of the 
application of the user interface, icon, and label can be 
defined.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Activity tag&lt;/strong&gt;: It defines all the activities to be 
present in an application.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Intent filter&lt;/strong&gt;: It specifies the initial running of the 
application.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;u&gt;Resource folder&lt;/u&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It contains the form of files and files and static content that your code uses, such as colors and animations.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5nj94rbfa446mz2sus6v.jpeg" alt="Resf"&gt;
&lt;/li&gt;
&lt;li&gt;Resources available include &lt;em&gt;string, color, dimension, and font&lt;/em&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;String&lt;/strong&gt;: It enables you to define the text in the 
res/value/string.xml file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Color&lt;/strong&gt;: It is defined in the color.xml. It helps you 
manage your colors so that they are accessible across the 
app.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dimension&lt;/strong&gt;: It allows you to manage all your dimensions in 
one place using dimensions.xml.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Font&lt;/strong&gt;: It is used to manage all the fonts you use within 
your entire app project.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;These resources play an important role in your app compatibility.&lt;/li&gt;

&lt;li&gt;If you want to show congratulations in your app&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

    &amp;lt;resources&amp;gt;
    &amp;lt;string name = "message"&amp;gt;Congratulations!!.&amp;lt;string&amp;gt;
        &amp;lt;/resources&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;These folder lets you manage, change and access your resources globally across your app.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;u&gt;Project Files&lt;/u&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;They allow you to access the entire file structure of a project including all files hidden within folders from the Android view. &lt;/li&gt;
&lt;li&gt;These project files include

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;.build/&lt;/code&gt;- It contains files generated after a project build 
occurs.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.libs/&lt;/code&gt; - It contains private and third-party libraries used 
within the app.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;src/&lt;/code&gt;  - It contains all code and resource files for the 
module in its subdirectories.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;androidTest/&lt;/code&gt; - It contains code for testing features of the 
app.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;test/&lt;/code&gt;- it contains the unit testing code, with unit tests 
executed on the computer.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;main/&lt;/code&gt;- It contains Android code and resources for testing 
and production deployment.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvb25n4qwubut344ewxe8.png" alt="projS"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;AndroidManifest.xml&lt;/code&gt; - It describes specific information 
about your app and its activity.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;java/&lt;/code&gt;- It contains java and kotlin related code files.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;gen/&lt;/code&gt; - It contains the java files generated by android 
studio, which is required for the app to build successfully.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;res/&lt;/code&gt; - It contains application resources eg image files, 
font, dimension, and layout files.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;assets/&lt;/code&gt; - It contains files that should be compiled into 
an.apk file.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;You can navigate the directory using URLs and read files.&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  🚀🚀Thank you for following me along this journey🥳️🥳️ !!
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9z9jk23vqoakhyvi2687.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9z9jk23vqoakhyvi2687.jpeg" alt="End"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>android</category>
      <category>kotlin</category>
      <category>motivation</category>
    </item>
    <item>
      <title>The Fundamentals of Android Development.</title>
      <dc:creator>Daniel Brian</dc:creator>
      <pubDate>Thu, 10 Nov 2022 20:39:41 +0000</pubDate>
      <link>https://dev.to/dbriane208/the-fundamentals-of-android-development-1ffi</link>
      <guid>https://dev.to/dbriane208/the-fundamentals-of-android-development-1ffi</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Learning objectives&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Provide an overview of the difference between mobile apps and mobile websites.&lt;/li&gt;
&lt;li&gt;Explain how the mobile Operating system works.&lt;/li&gt;
&lt;li&gt;The Android Operating system.&lt;/li&gt;
&lt;li&gt;Introduction to Android development.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Mobile Platforms&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
 A mobile app is an installable software that runs on a smartphone device. Mobile apps use the device's hardware, and software features and usually provide an efficient, more intuitive, and seamless user experience. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;What is the difference between a mobile app and a mobile website?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A mobile app is software that runs on a hardware device whereas a mobile website works on a mobile app and does not involve any hardware to be functional.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;What are the advantages of mobile apps and a mobile website?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Mobile app&lt;/u&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Faster than mobile websites&lt;/li&gt;
&lt;li&gt;Can access resources eg location, Bluetooth, etc.&lt;/li&gt;
&lt;li&gt;Can work without internet access&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;u&gt;Mobile website&lt;/u&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Cheap to build and maintain&lt;/li&gt;
&lt;li&gt;Need not to be built from scratch to be compatible with other platforms&lt;/li&gt;
&lt;li&gt;No approval is required from Appstore&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;em&gt;To determine whether to develop a mobile website or mobile app always ask yourself what specific actions you expect your product to perform.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How does a Mobile OS work
&lt;/h2&gt;

&lt;p&gt;The most fundamental software for any mobile device is its OS. An OS is designed to coordinate communications that occur between the hardware and apps of mobile devices. It manages the overall experiences of an app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mobile operating system&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yTRes1ao--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kfmeezt0m9ogn1h7seln.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yTRes1ao--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kfmeezt0m9ogn1h7seln.jpeg" alt="mobileOS" width="400" height="500"&gt;&lt;/a&gt;&lt;br&gt;
A mobile OS typically starts up when a device powers on, displaying different application icons and user interface (UI) elements to users.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;em&gt;Uses of Operating system&lt;/em&gt;&lt;/u&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Allows smartphones, tablets, and personal digital assistants (PDAs) to run applications.&lt;/li&gt;
&lt;li&gt;OS provides a channel with which applications can access device resources such as the processor, memory, Wi-Fi, Bluetooth, and more. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The most common operating systems are &lt;em&gt;Android&lt;/em&gt; and &lt;em&gt;iOS&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Android&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mWHtuUWU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eqs8b6l5vhl81e94jnq7.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mWHtuUWU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eqs8b6l5vhl81e94jnq7.jpeg" alt="Android" width="880" height="783"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Android is a mobile OS that was released in 2008.&lt;/li&gt;
&lt;li&gt;Android OS is based on a modified version of the Linux kernel and is an open-source software which means anyone can modify it.&lt;/li&gt;
&lt;li&gt;Android OS was built primarily for smartphones, Chromebook, Android TV, and Android Auto, as well as wearables such as smartwatches.&lt;/li&gt;
&lt;li&gt;Android has built-in sensors such as gyroscopes and accelerometers, which gives users a multi-touch experience.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;iOS&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xPV2jIfT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a8sx0ul0827lp1j8gbks.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xPV2jIfT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a8sx0ul0827lp1j8gbks.jpeg" alt="ios" width="880" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;iOS is Apple’s proprietary OS that runs on the iPhone, iPad, and other mobile devices&lt;/li&gt;
&lt;li&gt;Same as Android, iOS has built-in sensors such as gyroscopes and accelerometers, which gives users a multi-touch experience through several actions such as swiping, pulling, and tapping, and users can seamlessly interact with the screen.&lt;/li&gt;
&lt;li&gt;With the rise in popularity of iOS, developers now have more controls and access to its features.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Other mobile operating systems include &lt;em&gt;&lt;strong&gt;kaiOS&lt;/strong&gt;&lt;/em&gt; which runs on Mozilla Firefox, &lt;em&gt;&lt;strong&gt;SailfishOS&lt;/strong&gt;&lt;/em&gt; from Jolla, and &lt;em&gt;&lt;strong&gt;Huawei's HarmonyOS&lt;/strong&gt;&lt;/em&gt; which was released in 2019 and runs on a microkernel that Huawei developed. Mostly used in IoT devices. &lt;/p&gt;

&lt;h2&gt;
  
  
  Android Platforms
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Being the most used operating system in the world, Android is not limited to only mobile devices. Android is also used to power other devices due to its openness to others.&lt;/li&gt;
&lt;li&gt;Android platforms include, Chromebook, Android TV, Android Auto, and WearOS.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Chromebook&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ezgOVLow--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qucxdn5zzessjrl22zoq.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ezgOVLow--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qucxdn5zzessjrl22zoq.jpeg" alt="chromebook" width="880" height="587"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chromebooks are portable laptops that have support for running Android apps, which gives them more features.&lt;/li&gt;
&lt;li&gt;Chromebooks operate on Google's ChromeOS. &lt;/li&gt;
&lt;li&gt;Ability to use convertible form factors to not necessarily build apps from scratch for phones and tablets from ChromeOS.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Android TV&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ijWJJu4F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3yhpdn72o0p80s52xzqw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ijWJJu4F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3yhpdn72o0p80s52xzqw.jpeg" alt="androidtv" width="500" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Android TV is designed to bring the mobile experience to your TV.&lt;/li&gt;
&lt;li&gt;The voice control feature of the TV allows you to have complete control over your devices.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Android Auto&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9Z1-m0or--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/avwfyily7e1hldesrcn8.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9Z1-m0or--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/avwfyily7e1hldesrcn8.jpeg" alt="Android Auto" width="880" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It allows you to connect your phone to your car display.&lt;/li&gt;
&lt;li&gt;It automatically shows your apps on your car display and makes it possible for you to get driving directions and navigate seamlessly.&lt;/li&gt;
&lt;li&gt;Android Auto is made to help you stay focused on the road.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;WearOS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wD7sQNbW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/emsg673iqoo0831nrks1.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wD7sQNbW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/emsg673iqoo0831nrks1.jpeg" alt="wearos" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;WearOS is Google's Android OS that is specifically designed to power smartwatches and other wearables.&lt;/li&gt;
&lt;li&gt;The early release of WearOS allowed watching owners to install WearOS apps through their mobile phones from the google play store.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Introduction to Android Development
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Android Languages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the world of Android development, &lt;strong&gt;Java&lt;/strong&gt; and &lt;strong&gt;Kotlin&lt;/strong&gt; are both extremely popular programming languages. &lt;/li&gt;
&lt;li&gt;Java, which was released by Sun Microsystems in 1995 while Kotlin was introduced by JetBrains in 2011.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aq9I3cQs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9qu1qea9q117qxgfxij.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aq9I3cQs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9qu1qea9q117qxgfxij.jpeg" alt="kotlinvsjava" width="880" height="372"&gt;&lt;/a&gt;&lt;br&gt;
-Kotlin has officially become the preferred language for Android app development due to the following reasons;&lt;br&gt;
    1. It is concise and standardized hence low code errors.&lt;br&gt;
    2. Easier to maintain complex projects due to low code.&lt;br&gt;
    3. It is compatible with java hence easy to convert java &lt;br&gt;
       code to Kotlin.&lt;br&gt;
    4. Kotlin handles errors that crash Android apps better &lt;br&gt;
       than java.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Android OS&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Android is a Linux-based OS primarily designed for touchscreen mobile devices such as smartphones and tablets.&lt;/li&gt;
&lt;li&gt;Some of the unique features and characteristics of the Android OS include:&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;em&gt;&lt;strong&gt;Near-field communication&lt;/strong&gt;&lt;/em&gt;: This feature makes it easy for electronic devices to communicate over short distances.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;&lt;strong&gt;Wi-Fi&lt;/strong&gt;&lt;/em&gt;: With this feature, users can connect to various wireless access points around them due to these in-built technologies that support Wi-Fi protocols.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;&lt;strong&gt;Custom home screen&lt;/strong&gt;&lt;/em&gt;: Android OS allows you to further personalize your home screen the way you like it.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;&lt;strong&gt;Widgets&lt;/strong&gt;&lt;/em&gt;: Used for home-screen customization to give you a glance view of users' most important data.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;&lt;strong&gt;App downloads&lt;/strong&gt;&lt;/em&gt;: users can unlock the full potential of the Android operating system through app downloads.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;&lt;strong&gt;Custom ROMS&lt;/strong&gt;&lt;/em&gt;: Android can use customized and modified versions of Android OS to access features of a recent on an older device.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The Android OS Architecture&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Consists of components that Android needs to be functional.&lt;/li&gt;
&lt;li&gt;Android is built on top of an open-source Linux kernel and other C and C++ libraries exposed via application framework services.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The Android OS is a stack of software components roughly divided into five sections:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Applications
&lt;/li&gt;
&lt;li&gt;Application frameworks&lt;/li&gt;
&lt;li&gt;Android runtime&lt;/li&gt;
&lt;li&gt;Platform Libraries&lt;/li&gt;
&lt;li&gt;Linux Kernel&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;These are separated into 4 layers, as shown in the architecture diagram below.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---A1H9nDi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l1rfgxamwk4grs53oge7.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---A1H9nDi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l1rfgxamwk4grs53oge7.PNG" alt="AndroidOS layers" width="791" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Android App Cheatsheet
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;To get started with developing an app, you need a clear understanding of relevant concepts.&lt;/li&gt;
&lt;li&gt;These concepts include:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Top-level component&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enables apps to connect to the internet, make calls, and take pictures through BroadcastReceiver, ContentProvider, and Service and activity accessible in Android SDK.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Activity Components&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;These are activities present for content users to interact with on the screen.&lt;/li&gt;
&lt;li&gt;Single activity architecture pattern allows one activity or a relatively small number of activities to be used for an entire app.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Android views&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is the design interface that occupies a rectangular area on the screen and is responsible for drawing and event handling. It displays text, images, and more.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Android layout files&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In Android, each layout is represented by an XML file. These plain text files serve as blueprints for the interface that your application presents to the user.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Project files&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Android Project Files belong to one of three main categories: &lt;strong&gt;configuration&lt;/strong&gt;,&lt;strong&gt;code&lt;/strong&gt;, and &lt;strong&gt;resource&lt;/strong&gt;. &lt;em&gt;Configuration files&lt;/em&gt; define the project structure, &lt;em&gt;code files&lt;/em&gt; provide the logic, and &lt;em&gt;resource files&lt;/em&gt; provide essentially everything else.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Anatomy of An Android App
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This basically looks into the components that go in when creating an App.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QmRp3SGO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9vynor3c0eznuhrah9cd.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QmRp3SGO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9vynor3c0eznuhrah9cd.jpeg" alt="Anatomy" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An Android app is made up of four major components that serve as the building blocks of any Android app in the market.&lt;/li&gt;
&lt;li&gt;The four major components include:&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Activities&lt;/strong&gt;: This is the entry point of users that represent a single user. It allows you to place UI components, widgets, or user interfaces on a single screen. eg &lt;em&gt;a music player app may have an activity that shows you a list of your favorite songs, another activity that allows you to play a specific song, and another which shows you a list of trending songs.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Services&lt;/strong&gt;: They run in the background and constantly update the data sources and activities with the latest changes. It also performs tasks when users are not active on applications. eg &lt;em&gt;A good example of a service is chatting with someone whilst listening to music.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Broadcast Receiver&lt;/strong&gt;: Its purpose is to respond to messages from other applications or systems in real time. eg,&lt;em&gt;imagine you're enjoying your favorite song on your music app when you get a notification that you're running low on battery power.&lt;/em&gt; &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Content providers&lt;/strong&gt;: It's responsible for sharing data between applications. eg &lt;em&gt;A typical example is a social media app that allows users to share their images online.&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These Android components are coupled by a configuration file called &lt;strong&gt;AndroidManifest.xml&lt;/strong&gt;. It is used to specify each component and how they interact with each other.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4YX6099U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pirqbpipdpub1pu3gtc9.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4YX6099U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pirqbpipdpub1pu3gtc9.jpeg" alt="Androidmanifest" width="802" height="420"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Extensible Markup Language(XML)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;XML (Extensible Markup Language) is used in the presentation of different kinds of data. Its main function is to create data formats that are used to encode information for documentation, records, transactions, and several other data formats.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JdJHnYeE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pbhohy4eduweqbq31to2.jpeg" alt="xml" width="600" height="300"&gt;
&lt;/li&gt;
&lt;li&gt;For an XML document to be valid, the following conditions must be fulfilled:&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;The document must be well-formed.&lt;/li&gt;
&lt;li&gt;The document must comply with all the rules of the XML syntax.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;THE END.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thank you for taking the time to go through the article!!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AuepXd1d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v75bei3o07x5f3r3hx4h.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AuepXd1d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v75bei3o07x5f3r3hx4h.jpeg" alt="TheEnd" width="880" height="587"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>android</category>
      <category>mobile</category>
      <category>kotlin</category>
    </item>
    <item>
      <title>BIG O NOTATION AND TIME COMPLEXITY.</title>
      <dc:creator>Daniel Brian</dc:creator>
      <pubDate>Tue, 05 Jul 2022 07:41:25 +0000</pubDate>
      <link>https://dev.to/dbriane208/big-o-notation-and-time-complexity-247c</link>
      <guid>https://dev.to/dbriane208/big-o-notation-and-time-complexity-247c</guid>
      <description>&lt;p&gt;Hello👋👋.Before we embark on this amazing article be sure to check out my last wonderful 🙂article on &lt;a href="https://dev.to/dbriane208/data-structure-and-algorithms-101-m5b"&gt;Data Structures and algorithms 101.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article, we will learn everything that we need to know about Big O notation and how you can use it to improve your ability to create efficient algorithms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Big O notation&lt;/strong&gt; is used to classify algorithms based on how fast they grow or decline. It is used to analyze the efficiency of an algorithm as its input approaches infinity.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;For Example:&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;Let's say we have a dentist and she takes 30 minutes to attend to one patient. As her line of patients increases, the time that it takes to treat all of the patients will scale linearly with the number of patients waiting in the line.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DJpFAIHr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/72vjsvb6uqekqgv0s8ou.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DJpFAIHr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/72vjsvb6uqekqgv0s8ou.jpeg" alt="" width="880" height="548"&gt;&lt;/a&gt;&lt;br&gt;
This gives us a general understanding of how long our dentist would take to attend to any number of patients since she uses a constant amount of time, which is 30 minutes to treat each patient. With this in mind, we can categorize his efficiency as linear or as we say in big O terms big O of n (&lt;em&gt;Big O(n)&lt;/em&gt;), where &lt;em&gt;n&lt;/em&gt; is equal to the number of patients, the time that it takes for her to finish her work scales linearly or proportionally with the number of patients.&lt;/p&gt;

&lt;p&gt;We can use the same technique to determine the general idea of how a function's time efficiency scales by categorizing a given function's efficiency in the same way as the dentist's efficiency. Let's create an easily comprehensible function that scales similarly to the dentist.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Finding the sum of numbers in a given array.

            given_array = [1,4,3,2,...,10]
            def find_sum(given_array):
            total = 0
            for each i in given_array:
            total+=i
            return total
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;One may ask how does the runtime of a function grow?&lt;/strong&gt;&lt;br&gt;
   we run our functions to generate a bunch of arrays with various sizes as our inputs. These were:[5,7,9,7,8],[4,9,8,6,3],[1,9,7,1,10,7,6,7,9,4],[6,9,7,5,6,1,5,6,6,7]&lt;/p&gt;

&lt;p&gt;Using these randomly generated arrays as input we run our function many times to find the average time it takes to run our function in each of n where n is the number of elements in a given array.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M2jxAZfJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wm2uprup17aw4ps9iozc.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M2jxAZfJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wm2uprup17aw4ps9iozc.PNG" alt="" width="514" height="335"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/em&gt;&lt;br&gt;
The X-axis represents the number of elements and the Y-axis represents the time in microsecond it takes to run a function. &lt;/p&gt;

&lt;p&gt;From the graph, this is known as &lt;strong&gt;linear time complexity&lt;/strong&gt; represented as &lt;strong&gt;O(n)&lt;/strong&gt;. &lt;em&gt;Time complexity&lt;/em&gt; is a way of showing how the runtime of a function increases as the size of the input increases.&lt;/p&gt;

&lt;p&gt;Other time complexities include:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Constant time&lt;/strong&gt;: This is where the time to run a function does not increase with increase as the input increases. It is represented as &lt;strong&gt;O(1).&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example:
   given_array=[1,4,3,2,...,10]
   def stupid_function(given_array):
   total = 0:
   return total

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we run this function with various sizes of array inputs the result is as shown below.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nD0ABbck--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z4ixmc8qgrej6am81img.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nD0ABbck--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z4ixmc8qgrej6am81img.PNG" alt="" width="579" height="385"&gt;&lt;/a&gt;&lt;br&gt;
Our constant c = 0.115 and it's the fastest-growing time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Quadratic time&lt;/strong&gt;: This is where the time to run function increases the way a quadratic function increases. It is represented as &lt;strong&gt;O(n^2)&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example:
   array_2d = [[1,4,3],     [[1,4,3,1],
               [3,1,9],      [3,1,9,4],
               [0,5,2]].     [0,5,2,6],
                             [4,5,7,8]].
  1. def find_sun_2d(array_2d):
  2.     total = 0
  3.  for each row in array_2d:
  4.  for each i in row:
  5.     total += i
  6.  return total

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-Lines 2,5 and 6 take the same amount of time to run and thus have a constant time. In addition, we have 2 double for loops in our example which we assume do exactly the same thing. This would give us&lt;br&gt;
      &lt;strong&gt;T = O(1) + n^2 * O + O(1)&lt;br&gt;
        =O(n^2).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thank you for Having time for my Article.🤗🥰️🎉&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thank you for taking your time to read 🤗🥳Happy learning😇🌟.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TFCXVUc8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dhgilfs5iexk9y037ilx.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TFCXVUc8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dhgilfs5iexk9y037ilx.jpeg" alt="" width="626" height="619"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>machinelearning</category>
      <category>algorithms</category>
      <category>challenge</category>
    </item>
    <item>
      <title>Data Structure and Algorithms 101.</title>
      <dc:creator>Daniel Brian</dc:creator>
      <pubDate>Tue, 21 Jun 2022 16:49:45 +0000</pubDate>
      <link>https://dev.to/dbriane208/data-structure-and-algorithms-101-m5b</link>
      <guid>https://dev.to/dbriane208/data-structure-and-algorithms-101-m5b</guid>
      <description>&lt;p&gt;What is Data Structure?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data Structures&lt;/strong&gt; allows you to organize your data in such a way it enables you to store collections of data, relate them and perform operations on them accordingly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of Data Structures&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;Built-in/Primitive data structures&lt;/em&gt;&lt;/strong&gt;: They store data of only one type. They include:&lt;/p&gt;

&lt;p&gt;a)&lt;strong&gt;&lt;em&gt;List&lt;/em&gt;&lt;/strong&gt;: Lists can have heterogeneous data types in them. They can be mutable that is they can be changed. We use Square brackets to create lists.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example:
a=['apple','banana','pear']
#We can add another fruit into the lists through
a.append(orange)
print(a)
#When we run this in any IDE; a=['apple','banana','pear','orange']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;b)&lt;strong&gt;&lt;em&gt;Tuples&lt;/em&gt;&lt;/strong&gt; : They are not mutable. They are faster than lists. We use regular brackets to create tuples.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;b=(3,4,5)
print(b)
solution:(3,4,5)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;c)&lt;strong&gt;&lt;em&gt;Dictionary&lt;/em&gt;&lt;/strong&gt; : They hold key value pairs. We use curly brackets to initialize dictionaries. Dictionaries are mutable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;c={1:'python',2:'java'}
print(c)
solution: {1:'python',2:'java'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;d)&lt;strong&gt;&lt;em&gt;Sets&lt;/em&gt;&lt;/strong&gt;: These are unordered collection of unique elements. We use curly brackets to initialize sets. Sets are mutable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;d = {2,3,4,2}
print(d)
solution: {2,3,4}
#This is because sets do not repeat same elements inside it.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. User-defined/derived/non-primitive data Structures&lt;/strong&gt;: They are data of more than one type. They include;&lt;/p&gt;

&lt;p&gt;a)&lt;strong&gt;&lt;em&gt;Stacks&lt;/em&gt;&lt;/strong&gt;: The data that is entered last will be the first one to be accessed. They are built using array structure and have operations namely &lt;strong&gt;&lt;em&gt;push&lt;/em&gt;&lt;/strong&gt; which adds an element to the collection and &lt;em&gt;&lt;strong&gt;pop&lt;/strong&gt;&lt;/em&gt; which removes elements from a collection. They are used in applications such as recursive programming, reversing words etc.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftfqyigi3hd05ebvys3yz.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftfqyigi3hd05ebvys3yz.jpeg" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
b)&lt;em&gt;&lt;strong&gt;Queues&lt;/strong&gt;&lt;/em&gt;: This is a linear data structure based on the principle of first in first out.  They are also built using an array structure and operations can be done on them. They are used in the application of traffic congestion management and in operating systems for job scheduling.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F372yn1km9lgx2qjsi5hq.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F372yn1km9lgx2qjsi5hq.jpeg" alt="Queues"&gt;&lt;/a&gt;&lt;br&gt;
c)&lt;em&gt;&lt;strong&gt;Trees&lt;/strong&gt;&lt;/em&gt;: This is a non-linear data structure that has roots and nodes. Roots are where the data originates while nodes are any point where data is accessible to us. The node to proceed is the parent and the latter is the child. Trees are widely used in Html pages and are efficient for searching purposes.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fic7e7kp9lnqc3etejit7.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fic7e7kp9lnqc3etejit7.jpeg"&gt;&lt;/a&gt;&lt;br&gt;
d)&lt;em&gt;&lt;strong&gt;Linked lists&lt;/strong&gt;&lt;/em&gt;: These are liner data structures t are not stored concurrently but are linked together through pointers. The node of a list composes of data and a pointer. They are used in image viewing applications and music player applications.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbkqdvfs48kf3uuyew1ap.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbkqdvfs48kf3uuyew1ap.jpeg"&gt;&lt;/a&gt;&lt;br&gt;
e)&lt;em&gt;&lt;strong&gt;Graphs&lt;/strong&gt;&lt;/em&gt;: They are used to store data collection of points and edges. Many applications such as google maps and uber use graphs to find the least path in order to maximize profits.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft976peu72ld4e1y7m9xx.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft976peu72ld4e1y7m9xx.jpeg"&gt;&lt;/a&gt;&lt;br&gt;
f)&lt;em&gt;&lt;strong&gt;Hashmaps&lt;/strong&gt;&lt;/em&gt;: They are the same as what directions are in python. They are used to implement applications such as phonebooks and populate data.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnyhs6nu3k8z2fprvz4xj.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnyhs6nu3k8z2fprvz4xj.jpeg"&gt;&lt;/a&gt;&lt;br&gt;
What are Algorithms?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Algorithms&lt;/strong&gt; are rules or instructions which are formulated in a finite sequential order to solve problems. They provide pseudocode for problems. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Important things to note when writing algorithms.&lt;/em&gt;&lt;br&gt;
   -Figure out what is the exact problem&lt;br&gt;
   -Determine where you need to start&lt;br&gt;
   -Determine where you need to stop&lt;br&gt;
   -Formulate the intermediate steps&lt;br&gt;
   -Review your steps&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Elements of a good Algorithm&lt;/em&gt;&lt;br&gt;
   -Steps should be finite, clear, and understandable&lt;br&gt;
   -Clear and precise description of inputs and outputs&lt;br&gt;
   -The algorithm should be flexible&lt;br&gt;
   -The steps should make use of general programming fundamentals&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Algorithm classes&lt;/strong&gt;&lt;br&gt;
There are three types;&lt;br&gt;
   i)&lt;em&gt;&lt;strong&gt;Divide and Conquer&lt;/strong&gt;&lt;/em&gt; - Divides the problem into subparts and solves the subparts separately.&lt;br&gt;
   ii)&lt;em&gt;&lt;strong&gt;Dynamic programming&lt;/strong&gt;&lt;/em&gt; - Divides the problem into subparts remembers the results of the sub-parts and applies them to similar ones.&lt;br&gt;
   iii)&lt;em&gt;&lt;strong&gt;Greedy Algorithms&lt;/strong&gt;&lt;/em&gt; - Involves taking the easiest step while solving a problem without worrying about the complexity of the future steps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tree Traversal Algorithms&lt;/strong&gt;&lt;br&gt;
There are three types of tree traversals:&lt;br&gt;
   i)&lt;em&gt;&lt;strong&gt;In-order traversal&lt;/strong&gt;&lt;/em&gt;: refers to visiting the left nodes followed by the root and then right nodes.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feanhzvvuq10p523y1jv2.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feanhzvvuq10p523y1jv2.jpeg"&gt;&lt;/a&gt;&lt;br&gt;
  ii)&lt;em&gt;&lt;strong&gt;Pre-ordered traversal&lt;/strong&gt;&lt;/em&gt;: refers to visiting the root nodes followed by the left nodes and then right nodes.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3p8r8pqctfz6a5ii6uxm.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3p8r8pqctfz6a5ii6uxm.jpeg"&gt;&lt;/a&gt;&lt;br&gt;
  iii)&lt;em&gt;&lt;strong&gt;Post-order traversal&lt;/strong&gt;&lt;/em&gt;: refers to visiting the left nodes followed by the right nodes and then the root node.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbm36brb5ilgezovl84qv.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbm36brb5ilgezovl84qv.jpeg"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Sorting Algorithms&lt;/strong&gt;&lt;br&gt;
It is used to sort data in some given order. It can be classified into five steps.&lt;br&gt;
   i)&lt;em&gt;&lt;strong&gt;Merge sort&lt;/strong&gt;&lt;/em&gt;: The given list is first divided into smaller lists and compares to adjacent lists and records in the desired sequence. &lt;br&gt;
   ii)&lt;em&gt;&lt;strong&gt;Bubble sort&lt;/strong&gt;&lt;/em&gt;: is a comparison algorithm that first compares and sorts adjacent elements if they are not in the specified order.&lt;br&gt;
   iii)&lt;em&gt;&lt;strong&gt;Insertion sort&lt;/strong&gt;&lt;/em&gt;: Picks one element of the given list at a time and places it at the exact position where it is to be placed.&lt;br&gt;
   iv)&lt;em&gt;&lt;strong&gt;Selection sort&lt;/strong&gt;&lt;/em&gt;: Picks one element of a given list at a time and places it at the exact spot where it is placed.&lt;br&gt;
   v)&lt;em&gt;&lt;strong&gt;Shell sort&lt;/strong&gt;&lt;/em&gt;: allows you to sort elements apart from each other.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Searching Algorithms&lt;/strong&gt;&lt;br&gt;
  Searching algorithms are used to search for or fetch elements present in some given dataset. There are many types of search algorithms; Linear search, Binary search, Exponential search, and interpolation search.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Algorithm analysis&lt;/strong&gt;&lt;br&gt;
a)&lt;em&gt;&lt;strong&gt;A prior analysis&lt;/strong&gt;&lt;/em&gt;: where all factors are assumed to be constant and do affect the implementation.&lt;br&gt;
b)&lt;em&gt;&lt;strong&gt;A posterior analysis&lt;/strong&gt;&lt;/em&gt;: The actual values like time complexity or execution on time of an algorithm, and space complexity are gathered.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thank you for taking your time to read 🤗🥳Happy learning😇🌟.&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>FAKE NEWS DETECTION WITH PYTHON</title>
      <dc:creator>Daniel Brian</dc:creator>
      <pubDate>Sun, 01 May 2022 20:51:17 +0000</pubDate>
      <link>https://dev.to/dbriane208/fake-news-detection-with-python-lp5</link>
      <guid>https://dev.to/dbriane208/fake-news-detection-with-python-lp5</guid>
      <description>&lt;p&gt;Fake news is one of the biggest problems with online social platforms.We can using machine learning for fake news detection. In this article, I will walk you through the task of Fake News Detection with Machine Learning using Python.Here is the basic workflow.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#we're loading data into our notebook
#we load in the necessary libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import warnings
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import MultinomialNB

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After importing the relevant libraries we have to load in our d&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#importing our data through pandas
data=pd.read_csv('/content/drive/MyDrive/news.csv')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After loading the data, let us examine it. It is usually not recommended to throw all the data into a predictive model without first understanding the data. this would often help us improving our model.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#we check our first five rows and columns
data.head()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Missing data values can really mess our model. It's crucial to check whether there are some missing data and fill them. For our case we didnt have any missing values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#To check whether our data have missing values
data.isnull().sum()

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Machine learning algorithms cannot understand texts(categorical values)and thus we have to convert them to numeric data.&lt;/p&gt;

&lt;p&gt;We will convert our 'label' into 1 and 0 using the lamda function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;data['label'] = data['label'].apply(lambda x: 1 if x == 'REAL' else 0)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For our other categorical features we will use function dummies from pandas library.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dummies=pd.get_dummies(data[['title','text']])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Afterwards we split our data into x and y variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#we split our data into x and y
x=data.drop('label',axis=1)
y=data['label']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lastly we will fit our model using RandomForestClassifier.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from sklearn.naive_bayes import MultinomialNB
from sklearn.model_selection import train_test_split

np.random.seed(42)
x_train,x_test,y_train,y_test=train_test_split(dummies,y,test_size=0.2)
model=MultinomialNB()
model.fit(x_train,y_train)
model.score(x_test,y_test)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So this is how we can train a machine learning model for the task of fake news detection by using the Python programming language.I hope you liked this article on the task of Fake News detection with machine learning using Python.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Python 101 : The Ultimate Python Tutorial For Beginners</title>
      <dc:creator>Daniel Brian</dc:creator>
      <pubDate>Sun, 24 Apr 2022 20:23:42 +0000</pubDate>
      <link>https://dev.to/dbriane208/python-101-the-ultimate-python-tutorial-for-beginners-36a3</link>
      <guid>https://dev.to/dbriane208/python-101-the-ultimate-python-tutorial-for-beginners-36a3</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is python programming?🤔&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python&lt;/strong&gt; is a high level programming language. It emphasizes code reusability with the use of significant indentation. It was designed by Guido Van Rossum on 20th February 1991.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Applications of python programming&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Python programming is widely used. These are some of the ways it is majorly used in:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Web development&lt;/li&gt;
&lt;li&gt;Game development&lt;/li&gt;
&lt;li&gt;Machine learning and Artificial Intelligence&lt;/li&gt;
&lt;li&gt;Data Science and Data visualization&lt;/li&gt;
&lt;li&gt;Desktop Applications&lt;/li&gt;
&lt;li&gt;Automation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Advantages of using python programming language&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It is easy to use&lt;/li&gt;
&lt;li&gt;It's improved productivity&lt;/li&gt;
&lt;li&gt;It's an interpreted language&lt;/li&gt;
&lt;li&gt;It's dynamically typed&lt;/li&gt;
&lt;li&gt;It's free and open-source&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Python installation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Visit &lt;a href="https://www.python.org/downloads/%5B%5D(url)"&gt;https://www.python.org/downloads/[](url)&lt;/a&gt;&lt;br&gt;
Select your Operating system&lt;br&gt;
Select the release or version, and click on it to download.&lt;br&gt;
Double click on the file to execute and install. For window mark "add to system paths" An alternative way to install python on Linux is to run&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;gt; sudo apt install python3 or sudo apt install python on the terminal&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Variables in python&lt;/strong&gt;&lt;br&gt;
A variable is a reserved memory location to store variables. There are four types of variables;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Integers&lt;/li&gt;
&lt;li&gt;Long Integer&lt;/li&gt;
&lt;li&gt;Float&lt;/li&gt;
&lt;li&gt;String&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are rules which are followed when declaring variables which are;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Keywords cannot be used to name variables.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example: def = 5
# This is incorrect because def is a keyword in python
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Must start with a letter or underscore character.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example: a)variable = name
         b)@variable = name
 #when executing this type of code a will be executed but b wont be executed because it doesn't start with letter or underscore.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Variables are case sensitive, (age, Age, and AGE) are different variables
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example: #When you declare a variable it must be consistent in you code.
i) age = 15
ii) Age = 14
#the output of age will not be the same with that of Age
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Can only contain alpha-numeric character and underscore(A- Z,0-9, _)
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example:
     sum = $400
     sum = 400
  #sum is executable while $um is not because dollar sign is non-alphernumeric

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Variable cannot start with a number.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example 
num1 = 7
2num = 8
# 2num is not executable because variables cannot start with numbers.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Literals in python&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Literals refers to data stored in variables. Different types of literals include:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  1. Boolean literals
  2. Special literals
  3. String literals
  4. Numeric literals
  5. Literal collections
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;1. Boolean literals&lt;/strong&gt;&lt;br&gt;
They are only two: True, False.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example:
games= [soccer,tennis,rugby]
print(soccer in games)
True
print(badminton in games)
False

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.Special characters&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Python contains one special literal. "None", it is used to define a null variable. If "None" is compared with anything else than "None" it will return false.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. String literals&lt;/strong&gt;&lt;br&gt;
These are characters that are surrounded by single or double quotes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#In single quote
name = 'Daniel Brian'

#In double quotes
name = "Daniel Brian"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4.Numerical literals&lt;/strong&gt;&lt;br&gt;
They are of different types;&lt;br&gt;
Complex&lt;br&gt;
Integers&lt;br&gt;
Float&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Complex
These are numbers having both a real and imaginary part in the form of x + 5j, where x is real and y is imaginary.&lt;/li&gt;
&lt;li&gt;Float
These are both positive and negative numbers with
floating.
point numbers(with decimals).
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; num =0.256784
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Integers
These are both positive and negative integers without floating point numbers.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 28
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;4. Literal collections&lt;/strong&gt;&lt;br&gt;
These are;&lt;br&gt;
 a)&lt;em&gt;List&lt;/em&gt;:Its an ordered sequence of data.They are mutable meaning if you want to change anything in a list you can change.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example:
 A=["Earth","Mars","Jupiter"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;b)&lt;em&gt;Tuples&lt;/em&gt;: is a sequence of immutable sequence objects.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example:
mytuple = ("apple", "banana", "cherry")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;c)&lt;em&gt;Dictionaries&lt;/em&gt;: They are special characters which allows one to store information in key-value pairs&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example:
monthconversions={
"Jan":"January"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;d)&lt;em&gt;Set&lt;/em&gt;:They are used to store multiple items in a single variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Example:
&amp;gt;&amp;gt;&amp;gt; A = {1, 2, 3, 4, 5} &amp;gt;&amp;gt;&amp;gt; B = {4, 5, 6, 7, 8}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>python</category>
      <category>opensource</category>
      <category>machinelearning</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
