<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Muhammad Bilal on Medium]]></title>
        <description><![CDATA[Stories by Muhammad Bilal on Medium]]></description>
        <link>https://medium.com/@muhammadb159?source=rss-79b956899184------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wXfDdI17AeAoE60hIUQXwA.jpeg</url>
            <title>Stories by Muhammad Bilal on Medium</title>
            <link>https://medium.com/@muhammadb159?source=rss-79b956899184------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 16:36:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@muhammadb159/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Flutter Experience by Bilal]]></title>
            <link>https://medium.com/@muhammadb159/flutter-experience-by-bilal-13f963dba605?source=rss-79b956899184------2</link>
            <guid isPermaLink="false">https://medium.com/p/13f963dba605</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[mobi̇le]]></category>
            <dc:creator><![CDATA[Muhammad Bilal]]></dc:creator>
            <pubDate>Mon, 01 Nov 2021 07:13:05 GMT</pubDate>
            <atom:updated>2021-11-01T07:13:05.133Z</atom:updated>
            <content:encoded><![CDATA[<p>Flutter Apprentice is a great book for learning the basics of flutter. I started reading the book from the beginning on weekend. I have completed this book till chapter 5: Scrollable Widgets.</p><p><a href="https://www.raywenderlich.com/books/flutter-apprentice/v2.0/chapters/5-scrollable-widgets">https://www.raywenderlich.com/books/flutter-apprentice/v2.0/chapters/5-scrollable-widgets</a></p><p>Things that I like about this book and raywenderlich collaboration :</p><p>1. Easy to understand the simple concepts without getting into the complexities</p><p>2. Practical knowledge with concepts.</p><p>3. Step by step integration of concepts in a constructive manner.</p><p>4. Reading and implementing concepts gives developers a sense of confidence for getting familiar with flutter.</p><p>Highly recommended for a new developer in the mobile stack</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13f963dba605" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin By Bilal — Productivity Boosters in Kotlin]]></title>
            <link>https://medium.com/@muhammadb159/kotlin-by-bilal-productivity-boosters-in-kotlin-fa257991b07c?source=rss-79b956899184------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa257991b07c</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kotlin-native]]></category>
            <category><![CDATA[kotlin-beginners]]></category>
            <dc:creator><![CDATA[Muhammad Bilal]]></dc:creator>
            <pubDate>Thu, 07 Oct 2021 08:12:52 GMT</pubDate>
            <atom:updated>2021-10-07T08:12:52.668Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kotlin By Bilal — Productivity Boosters in Kotlin</h3><p>Kotlin itself is a productivity booster as compared to JAVA, but I see some really cool things in Kotlin that will surely boost up your productivity.</p><p>Let me list them here :</p><ol><li>Named Arguments.</li><li>String templates and String manipulation.</li><li>Smart Casts.</li><li>Destructuring Declaration.</li></ol><p>I will explain each point one by one :</p><p><strong>Named Arguments :</strong></p><p>Named Arguments are made to provide ease to developers while passing arguments into the function. We can use “name =” where name is the variable name that needs to be pass.</p><p><em>Example :</em></p><pre>fun main() {<br>    <em>printUserInfo</em>(secondName = &quot;Khalid&quot;, firstName = &quot;Bilal&quot;)<br>}<br><br>fun printUserInfo(firstName: String, secondName: String) {<br>    <em>println</em>(&quot;$firstName $secondName&quot;)<br>}</pre><p>You can also use these name functions like this :</p><p><em>Example :</em></p><pre>fun main() {<br>    <em>printUserInfo</em>( firstName = &quot;Bilal&quot;, secondName = &quot;Khalid&quot;)<br>}<br><br>fun printUserInfo(firstName: String, secondName: String, middleName : String = &quot;Rajput&quot;) {<br>    <em>println</em>(&quot;$firstName $secondName $middleName&quot;)<br>}</pre><p>As you use the default variable name for the function.</p><p><strong>String Template :</strong></p><p><a href="https://kotlinlang.org/docs/reference/basic-types.html#string-templates">String templates</a> allow you to include variable references and expressions into strings. When the value of a string is requested (for example, by println), all references and expressions are substituted with actual values.</p><p><em>Example :</em></p><pre>val <em>greeting </em>= &quot;Kotliner&quot;<br>println(&quot;Hello $greeting&quot;) // 1 <br>println(&quot;Hello ${greeting.toUpperCase()}&quot;)</pre><ol><li>Prints a string with a variable reference. References in strings start with $.</li><li>Prints a string with an expression. Expressions start with $ and are enclosed in curly braces.</li></ol><p><strong>Smart Casts :</strong></p><p>Kotlin compiler is smart enough to perform the typecast automatically in most cases. Kotlin can convert supertype to subtype</p><p><em>Example :</em></p><pre>val <em>date</em>: ChronoLocalDate? = LocalDate.now()    // 1<br><br>if (date != null) {<br>    println(date.isLeapYear)                    // 2<br>}<br><br>if (date != null &amp;&amp; date.isLeapYear) {          // 3<br>    println(&quot;It&#39;s a leap year!&quot;)<br>}<br><br>if (date == null || !date.isLeapYear) {         // 4<br>    println(&quot;There&#39;s no Feb 29 this year...&quot;)<br>}<br><br>if (date is LocalDate) {<br>    val month = date.monthValue                 // 5<br>    println(month)<br>}</pre><p>Points explain:</p><ol><li>Declares a nullable variable.</li><li>Smart-cast to non-nullable (thus allowing direct access to isLeapYear).</li><li>Smart-cast inside a condition (this is possible because, like Java, Kotlin uses <a href="https://en.wikipedia.org/wiki/Short-circuit_evaluation">short-circuiting</a>).</li><li>Smart-cast inside a condition (also enabled by short-circuiting).</li><li>Smart-cast to the subtype LocalDate.</li></ol><p><strong><em>note: this example is taken from kotlin official website</em></strong></p><p><strong>Destructuring Declarations :</strong></p><p>A destructuring declaration is <strong>the one that creates and initializes multiple variables at once</strong>. These multiple variables correspond to the properties of a class that are associated with an instance. These variables can be used independently in any way you want.</p><p><em>Example 1:</em></p><pre>// destructuring array &amp; nested array &amp; combine array into single array<br>let person = [&quot;Ronaldo&quot;, &quot;Usman&quot;, &quot;Khalid&quot;, [&quot;Tommy&quot;, &quot;Max&quot;], &quot;Diego&quot;, &quot;Benzima&quot;];<br>// empty comma is like skipping array index. I skipped &quot;Sam&quot;<br>const [a, b, c,...d] = person;</pre><p>output:</p><pre>println(a); // output: &quot;Ronaldo&quot;<br>println(b); // output: &quot;Usman&quot;<br>println(c); // output: &quot;Khalid&quot; <br>println(d); // output: [&quot;Tommy&quot;, &quot;Max&quot;]</pre><p>Example <em>2</em>:</p><pre>// A sample data class<br>data class Data(val name:String,val age:Int)<br><br>// A function returning two values<br>fun sendData():Data{<br>    return Data(&quot;Jack&quot;,30)<br>}<br><br>fun main(){<br>    val obj = <em>sendData</em>()<br>    //  Using instance to access properties<br>    <em>println</em>(&quot;Name is ${obj.name}&quot;)<br>    <em>println</em>(&quot;Age is ${obj.age}&quot;)<br><br>    // Creating two variables using  destructing declaration<br>    val (name,age) = <em>sendData</em>()<br>    <em>println</em>(&quot;Name is $name&quot;)<br>    <em>println</em>(&quot;Age is $age&quot;)<br><br>}</pre><p>I will write a detailed story about <strong>Destructuring Declarations</strong> stay tuned..!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa257991b07c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Just started my journey on FLUTTER]]></title>
            <link>https://medium.com/@muhammadb159/just-started-my-journey-on-flutter-5e164c06603?source=rss-79b956899184------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e164c06603</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter-web]]></category>
            <dc:creator><![CDATA[Muhammad Bilal]]></dc:creator>
            <pubDate>Mon, 04 Oct 2021 12:55:05 GMT</pubDate>
            <atom:updated>2021-10-04T12:55:05.363Z</atom:updated>
            <content:encoded><![CDATA[<p>In this story, I would like to tell about my journey with flutter so far, While learning flutter I feel that I am more close to web development rather than mobile development. Did you feels the same ?… well if you did clap like a high-five. :)</p><p>I was struggling to learn flutter for the past 6 months, now I think it is the right time to take off with flutter, using my free time to learn flutter is going well for now. I would like to mention one thing that I enjoyed about flutter is the speed of developing any application and the second thing that really fascinates me about flutter is adding dependencies with terminal, it really helps me avoid into pubyml indentation issue, Flutter developer can relate to it. I really enjoyed developing apps on flutter now.</p><p>Benefits of Developing application in a flutter, What I think about flutter development:</p><ol><li>If you are a mobile application developer and you are also a freelancer, this point is for you, you have an edge to developer a fast prototype for your client using single-based code for ANDROID and IOS at the same time.</li><li>Development on flutter is quite fast than native android, but native will always be there for complex applications</li><li>Flutter is like blocks, that needs to be arranged and built by the developer in such a way that will complement the problem-solving of a developer and sense of development application according to user experience and business model</li></ol><p>Working with Dart :</p><p>Dart is a new language for me as I have no experience with JAVAscript or any other web application development language. It was a bit difficult at the start now I think, dart and I are becoming friends.</p><p>Flutter uses Dart as Dart <strong>allows Flutter to avoid the need for a separate declarative layout language like JSX and XML</strong>. The layout of Dart is declarative and programmatic and it makes it easy for developers to read and visualize it very easily and effortlessly.</p><p>This is my application for flutter that I started 15 days, take a look at the repo and let me know what you think about the application code :</p><p><a href="https://github.com/bilal5008/petapp">https://github.com/bilal5008/petapp</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e164c06603" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin By Bilal — Lists and operations on List]]></title>
            <link>https://medium.com/@muhammadb159/kotlin-by-bilal-lists-and-operations-on-list-56a5e62f6810?source=rss-79b956899184------2</link>
            <guid isPermaLink="false">https://medium.com/p/56a5e62f6810</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin-native]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kotlin-beginners]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Muhammad Bilal]]></dc:creator>
            <pubDate>Thu, 30 Sep 2021 07:00:54 GMT</pubDate>
            <atom:updated>2021-09-30T07:00:54.637Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kotlin By Bilal — Lists and operations on List</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*2eGXTSjQB-SjiKhLYjTg4g.jpeg" /></figure><p>List and its operations in Kotlin can help you Big time while developing with.</p><p>A list is a generic ordered collection of elements that can contain duplicate values. And, <strong><em>List</em> in Kotlin is an interface that extends the <em>Collection</em> interface</strong>.</p><p><strong>All the methods in this interface support read-only access to the list</strong>. Let’s look at how the list interface is declared:</p><pre>public interface <strong>List</strong>&lt;<strong>out</strong> <strong>E</strong>&gt; : <strong>Collection</strong>&lt;<strong>E</strong>&gt;</pre><p><strong>Additionally,</strong> <strong>Kotlin has a <em>MutableList</em> interface to modify the elements of a list</strong>. The <em>MutableList</em> interface extends the <em>MutableCollection </em>interface. The methods within this interface allow us to add and remove elements from the list.</p><p>Let’s now see how the mutable list interface is declared:</p><pre>public interface <strong>MutableList</strong>&lt;<strong>E</strong>&gt; : <strong>List</strong>&lt;<strong>E</strong>&gt;, <strong>MutableCollection</strong>&lt;<strong>E</strong>&gt;</pre><p>Both the <em>List</em> and <em>MutableList </em>interfaces have methods that help us work with lists in Kotlin.</p><p>let me explain operations on the list :</p><ol><li><strong>Filtering :</strong></li></ol><p>List in Kotlin can be filtered with the predefined operation and user-defined functions that are really helpful for a developer.</p><p><em>example 1:</em></p><pre>val name: List&lt;String&gt; = <em>listOf</em>(&quot;Donn&quot;, &quot;Bob&quot;, &quot;Jenny&quot;, &quot;Bilal&quot;)<br>// you can filtering on different type of filtering<br>val filtered: List&lt;String&gt; = name.<em>filter </em><strong>{ it</strong>.<em>toLowerCase</em>().<em>contains</em>(&quot;a&quot;) <strong>}<br></strong><em>println</em>(filtered)</pre><p>output :</p><p>[Bilal]</p><p><em>example 2 :</em></p><p>For this example, I am using my defined function i.e isAdult</p><pre>val age = <em>listOf</em>(23, 4, 5, 6, 6, 443)<br><br>// filtering through function........<br>val adults = age.<em>filter</em>(::isAdult)<br><em>println</em>(adults)</pre><pre>fun isAdult(value: Int): Boolean {<br>    return value &gt; 18<br>}</pre><p>output :</p><p>[23, 443]</p><p><em>example 3 :</em></p><p>I will use example 1 for this example :</p><p>if we apply filterNot function on the list above</p><pre><em>println</em>(&quot; notfiltering ${name.<em>filterNot </em><strong>{ it</strong>.<em>contains</em>(&quot;a&quot;) <strong>}</strong>}&quot;)</pre><p>output :</p><p>notfiltering [Donn, Bob, Jenny]</p><p><strong>Filtering one list over another list:</strong></p><p><em>Example 4:</em></p><pre>// merging array should be mutable<br>val mutableList1: MutableList&lt;String&gt; = <em>mutableListOf</em>(&quot;Donn&quot;, &quot;Bob&quot;, &quot;Jenny&quot;, &quot;Inaam&quot;, &quot;Liala&quot;)<br>// into merging array should not be mutable<br>val toFilterList: List&lt;String&gt; = <em>listOf</em>(&quot;Donn&quot;, &quot;Bob&quot;, &quot;Jenny&quot;, &quot;Bilal&quot;)<br><br>// filtering a non mutable like from mutable ....<br><br>toFilterList.<em>filterNotTo</em>(mutableList1) <strong>{<br>    it</strong>.<em>contains</em>(&quot;a&quot;)<br><strong>}<br><br></strong>// printing value for non mutable list..............<br><em>println</em>(&quot;this is value$mutableList1&quot;)</pre><p>Output :</p><p>this is value[Donn, Bob, Jenny, Inaam, Liala, Donn, Bob, Jenny]</p><p>In this example, I remove Bilal from the list and merge it with the mutable list.</p><p><strong>Merge arrays with flatten() function :</strong></p><p>Flatten returns a single list of all elements from all arrays in the given array.</p><pre>// flatten array is java<br><br>val flatten1 = <em>arrayOf</em>(&quot;Donn&quot;, &quot;Bob&quot;, &quot;Jenny&quot;, &quot;Bilal&quot;)<br>// into merging array should not be mutable<br>val flatten2 = <em>arrayOf</em>(&quot;Donn&quot;, &quot;Bob&quot;, &quot;Jenny&quot;, &quot;aaaa&quot;, &quot;aaaa&quot;)<br>val allArrays = <em>arrayOf</em>(flatten1, flatten2)<br><br><em>println</em>(&quot;flatten one ${allArrays.<em>flatten</em>()}&quot;)</pre><p><strong>Another way to merge immutable arrays :</strong></p><p>Plus() function :</p><p>Plus() returns a list containing all elements of the original collection and then all elements of the given elements collection.</p><p>Example 5:</p><pre>//multiple immutable list in kotlin adding list  in non mutable list of strings............./<br><br>val mine = <em>listOf</em>(&quot;Apples, Grapes&quot;)<br>val theirs = <em>listOf</em>(&quot;Oranges, pears , strawberries&quot;)<br>val other = <em>listOf</em>(&quot;Kiwi, Watermalon&quot;)<br>val result = mine.<em>plus</em>(theirs).<em>plus</em>(other)<br><em>println</em>(&quot;$result&quot;)</pre><p>output :</p><p>[Apples, Grapes, Oranges, pears, strawberries, Kiwi, Watermalon]</p><p><strong>Replacing Elements in the array :</strong></p><p>Example 6 :</p><p>Map() function :</p><p>Map () returns a list containing the results of applying the given transform function to each element in the original collection.</p><pre>val item = <em>listOf</em>(&quot;Muhammad Bilal&quot;, &quot;Safina Malik&quot;, &quot;Usman Munir&quot;, &quot;Hassan Sheik&quot;)<br>val abbrevation = item.<em>map </em><strong>{ </strong>&quot;Abc&quot; <strong>}<br><br></strong><em>println</em>(&quot;mapping abbrevation $abbrevation&quot;)</pre><p>output :</p><p>mapping abbreviation [Abc, Abc, Abc, Abc]</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56a5e62f6810" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin by Bilal — Arrays and list In Kotlin]]></title>
            <link>https://medium.com/@muhammadb159/kotlin-by-bilal-arrays-and-list-in-kotlin-1ac63eaa6579?source=rss-79b956899184------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ac63eaa6579</guid>
            <category><![CDATA[kotlin-native]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kotlin-beginners]]></category>
            <dc:creator><![CDATA[Muhammad Bilal]]></dc:creator>
            <pubDate>Tue, 28 Sep 2021 06:57:24 GMT</pubDate>
            <atom:updated>2021-09-28T06:57:24.276Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kotlin by Bilal — Arrays and list In Kotlin</h3><p>The array is one of the most important and fundamental data structures in all programming languages. The array can store multiple items of the same data type, such as an integer or string under a single variable name.</p><p><strong>Here are some basic properties of arrays –</strong></p><ul><li>They are stored in contiguous memory locations.</li><li>They can be accessed programmatically through their indexes (array[1], array[0], etc.)</li><li>They are mutable.</li><li>Their size is fixed.</li></ul><p>Creating Array :</p><p><strong>Using the </strong><strong>arrayOf() function –</strong></p><p><em>Example :</em></p><pre>val items = <em>arrayOf</em>(&quot;Mac&quot;, &quot;Macbook&quot;)<br>items.<em>forEach </em><strong>{ </strong><em>println</em>(<strong>it</strong>) <strong>}</strong></pre><pre>items.<em>forEach </em><strong>{<br>    </strong><em>println</em>(<strong>it</strong>.toString())<br><strong>}</strong></pre><p><strong><em>Output :</em></strong></p><p>Mac<br>Macbook</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*2eGXTSjQB-SjiKhLYjTg4g.jpeg" /></figure><p>We can also use the whole model in the array</p><p><strong>Creating an array using Custom model :</strong></p><pre>val users = <em>arrayOf</em>(<br>    User(&quot;Bilal&quot;, &quot;khalid&quot;),<br>    User(&quot;Bilal&quot;, &quot;khalid&quot;),<br>    User(&quot;Bilal&quot;, &quot;khalid&quot;)<br><br>)</pre><pre>users.<em>forEach </em><strong>{<br>    </strong><em>println</em>(<strong>it</strong>.toString())<br><strong>}</strong></pre><p><strong>Output :</strong></p><p>User(name1=’Bilal’, name2=’khalid’)<br>User(name1=’Bilal’, name2=’khalid’)<br>User(name1=’Bilal’, name2=’khalid’)<br>User(name1=’Bilal’, name2=’khalid’)</p><p><strong>Filter from List :</strong></p><p>We often need to filter our list according to some business logic, we can use list build-in functions for filtering the list.</p><p><strong><em>Let me show it with an example :</em></strong></p><pre>val name: List&lt;String&gt; = <em>listOf</em>(&quot;Donn&quot;, &quot;Bob&quot;, &quot;Jenny&quot;, &quot;Bilal&quot;)</pre><pre>val filtered: List&lt;String&gt; = name.<em>filter </em><strong>{ it</strong>.<em>toLowerCase</em>().<em>contains</em>(&quot;a&quot;) <strong>}<br></strong><em>println</em>(filtered)</pre><p><strong><em>Output :</em></strong></p><p>[Bilal]</p><p>filtering through a function ………………….!</p><p>we can also write a custom filter for lists using functions in the filter function.</p><p><strong><em>let me show a simple example without a function filter :</em></strong></p><pre>val age = <em>listOf</em>(23, 4, 5, 6, 6, 443)<br> filtering through value<br> val adults  = age.filter { it &gt;= 18 }<br> println(adults)</pre><p><strong><em>now filter with function :</em></strong></p><pre>///  filtering through function........<br>val adults = age.<em>filter</em>(::isAdult)<br><em>println</em>(adults)</pre><pre>fun isAdult(value: Int): Boolean {<br>    return value &gt; 18<br>}</pre><p><strong><em>Output for both :</em></strong></p><p>[23, 443]</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ac63eaa6579" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin by Bilal — Overriding Getters and Setters]]></title>
            <link>https://medium.com/@muhammadb159/kotlin-by-bilal-overriding-getters-and-setters-1b6afd79e547?source=rss-79b956899184------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b6afd79e547</guid>
            <category><![CDATA[kotlin-beginners]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin-native]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Muhammad Bilal]]></dc:creator>
            <pubDate>Mon, 27 Sep 2021 08:48:25 GMT</pubDate>
            <atom:updated>2021-09-27T08:48:25.684Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kotlin by Bilal — Overriding Getters and Setters</h3><p>The need for overriding getters and setters comes when we need to apply some business logic or for the ease of developers to set value in a container and get value according to the need of business logic.</p><p>You can override your getters and setters for that, and provide custom values using logic to junior developers or developers working at the upper layer of an application.</p><p>Before jump into the code, I would like to share definitions of two important keywords</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*2eGXTSjQB-SjiKhLYjTg4g.jpeg" /></figure><p><strong>Field and value</strong></p><p>In Kotlin, a <strong>field is only used as a part of a property to hold its value in memory</strong>. Fields cannot be declared directly. However, when a property needs a backing field, Kotlin provides it automatically.</p><p><strong>Let me clear the above explanation with, overriding of getters and setters with examples.</strong></p><p><strong>Overriding Setter :</strong></p><p><em>main class</em></p><pre>fun main() {<br><br>    var userSetter = UserOverriddingSetter(&quot;Bilal&quot;)<br>    <em>println</em>(&quot;userSetter  ${userSetter.fullName}&quot;)<br>    userSetter.fullName = &quot;Bilal&quot;<br>    <em>println</em>(&quot;Value by over riding setter   ${userSetter.fullName}&quot;)<br><br>    userSetter.fullName = &quot;Safina Bilal&quot;<br>    <em>println</em>(&quot;Value by over riding setter  ${userSetter.fullName}&quot;)<br>    <br>}</pre><p><em>Override Setter</em></p><pre>class UserOverriddingSetter(firstName: String) {<br>    // setter do not call first time when i set firstname in constructor<br>    // setter works when i set firstname specifically for setter<br>    var fullName: String = &quot;$firstName&quot;<br>        get() = &quot;Name : $<strong>field</strong>&quot;<br>        set(value) {<br>            <strong>field </strong>= if (value.<em>startsWith</em>(&quot;Bilal&quot;)) {<br>                &quot;This is a new Person&quot;<br>            } else {<br>                value     // here we need to set value in else condition<br>            }<br>        }<br>}</pre><p><em>output :</em></p><p><strong>userSetter Name : Bilal<br>Value by overriding setter Name: This is a new Person<br>Value by overriding setter Name: Safina Bilal</strong></p><p><strong>Overriding Getters :</strong></p><p><em>main class :</em></p><pre>fun main() {<br>    var user = UserOverriddingGetter(&quot;Safina&quot;, &quot;Bilal&quot;)<br>    <em>println</em>(&quot;userGetter  ${user.fullName}&quot;)<br>}</pre><p><em>Override Getter :</em></p><pre>class UserOverriddingGetter( firstName: String,  LastName: String) {<br>    val name: String? = null<br>    var age: String? = null<br>    var degree: String? = null<br>    var job: String? = null<br>    var fullName: String = &quot;$firstName $LastName&quot;<br>        get() = &quot;Name : $<strong>field</strong>&quot;<br>}</pre><p><em>output :</em></p><p><strong>userGetter Name: Safina Bilal</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b6afd79e547" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin by Bilal — Null Safety]]></title>
            <link>https://medium.com/@muhammadb159/kotlin-by-bilal-null-safety-49bdb558298c?source=rss-79b956899184------2</link>
            <guid isPermaLink="false">https://medium.com/p/49bdb558298c</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kotlin-beginners]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin-native]]></category>
            <dc:creator><![CDATA[Muhammad Bilal]]></dc:creator>
            <pubDate>Fri, 24 Sep 2021 10:54:13 GMT</pubDate>
            <atom:updated>2021-09-24T10:54:13.194Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kotlin by Bilal — Null Safety</h3><p>Kotlin null safety is a procedure to eliminate to null pointer exception from the code.</p><p><strong>NullPointer Exception can only be Possible when :</strong></p><ul><li>When uninitialized of this variable is passed into constructor and used</li><li>When the developer forcefully call to throw NullPointerException()</li><li>The use of external Java code as Kotlin is Java interoperability.</li></ul><p><em>The third point needs some explanation for sure :</em></p><p>In koltin null checks are due to nullable annotation, as we cannot apply the nullable annotation to java, so there is the issue of getting NPE when using kotlin and java interoperating.</p><p>If you want to pass any value null and do not let your app crash at runtime, that is the beauty of kotlin null safety.</p><p><strong>Example :</strong></p><pre>var name : String?  = null<br>name  = &quot;Bilal&quot;<br>print(name)</pre><pre>output :<br>Bilal</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*2eGXTSjQB-SjiKhLYjTg4g.jpeg" /></figure><p>vice versa</p><p><strong>Example :</strong></p><pre>var name : String?  = &quot;Bilal&quot;<br>name  = null<br>print(name)</pre><pre>output :<br>null</pre><h3>Checking for null in conditions</h3><p>Kotlin’s If the expression is used for checking condition and returns the value.</p><pre>fun main(args: Array&lt;String&gt;){<br>    var str: String? = &quot;Hello&quot;     // variable is declared as nullable  <br>    var len = if(str!=null) str.length else -1<br>    <em>println</em>(&quot;str is : $str&quot;)<br>    <em>println</em>(&quot;str length is : $len&quot;)<br><br>    str = null<br>    <em>println</em>(&quot;str is : $str&quot;)<br>    len = if(str!=null) str.length else -1<br>    <em>println</em>(&quot;b length is : $len&quot;)<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49bdb558298c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin By Bilal- Enums]]></title>
            <link>https://medium.com/@muhammadb159/kotlin-by-bilal-enums-33be5d633f2f?source=rss-79b956899184------2</link>
            <guid isPermaLink="false">https://medium.com/p/33be5d633f2f</guid>
            <category><![CDATA[kotlin-beginners]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-apps]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kotlin-native]]></category>
            <dc:creator><![CDATA[Muhammad Bilal]]></dc:creator>
            <pubDate>Thu, 23 Sep 2021 09:03:10 GMT</pubDate>
            <atom:updated>2021-09-23T09:03:10.395Z</atom:updated>
            <content:encoded><![CDATA[<p>Enums are useful when we are dealing with a group of constant (unchangeable variables, like final variables)- they can have properties, implement interfaces and companion objects</p><pre>enum Level {<br>  LOW,<br>  MEDIUM,<br>  HIGH<br>}</pre><p>you can access enum constant with dot syntax</p><p>var level = Level.MEDIUM</p><p>In Kotlin we can also create an enum class that is very useful.</p><p>let&#39;s see some code examples of how we can use:</p><p><strong>Enums with Interface :</strong></p><p><em>Enum class</em></p><pre>enum class CardType : ICardLimit {<br>    <em>SILVER </em>{<br>        override fun getCreditLimit() = 100000<br>    },<br>    <em>GOLD </em>{<br>        override fun getCreditLimit() = 200000<br>    },<br>    <em>PLATINUM </em>{<br>        override fun getCreditLimit() = 300000<br>    }<br>}</pre><p><em>Interface</em></p><pre>interface ICardLimit {<br>    fun getCreditLimit(): Int<br>}</pre><p><em>main function</em></p><pre>val creditLimit = CardType.<em>PLATINUM</em>.getCreditLimit()<br><em>println</em>(&quot;creditLimit for Platinum  is $creditLimit&quot;)</pre><p>So, this example shows a clean implementation of the enum with the interface.</p><p><strong>Enum with Function Abstraction :</strong></p><p>We can use the abstract function in the enum class to call the override function of a required enum.</p><p><em>Enum class with abstraction function</em></p><pre>enum class AbstractAccountType() {<br><br>    // implementing abstract function in a enum<br>    <em>BROZE </em>{<br>        override fun calculateDiscountpercentage() =5<br>    },<br>    <em>SILVER </em>{<br>        override fun calculateDiscountpercentage() = 10<br>    },<br>    <em>GOLD </em>{<br>        override fun calculateDiscountpercentage() = 11<br>    },<br>    <em>PLATIUM </em>{<br>        override fun calculateDiscountpercentage()=12<br>    };<br><br>    abstract fun calculateDiscountpercentage() : Int<br><br>}</pre><p><em>main function</em></p><pre>fun main() {<br>    val fromApi  = &quot;Platium&quot;<br>    val accountType = AbstractAccountType.valueOf(fromApi.<em>toUpperCase</em>())<br>    <em>println</em>(accountType.calculateDiscountpercentage())<br>}</pre><p>So, this example explains enum with abstract function</p><p><strong>Enum with Constructor Parameter :</strong></p><p>Enum is used with constructor parameter …. hmmm, let me show you.</p><p><em>Class with constructor parameter :</em></p><pre>enum class AccountType(val discountPercentage: Int, val numberOfPercentage: Int) {<br>    // this is enum constructor parameters<br>    <em>BROZE</em>(10, 12),<br>    <em>SILVER</em>(11,12),<br>    <em>GOLD</em>(12,12),<br>    <em>PLATIUM</em>(14,23)<br><br><br>}</pre><p>Functions parameter can be accessed with getters in the main function</p><pre>fun main() {<br><br>    val value = AccountType.valueOf(&quot;Platium&quot;.<em>toUpperCase</em>())<br>    <em>println</em>(&quot;This is value  $value&quot;)<br>    <em>println</em>(&quot;This is value  ${value.discountPercentage}&quot;)<br>    <em>println</em>(&quot;This is value  ${value.numberOfPercentage}&quot;)<br><br><br>}</pre><p><strong>Iteration over Enum in Kotlin :</strong></p><p>Enums can be iterating over every override function with loops</p><pre>enum class IteratingAbstractAccountType() {<br><br>    // implementing abstract function in a enum<br>    <em>BROZE </em>{<br>        override fun calculateDiscountpercentage() = 5<br>    },<br>    <em>SILVER </em>{<br>        override fun calculateDiscountpercentage() = 10<br>    },<br>    <em>GOLD </em>{<br>        override fun calculateDiscountpercentage() = 11<br>    },<br>    <em>PLATIUM </em>{<br>        override fun calculateDiscountpercentage() = 12<br>    };</pre><pre>    abstract fun calculateDiscountpercentage(): Int<br>}</pre><p><em>Main functions using loop</em></p><pre>fun main() {<br>    IteratingAbstractAccountType.values().<em>forEach </em><strong>{<br>        </strong><em>println</em>(<strong>it</strong>.calculateDiscountpercentage())<br>    <strong>}<br></strong>}</pre><p><strong>Enums using Static function :</strong></p><p>Using a static functions is always a helpful and easy solution for using enums.</p><pre>enum class StaticMethodAccountType() {<br>    // implementing singleton pattern for getting account type<br>    <em>BROZE</em>,<br>    <em>SILVER</em>,<br>    <em>GOLD</em>,<br>    <em>PLATIUM</em>,<br>    <em>abc</em>;<br>    // acts like a static method like<br>    companion object {<br>        fun getAccountTypeByNAme(name: String) = valueOf(name.<em>toUpperCase</em>())<br>    }<br><br>}</pre><pre>fun main() {<br>    val fromApi = &quot;Platium&quot;<br>    val accountType = StaticMethodAccountType.getAccountTypeByNAme(fromApi)<br>    <em>println</em>(accountType)<br><br>    // when working with exhausted approach to work with.. else  keyword......<br>    when (accountType) {<br>        StaticMethodAccountType.<em>PLATIUM </em>-&gt; {<br>            <em>println</em>(&quot;this is my value&quot;)<br>        }<br>    }<br><br><br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33be5d633f2f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing in Android]]></title>
            <link>https://medium.com/@muhammadb159/testing-in-android-de5d64d30533?source=rss-79b956899184------2</link>
            <guid isPermaLink="false">https://medium.com/p/de5d64d30533</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Muhammad Bilal]]></dc:creator>
            <pubDate>Mon, 13 Sep 2021 05:13:12 GMT</pubDate>
            <atom:updated>2021-09-13T05:13:12.429Z</atom:updated>
            <content:encoded><![CDATA[<p>Testing your own code is really a code practice these days, developing a mobile application for android with the test-driven approach is a new thing in the market and can save you from a lot of problems before getting your application into the hands of quality assurance.</p><p><strong>Type of testing :</strong></p><p>There are 3 types of testing for android.</p><ol><li>Unit testing.</li><li>Instrumental testing.</li><li>Ui testing.</li></ol><p>let me explain the difference in each of them in detail</p><p><strong>Unit Testing :</strong></p><p>Unit testing is testing that will totally test your logic for a function, it does testing only on your personal computer and requires JVM for testing. It does not require any instrument or device for testing. that is why this test is very fast. You can write 1000’s of tests that will execute in few seconds.</p><p><strong>Unit Testing tools :</strong></p><p>Unit testing can be done by using <strong>JUNIT5 </strong>and <strong>mockito.</strong></p><p><strong>Instrumental Testing:</strong></p><p>Instrumental testing requires a device for testing purposes, instrumental testing is also used for android specific testing using a device or emulator.</p><p><strong>Instrumental testing tools :</strong></p><p>Instrumental testing can be done by using <strong>JUNIT4</strong> and <strong>mockito.</strong></p><p><strong>UI Testing :</strong></p><p>UI testing requires a device for testing, it is different from instrumental testing as it only checks to assert logic for UI visibility and testing UI correctness on navigating different screens in the mobile applications.</p><p><strong>UItesting tools :</strong></p><p>Instrumental testing can be done by using<strong> Expresso lib.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de5d64d30533" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin by Bilal — Creating Class]]></title>
            <link>https://medium.com/@muhammadb159/kotlin-by-bilal-creating-class-18db0cacbc6c?source=rss-79b956899184------2</link>
            <guid isPermaLink="false">https://medium.com/p/18db0cacbc6c</guid>
            <category><![CDATA[kotlin-conventions]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kotlin-beginners]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Muhammad Bilal]]></dc:creator>
            <pubDate>Sat, 11 Sep 2021 10:01:03 GMT</pubDate>
            <atom:updated>2021-09-11T10:01:03.082Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kotlin by Bilal — Creating Class</h3><p>Creating class is very simple in Kotlin</p><p>Primary Class :</p><p>Every class that owns an object is called the primary class.</p><p><strong>Example :</strong></p><p>This is a simple user class, you cannot see the constructor keyword or any constructor because kotlin does that for you.</p><pre>class User {<br>    val name: String? = null<br>    var age: String? = null<br>    var degree: String? = null<br>    var job: String? = null<br>}</pre><p><em>main class</em></p><pre>fun main() {<br>    var user = User()<br><br>    user.degree = &quot;Computer Science&quot;<br>    user.age = &quot;28&quot;<br>    user.job = &quot;Software Engineer&quot;<br><br>}</pre><p>we can access all the internal and private remember for a class, but cannot access the getter of a val variable and private variable.</p><p><strong>Constructor for class</strong> :</p><p>We can have a primary constructor for a class with or without using the constructor keyword, as you can see in the above example.</p><p><em>let me give you an example for a constructor using the </em><strong><em>constructor</em></strong><em> keyword </em>:</p><pre>class User constructor( myname  : String ) {<br>    var name: String? = myname<br>    var age: String? = null<br>    var degree: String? = null<br>    var job: String? = null<br>}</pre><p><em>main class</em></p><pre>fun main() {<br>    var user = User(&quot;Bilal&quot;)<br><br>    user.degree = &quot; Computer Science&quot;<br>    user.age = &quot;28&quot;<br>    user.job = &quot;Software Engineer&quot;<br><br>}</pre><p>there is one more magic creating kotlin constructors i.e you can also declare variables in class using the constructor.</p><p><em>Using the same example :</em></p><pre>class User constructor( var myname  : String ) {<br><br>    var age: String? = null<br>    var degree: String? = null<br>    var job: String? = null<br>}</pre><pre>fun main() {<br>    var user = User(&quot;Bilal&quot;)<br><br>    user.myname = &quot;Muhammad Bilal&quot;<br>    user.degree = &quot; Computer Science&quot;<br>    user.age = &quot;28&quot;<br>    user.job = &quot;Software Engineer&quot;<br><br>}</pre><p><em>you can see </em><strong><em>var </em></strong><em>keyword is used with a variable in the constructor to initialize the variable.</em></p><p><strong>Init </strong>:</p><p>Init is an additional thing in kotlin, init gets called after the primary constructor.</p><p><em>Example </em>:</p><pre>class UserMultiple(var firstName: String = &quot;&quot;, var lastName: String = &quot;&quot;, var isPlatium: Boolean) {<br><br>    init {<br>        <em>println</em>(&quot;Init $firstName $lastName $isPlatium&quot;)<br>    }<br>}</pre><p><strong>Multiple Constructor calling </strong>:</p><p>Multiple constructors are just like the chaining of constructors for kotlin class, Secondary constructors can be called by taking the value of the primary constructors and you can also define default value for parameter declared and initialized in the secondary constructor.</p><p><em>let me explain with an example </em>:</p><pre>class UserMultiple(var firstName: String = &quot;&quot;, var lastName: String = &quot;&quot;, var isPlatium: Boolean) {<br>      constructor(firstName: String, lastName: String) : this(firstName, lastName, false) {<br>        <em>println</em>(&quot;Calling Secondary Constructor $firstName $lastName $isPlatium&quot;)<br>    }<br>}<br>fun main() {  <br>  UserMultiple(&quot;Safina&quot;, &quot;Bilal&quot;)<br>}</pre><p>you can see this keyword with the secondary constructor, which required parameters from a primary constructor.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18db0cacbc6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>