<?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 Kenan HAS on Medium]]></title>
        <description><![CDATA[Stories by Kenan HAS on Medium]]></description>
        <link>https://medium.com/@KenanHas?source=rss-d3e0fc0c699d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qYF4mXJv_kIV6Oh6uAekgg.jpeg</url>
            <title>Stories by Kenan HAS on Medium</title>
            <link>https://medium.com/@KenanHas?source=rss-d3e0fc0c699d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 00:54:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@KenanHas/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[Collections in Kotlin]]></title>
            <link>https://medium.com/@KenanHas/collections-in-kotlin-6efa85cd60fe?source=rss-d3e0fc0c699d------2</link>
            <guid isPermaLink="false">https://medium.com/p/6efa85cd60fe</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[lists]]></category>
            <category><![CDATA[maps]]></category>
            <category><![CDATA[collection]]></category>
            <dc:creator><![CDATA[Kenan HAS]]></dc:creator>
            <pubDate>Wed, 03 Sep 2025 05:24:35 GMT</pubDate>
            <atom:updated>2025-09-03T05:36:04.664Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will provide information about the following topics:</p><p>1- What are Collections and why do we need them?</p><p>2- Types of Collections</p><p>3- What are the differences between Arrays and Collections?</p><p>4- Frequently Used Functions in Collections</p><h4>1- What are Collections and why do we need them?</h4><p>In Kotlin, collections are data structures used to hold multiple pieces of data together and perform operations on them easily, such as accessing, sorting, or filtering.</p><ol><li>Most real-world problems involve processing multiple data points together. For example:</li></ol><ul><li>A user’s favorite books,</li><li>Items in a shopping cart,</li><li>A list of users returned from a server…</li></ul><p>In such cases, storing each piece of data in a separate variable would be both complex and prone to errors:</p><pre>val user1 = &quot;James&quot;<br>val user2 = &quot;Mary&quot;<br>val user3 = &quot;Michael&quot;<br>//Bad practice! </pre><pre>val users = listOf(&quot;James&quot;, &quot;Mary&quot;, &quot;Michael&quot;) //Good practice!</pre><p>2. The ability to perform bulk operations on data</p><p>Collections allow us to process data in a bulk manner instead of one by one:</p><pre>val users = listOf(&quot;James&quot;, &quot;Mary&quot;, &quot;Michael&quot;)<br>val uppercaseUsers = users.map { it.uppercase() }</pre><p>This way, data can be:</p><ul><li>Filtered</li><li>Transformed</li><li>Sorted</li><li>Grouped</li></ul><p>3. Performance and Convenience</p><p>When dealing with data, collections:</p><ul><li>Optimize memory usage</li><li>Allow more operations to be performed with less code</li></ul><h4>2- Types of Collections</h4><p>A collection usually contains objects of the same type (and their subtypes). The objects in a collection are called elements or items. Kotlin allows you to manage collections regardless of the exact type of objects stored within them. In other words, adding a String to a List is done in the same way as adding an Int or a user-defined class. For this reason, the Kotlin Standard Library provides generic interfaces, classes, and functions to create, populate, and manage collections of any type. In Kotlin, collections are divided into three basic groups: List, Set, and Map.</p><p>The relationship between the element sequence number, index, and value is shown in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d2zNwWnCrGnMv_0GzdSxwA.png" /><figcaption>Elements in Collection</figcaption></figure><p>For each collection type, a pair of interfaces is defined:</p><ul><li>A read-only interface that provides access operations for collection elements.</li><li>A mutable interface that extends the corresponding read-only interface and allows for write operations (adding, removing, updating) to the collection’s elements.</li></ul><p>A mutable collection doesn’t need to be defined with <strong>var</strong>. Even if the collection is defined with <strong>val</strong>, write operations can still be performed. The advantage of defining mutable collections with <strong>val</strong> is to prevent the reference of the collection itself from being changed. As your code grows and becomes more complex, preventing references from being accidentally changed becomes even more important. For a safer and more robust code structure, use <strong>val</strong> as much as possible. If you try to reassign a <strong>val</strong> collection, you will get a compilation error.</p><pre>val numbers = mutableListOf(1,2,3,4)<br>numbers.add(5)   // this is OK<br>println(numbers)  //output: [1,2,3,4,5]<br>//numbers = mutableListOf(6,7)      // compilation error</pre><p><strong>2.1 List</strong></p><p>A <strong>List</strong> is an ordered collection where elements are accessed by their indices. Being ordered means that the elements in a <strong>List</strong> are preserved in the order they were added, and this order never changes. This ensures that each element has a unique position (index). Elements can appear more than once within a <strong>List</strong>. Indices start from zero (the index of the first element) and go up to lastIndex, which is equal to the expression <strong>(list.size - 1)</strong>.</p><p>A phone number can be given as an example of a list: it’s a group of digits, their order is important, and they can be repeated.</p><pre>val students = listOf(&quot;John&quot;, &quot;Mary&quot;, &quot;Peter&quot;, &quot;Jane&quot;)<br><br>println(&quot;Number of elements in the list: ${students.size}&quot;)<br>println(&quot;First element of the list: ${students.first()}&quot;)<br>println(&quot;Last element of the list: ${students.last()}&quot;)<br>println(&quot;Is &#39;Mary&#39; in the list?: ${students.contains(&quot;Mary&quot;)}&quot;)<br>println(&quot;What is the index of &#39;Mark&#39;?: ${students.indexOf(&quot;Mark&quot;)}&quot;)<br><br>/*Output:<br>Number of elements in the list: 4<br>First element of the list: John<br>Last element of the list: Jane<br>Is &#39;Mary&#39; in the list?: true<br>What is the index of &#39;Mark&#39;?: -1<br>*/</pre><p>With mutableListOf, you can add, remove, or update elements while preserving the list&#39;s type.</p><pre>val numbers = mutableListOf&lt;Int&gt;(1,3,5,7,9)<br>numbers[1] = 2<br>numbers.remove(9)<br>println(numbers)//[1, 2, 5, 7]</pre><p>The code for the mutableListOf structure in the Collections.kt class is as follows:</p><pre>public fun &lt;T&gt; mutableListOf(vararg elements: T): MutableList&lt;T&gt; =<br>    if (elements.size == 0) ArrayList() else ArrayList(ArrayAsCollection(elements, isVarargs = true))</pre><p>We can also use the MutableList structure to create a mutable list. In fact, if we look at the code above, the return type of the mutableListOf function is a MutableList interface.</p><pre>val numbers = MutableList&lt;Int&gt;(3, {index-&gt;<br>     index * 5<br>  })<br>println(numbers) //[0, 5, 10] <br></pre><p>Looking at the example above, when we created the numbers list with MutableList, the list&#39;s size was required. Also, MutableList is a higher-order function. Therefore, its second parameter contains a function. A mapping operation is performed on the indices of the list&#39;s elements within the curly braces. Below is the Java code for the MutableList function in the Collections.kt class.</p><pre>public inline fun &lt;T&gt; MutableList(size: Int, init: (index: Int) -&gt; T): MutableList&lt;T&gt; {<br>    val list = ArrayList&lt;T&gt;(size)<br>    repeat(size) { index -&gt; list.add(init(index)) }<br>    return list<br>}</pre><p><strong>2.2 Set</strong></p><p>A Set is a collection of unique elements. In other words, it’s a group of objects that don’t contain repeating elements. Generally, the order of elements within a Set is not important.</p><p>For example, in a team, each player has their own jersey number. There cannot be two players with the same jersey number. This reflects the principle of uniqueness, which is the most important feature of the Set structure. Each element can only be present once. The order in which the players take the field or the order of their names on the locker room list is not important. What&#39;s important is which players are on the team. Similarly, Set’s are also unordered. The order in which elements are added or their position isn&#39;t important; only whether or not the element is in the set matters.</p><pre>// Create a Set of student names<br>val studentNames = setOf(&quot;Alice&quot;, &quot;Bob&quot;, &quot;Charlie&quot;, &quot;Alice&quot;)<br><br>println(&quot;Original Set: $studentNames&quot;)<br>// Output: Original Set: [Alice, Bob, Charlie]<br><br>// Check if a specific name is in the Set<br>println(&quot;Is Bob in the Set? ${studentNames.contains(&quot;Bob&quot;)}&quot;)<br>// Output: Is Bob in the Set? true<br><br>// The size of the Set reflects only unique elements<br>println(&quot;Number of unique students: ${studentNames.size}&quot;)<br>// Output: Number of unique students: 3</pre><p>In Kotlin, mutableSetOf is used to create a mutable Set. A regular Set (created with setOf) cannot have its elements modified, added, or removed once it&#39;s defined. However, a Set created with mutableSetOf supports operations like adding (add) and removing (remove) elements. Just like setOf, a mutableSet also contains unique elements and is unordered.</p><pre>// Create a mutable set of student IDs<br>val studentIDs = mutableSetOf(101, 105, 110, 101)<br><br>println(&quot;Initial student IDs: $studentIDs&quot;)<br>// Output: Initial student IDs: [101, 105, 110]<br>// The duplicate ID (101) is automatically ignored.<br><br>// Add a new student ID<br>studentIDs.add(115)<br>println(&quot;After adding ID 115: $studentIDs&quot;)<br>// Output: After adding ID 115: [101, 105, 110, 115]<br><br>// Remove an existing student ID<br>studentIDs.remove(105)<br>println(&quot;After removing ID 105: $studentIDs&quot;)<br>// Output: After removing ID 105: [101, 110, 115]<br><br>// Attempt to add a duplicate ID<br>val addedSuccessfully = studentIDs.add(115)<br>println(&quot;Is 115 added again? $addedSuccessfully&quot;)<br>// Output: Is 115 added again? false<br>println(&quot;Current student IDs: $studentIDs&quot;)<br>// Output: Current student IDs: [101, 110, 115]<br>// The set remains unchanged because 115 already exists.</pre><p>The code for the mutableSetOf structure in the Sets.kt class is as follows:</p><pre>public fun &lt;T&gt; mutableSetOf(vararg elements: T): MutableSet&lt;T&gt; = elements.toCollection(LinkedHashSet(mapCapacity(elements.size)))</pre><p><strong>2.3 Map</strong></p><p>A Map is a collection of key-value pairs. The keys are unique, and each one corresponds to exactly one value. The values, however, can be repeated.</p><p>As an example, consider a system that stores country-capital information. In a Map, each country name would be the <strong>key</strong>, and the corresponding capital would be the <strong>value</strong>. When you need to find a capital, you just provide the country name (the <strong>key</strong>), and the system instantly retrieves the corresponding capital (the <strong>value</strong>). This is much faster and more efficient than searching through a list.</p><pre>// Create a Map containing country-capital pairings<br>val countryCapitals = mapOf(<br>    &quot;Turkey&quot; to &quot;Ankara&quot;,<br>    &quot;France&quot; to &quot;Paris&quot;,<br>    &quot;Japan&quot; to &quot;Tokyo&quot;,<br>    &quot;Germany&quot; to &quot;Berlin&quot;<br>)<br><br>// Get the value using the &quot;Germany&quot; key<br>val capitalOfGermany = countryCapitals[&quot;Germany&quot;]<br>println(&quot;Capital of Germany: $capitalOfGermany&quot;)<br>// Output: Capital of Germany: Berlin<br><br>// List the size of the Map and all its keys<br>println(&quot;Number of countries: ${countryCapitals.size}&quot;) //4<br>println(&quot;All countries: ${countryCapitals.keys}&quot;) //All countries: [Turkey, France, Japan, Germany]<br><br>// List all the values of the Map<br>println(&quot;All capitals: ${countryCapitals.values}&quot;) //All capitals: [Ankara, Paris, Tokyo, Berlin]<br><br>// Check if a value corresponding to a key exists<br>println(&quot;Does the map contain &#39;Tokyo&#39;? ${countryCapitals.containsValue(&quot;Tokyo&quot;)}&quot;)<br>// Output: Does the map contain &#39;Tokyo&#39;? true</pre><p>In Kotlin, as its name suggests, mutableMapOf is used to create a mutable Map. Unlike Map’s created with mapOf, you can later add new key-value pairs, update existing ones, or delete them from the collection you create with mutableMapOf.</p><pre> // Create a mutable Map to store order IDs and their statuses.<br>    val orderStatuses = mutableMapOf(<br>        101 to &quot;Processing&quot;,<br>        102 to &quot;Payment Failed&quot;<br>    )<br><br>    println(&quot;Current orders: $orderStatuses&quot;)<br>    // Output: Current orders: {101=Processing, 102=Payment Failed}<br><br>    // A new order with ID 103 comes in. We add it to the map.<br>    orderStatuses[103] = &quot;Processing&quot;<br>    println(&quot;Updated orders: $orderStatuses&quot;)<br>    // Output: Updated orders: {101=Processing, 102=Payment Failed, 103=Processing}<br><br>    // Order 101 has been shipped, so we update its status.<br>    orderStatuses[101] = &quot;Shipped&quot;<br>    println(&quot;Updated orders: $orderStatuses&quot;)<br>    // Output: Updated orders: {101=Shipped, 102=Payment Failed, 103=Processing}<br><br>    // Order 102 was cancelled, so we remove it from the map.<br>    val removedStatus = orderStatuses.remove(102)<br>    println(&quot;Removed order status: $removedStatus&quot;)<br>    // Output: Removed order status: Payment Failed<br>    println(&quot;Final orders: $orderStatuses&quot;)<br>    // Output: Final orders: {101=Shipped, 103=Processing}</pre><p>The code for the mutableMapOf structure in the Maps.kt class is as follows:</p><pre>public fun &lt;K, V&gt; mutableMapOf(vararg pairs: kotlin.Pair&lt;K, V&gt;): kotlin.collections.MutableMap&lt;K, V&gt; { /* compiled code */ }</pre><h4>3- What are the differences between Arrays and Collections?</h4><p><strong>Array</strong>: An Array is a fixed-size data structure. Its size cannot be changed once it’s created. It can hold both primitive types (Int, Double, etc.) and object types..</p><p><strong>Collections (List, Set, Map)</strong>: Collections are more flexible structures. Their sizes can change dynamically (for mutable ones).</p><p><strong>3.1 Size</strong></p><p><strong>Array</strong>: Its size is fixed. When an Array is created, its size is determined and cannot be changed later. To add or remove a new element, you have to create a new Array.</p><pre>val numbers = arrayOf(1, 2, 3)<br>numbers[0] = 10  // OK (the value is changed)<br>// numbers += 4   // The size cannot be changed!</pre><p><strong>Collections</strong>: The size can change, especially in Mutable types.</p><pre>val list = mutableListOf(1, 2, 3)<br>list.add(4)      // An element can be added<br>list.remove(2)   // An element can be removed</pre><p><strong>3.2 Performance</strong></p><p><strong>Array</strong>: As a lower-level structure, it’s generally faster than collections in terms of performance. It’s especially ideal for fixed-size, frequently accessed data.</p><p><strong>Collections:</strong> Due to their dynamic size, operations like adding or removing elements may require more processing power. They can also use slightly more memory than an Array.</p><h4>4- Frequently Used Functions in Collections</h4><p><strong>4.1 Filter</strong></p><p>The <strong>filter</strong> function is used to filter a collection&#39;s elements based on a specific condition. This function returns a new collection that consists of all the elements that satisfy the condition. The original collection is not modified.</p><pre>val numbers = listOf(1, 2, 3, 4, 5, 6)<br>val evenNumbers = numbers.filter { it % 2 == 0 } <br>// evenNumbers is [2, 4, 6]</pre><p>In this example, we created a new list called evenNumbers by filtering the even numbers in the numbers list.</p><p><strong>4.2 Map</strong></p><p>The <strong>map</strong> function is used to transform each element in a collection and create a new collection from the transformed elements.</p><pre>val names = listOf(&quot;james&quot;, &quot;robert&quot;, &quot;andrew&quot;)<br>val capitalizedNames = names.map { it.capitalize() }<br>// capitalizedNames is [James, Robert, Andrew]</pre><p>In this example, we created the capitalizedNames list by capitalizing the first letter of each name in the names list.</p><p><strong>4.3 Zip</strong></p><p>The <strong>zip</strong> function merges the elements of two collections to create a new list of pairs (Pair). Each pair consists of an element from the first collection and the corresponding element from the second. The size of the resulting list is limited by the size of the shorter collection.</p><pre>val names = listOf(&quot;James&quot;, &quot;Robert&quot;, &quot;Andrew&quot;)<br>val ages = listOf(30, 25, 35)<br><br>val combined = names.zip(ages)<br>// combined is [(James, 30), (Robert, 25), (Andrew, 35)]</pre><p>In this example, we created a Pair list by combining the elements from the names and ages lists.</p><p><strong>4.4 Group</strong></p><p>The <strong>groupBy</strong> function is used to group a collection based on a specific condition. As a result, it returns a Map where the <strong>key</strong> is the grouping condition and the <strong>value</strong> is a list of elements that satisfy that condition.</p><pre>val fruits = listOf(&quot;apple&quot;, &quot;banana&quot;, &quot;apricot&quot;, &quot;kiwi&quot;, &quot;avocado&quot;)<br>val groupedByFirstLetter = fruits.groupBy { it.first() }<br><br>/*<br>groupedByFirstLetter is {<br>    a=[apple, apricot, avocado], <br>    b=[banana], <br>    k=[kiwi]<br>}<br>*/</pre><p>In this example, we grouped the fruits by their first letter.</p><p><strong>4.5 Order</strong></p><p>The <strong>sorted</strong> function sorts a collection&#39;s elements according to their natural order. The <strong>sortedBy</strong> function, on the other hand, allows you to sort elements based on a specific property. Both functions return a new sorted list.</p><pre>val numbers = listOf(5, 2, 8, 1, 9)<br>val sortedNumbers = numbers.sorted()<br>// sortedNumbers is [1, 2, 5, 8, 9]<br><br>val users = listOf(<br>    User(&quot;Charles&quot;, 30),<br>    User(&quot;Matthew&quot;, 25),<br>    User(&quot;Paul&quot;, 35)<br>)<br><br>val sortedUsersByAge = users.sortedBy { it.age }<br><br>/*<br>sortedUsersByAge is [<br>    User(name=Matthew, age=25), <br>    User(name=Charles, age=30), <br>    User(name=Paul, age=35)<br>]<br>*/<br><br>data class User(val name: String, val age: Int)</pre><p>In this example, we first sorted the numbers naturally using sorted(). Then, we sorted the User objects by their age property using sortedBy.</p><p><a href="https://kotlinlang.org/docs/collections-overview.html#collections-overview.md">Collections overview | Kotlin</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6efa85cd60fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enum Classes in Kotlin]]></title>
            <link>https://medium.com/@KenanHas/enum-classes-in-kotlin-c3a3b999326c?source=rss-d3e0fc0c699d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3a3b999326c</guid>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[enum-class]]></category>
            <dc:creator><![CDATA[Kenan HAS]]></dc:creator>
            <pubDate>Tue, 04 Feb 2025 18:12:43 GMT</pubDate>
            <atom:updated>2025-02-04T18:12:43.766Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FK_S0qfJaBmUtJnIy97d7A.jpeg" /></figure><h3>Introduction</h3><p>Hello, Kotlin developers! In this article, I will talk about why we use enum classes in Kotlin and their features. Enjoy reading!</p><h3>What is an Enum Class?</h3><p>An enum class is a structure used to represent a specific and fixed group of values. For example, if we have a situation with limited options (such as the months of the year: January, February, March…), we can use an enum class to define them in a more organized and secure way. Enum classes also improve code readability. Below, I first wanted to give an example of how we can group data without using an enum class. As you can see, in our code, the months and their corresponding numerical values are provided.</p><pre>class Months{<br>    val january = 1<br>    val february = 2<br>    val march = 3<br>    val april = 4<br>    val may = 5<br>    val june = 6<br>    val july = 7<br>    val august = 8<br>    val september = 9<br>    val october = 10<br>    val november = 11<br>    val december = 12<br>}</pre><h3>Features of Enum Classes</h3><p><strong>1-</strong> Enum classes can use all visibility modifiers (public, internal, and private) except for <strong>protected</strong>. The <strong>protected</strong> visibility modifier cannot be applied to classes anyway.</p><p><strong>2- </strong>Enum classes have both primary and secondary constructors. Since they have a primary constructor, they also include <strong>init</strong> blocks.</p><pre>enum class Months constructor(){<br>    JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER;<br><br>    init{<br><br>    }<br><br>    constructor(season:String):this()<br><br>}</pre><p><strong>Note:</strong> The code block above is provided as an example for points 1 and 2. The structures we group within an enum class are called <strong>enum constants</strong>. One important point to note in the code is that the IDE requires a <strong>semicolon</strong> after the last enum constant.</p><p><strong>3- </strong>Enum classes cannot inherit from an open or abstract class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*ymjbCJIPgv7TEB15VGp3LQ.png" /></figure><p><strong>4-</strong> Enum classes can implement interfaces.</p><pre>enum class Months constructor() :Time{<br>    JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER;<br><br>}<br><br>interface Time{<br><br>}</pre><p><strong>5- </strong>Since enum classes cannot have the <strong>open</strong> keyword, they cannot be inherited by another class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*UL3CbG1F1HFQBJdLVCFPzQ.png" /></figure><p><strong>6-</strong> Functions can be defined within enum classes.</p><pre>enum class Months {<br>    JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER;<br><br>    fun printMonth(){<br>        <br>    }<br>}</pre><p><strong>7- </strong>We can use a function defined as abstract inside an enum class. Therefore, we do not only use the abstract keyword in abstract classes. Below, we have created an abstract function inside an enum class named ‘Months’. As shown in the image, all the enum constants are underlined in red.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gv6M5eyK1H47V3cCb6ba3A.png" /></figure><p>When we examine the error above, we see that the enum constants are required to override this abstract function. When we click on the ‘Implement members’ option in the warning, we get the following result.</p><pre>enum class Months {<br>    JANUARY {<br>        override fun getSeason() {<br>            TODO(&quot;Not yet implemented&quot;)<br>        }<br>    }, FEBRUARY {<br>        override fun getSeason() {<br>            TODO(&quot;Not yet implemented&quot;)<br>        }<br>    }, MARCH {<br>        override fun getSeason() {<br>            TODO(&quot;Not yet implemented&quot;)<br>        }<br>    }, APRIL {<br>        override fun getSeason() {<br>            TODO(&quot;Not yet implemented&quot;)<br>        }<br>    }, MAY {<br>        override fun getSeason() {<br>            TODO(&quot;Not yet implemented&quot;)<br>        }<br>    }, JUNE {<br>        override fun getSeason() {<br>            TODO(&quot;Not yet implemented&quot;)<br>        }<br>    }, JULY {<br>        override fun getSeason() {<br>            TODO(&quot;Not yet implemented&quot;)<br>        }<br>    }, AUGUST {<br>        override fun getSeason() {<br>            TODO(&quot;Not yet implemented&quot;)<br>        }<br>    }, SEPTEMBER {<br>        override fun getSeason() {<br>            TODO(&quot;Not yet implemented&quot;)<br>        }<br>    }, OCTOBER {<br>        override fun getSeason() {<br>            TODO(&quot;Not yet implemented&quot;)<br>        }<br>    }, NOVEMBER {<br>        override fun getSeason() {<br>            TODO(&quot;Not yet implemented&quot;)<br>        }<br>    }, DECEMBER {<br>        override fun getSeason() {<br>            TODO(&quot;Not yet implemented&quot;)<br>        }<br>    };<br><br>   abstract fun getSeason()<br>}</pre><p>When we look at the output above, we can see that each enum constant overrides the abstract function defined in the enum class. From this, we can make the following assumption: If these enum constants are required to override the abstract function defined in their enum class, we can think of each enum constant as an individual class that inherits from the enum class they belong to.</p><p><strong>Note: In the upcoming code examples, not all enum constants will be shown as above, because they take up too much space.</strong></p><p>When we decompile the above code into Java, we can see that the enum constants are actually static final classes in Java. Additionally, it is evident that the enum constants inherit from the enum class they belong to. The following code shows the decompiled Java version of the APRIL enum constant.</p><pre>static final class APRIL extends Months {<br>   APRIL(String $enum$name, int $enum$ordinal) {<br>      super((DefaultConstructorMarker)null);<br>   }<br><br>   public void getSeason() {<br>      String var1 = &quot;Not yet implemented&quot;;<br>      throw new NotImplementedError(&quot;An operation is not implemented: &quot; + var1);<br>   }<br>}</pre><p>In Java, if a structure is defined with the <strong>static </strong>keyword, its name is usually written in uppercase letters. Therefore, the reason we generally write enum constants in uppercase in Kotlin is because of this convention. However, if we wanted to, we could also write them in lowercase.</p><p><strong>8- </strong>When we add a primary constructor parameter named monthNumber to the Months enum class, the enum constants start giving errors. The reason for this is that enum constants actually inherit from the enum class they belong to, and if the enum class has a primary constructor, they must assign a value to the parameter in that constructor. If a parameter like monthNumber is defined but the enum constants do not provide a value for it, the assigned value becomes uncertain, causing the compiler to throw an error. To resolve this error, each enum constant must be assigned a value for monthNumber.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*dkXXEIeqsxexNFpEDwZtoA.png" /></figure><pre>enum class Months(val monthNumber: Int) {<br>    JANUARY(1) {<br>        override fun getSeason() {<br>            TODO(&quot;Not yet implemented&quot;)<br>        }<br>    }, FEBRUARY(2) {<br>        override fun getSeason() {<br>            TODO(&quot;Not yet implemented&quot;)<br>        }<br>    }, MARCH(3) {<br>        override fun getSeason() {<br>            TODO(&quot;Not yet implemented&quot;)<br>        }<br>    };<br><br>   abstract fun getSeason()<br>}</pre><p>In the code above, we assigned the monthNumber<strong> </strong>values to the primary constructors of the enum constants, and the error was resolved.</p><p><strong>9-</strong> Enum classes have functions such as <strong>entries</strong>. The <strong>entries</strong> function returns the constants of that enum class as an array.</p><pre>fun main() {<br>    println(&quot;${Months.entries}&quot;)<br>}<br>//Output: [JANUARY, FEBRUARY, MARCH]</pre><p>The <strong>valueOf() </strong>method takes any of the enum constants as a String parameter and returns the value of that constant.</p><pre>fun main() {<br>    println(&quot;${Months.valueOf(&quot;FEBRUARY&quot;)}&quot;)<br>}<br>//Output: FEBRUARY</pre><p>If the valueOf() function does not find any enum constant matching the given String parameter, the IDE throws an <strong>IllegalArgumentException </strong>error.</p><p>With the valueOf() function, we can access the member variables of that enum constant. For example, in the code below, we accessed the value of the monthNumber member variable of the “JANUARY” enum constant.</p><pre>fun main() {<br>    println(&quot;${Months.valueOf(&quot;JANUARY&quot;).monthNumber}&quot;)<br>}<br>//Output: 1</pre><p><strong>10-</strong> Enum constants also have properties named <strong>name </strong>and <strong>ordinal</strong> (you can check the constructor of the “APRIL” enum constant in the Java class from item 7). The <strong>name </strong>property directly returns the name of the enum constant, while <strong>ordinal </strong>indicates the position of the enum constant within the enum class. The important point to note here is that the order of enum constants starts from zero, just like in arrays.</p><pre>fun main() {<br>    println(&quot;${Months.MARCH.name}&quot;)<br>    println(&quot;${Months.MARCH.ordinal}&quot;)<br>}<br>//Output: <br>MARCH<br>2</pre><p>Since enum constants are in the form of a static class, we can access their functions and properties without creating objects. For example, Months.March.name</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3a3b999326c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[REST (Representational State Transfer) Nedir?]]></title>
            <link>https://medium.com/@KenanHas/rest-representational-state-transfer-nedir-d917d8010b0a?source=rss-d3e0fc0c699d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d917d8010b0a</guid>
            <category><![CDATA[http-rest]]></category>
            <dc:creator><![CDATA[Kenan HAS]]></dc:creator>
            <pubDate>Wed, 02 Nov 2022 08:41:22 GMT</pubDate>
            <atom:updated>2022-11-02T08:41:22.493Z</atom:updated>
            <content:encoded><![CDATA[<p>Dağıtık bir sistem yapısı ile web protokoller ve teknolojileri üzerinde gerçekleştirilir. Kullanıcı ile sunucu arasında daha hızlı bir şekilde iletişim gerçekleştirilmesi için kullanılan bir servis yapısıdır. Rest genellikle JSON veya XML gibi veri taşıma işlemleri gerçekleştirir. Rest protokolünü uygulayan web hizmetlerine RESTful web hizmetleri adı verilir.</p><h3>HTTP (Hyper Text Transfer Protocol) Nedir?</h3><p>HTTP internetteki web sayfalarını görüntülemek için kullanılan protokoldür. Dünyada en yaygın kullanılan protokoldür.</p><p><strong>HTTP Durum Kodları</strong></p><p>Bir web sitesine bazen bazı hatalar ile karşılaşabiliriz. Hatta bunlardan en çok bilineni 404 hatasıdır. Bilgisayarımız ile sunucuya ulaşmaya çalıştığımızda sunucu bizlere sayısal bir kod ile yanıtın durumunu gönderir. Bu gibi durum kodlarını 5 ayrı grupta inceleriz.</p><p>1xx — Bilgi</p><p>2xx — Başarı</p><p>3xx — Yönlendirme</p><p>4xx — Tarayıcı Hatası</p><p>5xx — Sunucu Hatası</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d917d8010b0a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java’da Interface Kavramı]]></title>
            <link>https://medium.com/@KenanHas/javada-interface-kavram%C4%B1-4bf2eda2d7b3?source=rss-d3e0fc0c699d------2</link>
            <guid isPermaLink="false">https://medium.com/p/4bf2eda2d7b3</guid>
            <dc:creator><![CDATA[Kenan HAS]]></dc:creator>
            <pubDate>Tue, 18 Oct 2022 18:14:10 GMT</pubDate>
            <atom:updated>2022-10-18T18:14:10.595Z</atom:updated>
            <content:encoded><![CDATA[<h3>📌Java’da Interface Kavramı</h3><p>🔷Bu yazımda interface nedir, neden kullanılır, class ve abstract class’tan farkı nedir gibi sorulara cevap bulabileceksiniz.</p><p>🔷Interface’in temel görevi referans tutmaktır. Referans tutarak polimorfizm yapısıyla birlikte sistemin sürekli güncel halde kalabilmesini sağlamaktadır. if programming dediğimiz karmaşık programlamadan bizi alıkoymaktadır. Aşağıda temel bir interface’in nasıl kurulduğu gösterilmiştir:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/1*ddkryirqPwPA1Tdr0uT6Fw.png" /><figcaption><strong>Şekil 1: Interface Kurulum Biçimi</strong></figcaption></figure><p>🔷Yukarıdaki görselde interface adı olan <strong>ICustomer </strong>ifadesinin başındaki “<strong>I</strong>” harfi o ifadenin bir interface olduğunu göstermektedir. Kullanımı zorunlu değildir fakat büyük projelerde farklı geliştiricilerin isme baktığı anda onun bir interface olduğunu anlaması daha kolay hale gelmektedir.</p><p>Interface, mantık ve kullanım açısından abstract class ve class yapılarına benzemektedir. Ancak temel farkları aşağıdaki gibidir:</p><blockquote>1. extends ve implements anahtar kelimeleri.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*rit87rw2aK2bZfX4xaCs2A.png" /><figcaption><strong>Şekil 2: extends Anahtar Kelimesi</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*WiD2r_DlQECu3byC8xcBCg.png" /><figcaption><strong>Şekil 3: implements Anahtar Kelimesi</strong></figcaption></figure><p>🔷Inheritance konusunda bir sub class (miras alan sınıf) bir base class’tan (miras veren sınıf) extends anahtar kelimesi ile yazılır. Interface konusunda ise bir class veya interface başka bir interface’e implements anahtar kelimesi ile ulaşır.</p><blockquote>2. Bir abstract class ve interface’te tanımlanmış metot tipleri</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/1*DuAfLV0NHVZ2cQqLo83UiA.png" /><figcaption><strong>Şekil 4: abstract Sınıfa Ait Metotlar</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/1*Roanz9_h6lx7LckLUeoTbQ.png" /><figcaption><strong>Şekil 5: implements’e Ait Metot</strong></figcaption></figure><p>🔷Şekil 4&#39;te görüldüğü üzere abstract bir class’ta kimi metotların gerçekleştirmesi varken (içi doluyken) kimi metotların içi boştur. İçi boş olan metotlar miras alan classlar tarafından override edilmek zorundadır. Şekil 5&#39;te ise interface’e ait sadece içi boş yani gerçekleştirmesi yapılmamış metot oluşturulabilir.</p><blockquote>3. implements ile extends anahtar kelimelerinden sonra kullanılabilecek ifade sayıları</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/1*s37L1BbtTH9Zn-kkapF3MQ.png" /><figcaption><strong>Şekil 6: extends Hatalı Kullanım</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*7d95-bRFSYdnh5c5RBmeqA.png" /><figcaption><strong>Şekil 7: Çoklu implements Kullanımı</strong></figcaption></figure><p>🔷Şekil 6&#39;daki gibi bir kullanım hataya sebep olacaktır. Ancak Şekil 7&#39;ye baktığımızda bir class birden fazla class’a implements edebilmektedir. İşte bu durum interfaceler’i abstract class’lardan ayıran en temel farktır.</p><p>✍Bir sonraki yazımda görüşmek dileğiyle …</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4bf2eda2d7b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Java’da Değer ve Referans Tipli Değişkenler]]></title>
            <link>https://medium.com/@KenanHas/javada-de%C4%9Fer-ve-referans-tipli-de%C4%9Fi%C5%9Fkenler-a6334763148d?source=rss-d3e0fc0c699d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6334763148d</guid>
            <dc:creator><![CDATA[Kenan HAS]]></dc:creator>
            <pubDate>Thu, 13 Oct 2022 19:59:43 GMT</pubDate>
            <atom:updated>2022-10-13T19:59:43.611Z</atom:updated>
            <content:encoded><![CDATA[<p>🔸 Bu yazımda sizlere Java’da yer alan değer ve referans tipli değişkenlerin ne olduğundan bahsedeceğim.</p><p>🔸Java programlama dilinde temel anlamda değer ve referans tipli olmak üzere iki adet değişken türü vardır. Değer tipli değişkenleri genelde aritmetik, karakter veya mantıksal işlemler için kullanırız. Değer tipli değişkenler, kendilerine atanan değerleri üzerinde tutarlar. Ancak sadece bir değeri üzerinde tutabilirler. Ancak aşağıdaki gibi bir kullanım söz konusu olabilir:</p><blockquote>int a = 4;</blockquote><blockquote>a=5;</blockquote><p>Yukarıdaki kullanımda a değişkeni anlık olarak sadece bir adet değer tutabilmektedir. İstenirse ilerleyen süreçte tutulan değer ezilerek yeni bir değer atanabilir.</p><p>🔸Değer tipli değişkenler toplamda 8 adettir. Bunlar aşağıda hazırlamış olduğum şemadaki gibidir:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*rhouiYlH1IAxlEw2_ThCDA.png" /><figcaption><strong>Şekil 1: Değer Tipli Değişkenler</strong></figcaption></figure><p>Yukarıdaki şemada da görüleceği üzere değer tipli değişkenler <strong>float, double, byte, short, int, long, boolean ve char</strong> olmak üzere 8 adettir. Integer tipte dört adet veri tipi olması aslında her bir tipin farklı boyutta değer tutabilmesinden kaynaklanmaktadır. Aşağıda hazırlamış olduğum tabloda bu dört tipin bellekte tuttuğu boyutlar verilmiştir:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*rlUIECHjlBUHCTf8NMdZWA.png" /><figcaption><strong>Tablo: integer Tipine Sahip Değişkenlerin Hafızada Tuttukları Değerler</strong></figcaption></figure><p>🔸Alt ve üst sınır o tipte tanımlanmış olan değişkenin maksimum ve minimum alabileceği değerleri göstermektedir. Burada üst sınırların alt sınırların mutlak değerinin bir eksiği gözükmesinin sebebi 0 (sıfır) değerinin de pozitif olarak düşünülmesidir. Örneğin byte olarak tanımlanmış bir değişken minimum -128, maksimum 127 değerini alabilir. Ancak bu sınırlar dışında bir değer ataması yapılırsa hata alınır.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*KXU5hDWiPFVCam4KXIIuSA.png" /><figcaption><strong>Şekil 2: byte Değişkeni Hatalı Kullanımı</strong></figcaption></figure><p>Şekil 2&#39; deki örnekte görüleceği üzere byte tipindeki bir değişkenin üst sınır değeri olan 127 değeri aşıldığı için IDE otomatik olarak hata vermektedir.</p><p>🔸Ondalıklı sayı tiplerinden olan float ve double tipleri de kendi aralarında noktadan sonra hafızada tutabildikleri basamak sayılarına göre ayrılmaktadır.</p><p>🔸Mantıksal tip olan boolean tipi true ve false olmak üzere iki değere sahip olabilir.</p><p>🔸Karakter tip olan char tipi ise ‘’ notasyonu içerisinde tek bir harf alabilir.</p><p>— — — — — — — — — — — — — BÖLÜM 2 — — — — — — — — — — — — —</p><p>🔸Bu bölümde de Java programlama dilinde ikinci tip değişken olan referans tiplerden söz edeceğiz. Referans tipli değişkenler birden fazla parçadan oluşurlar. Referans tipler birden fazla değer tipli değişkenlerden veya referans tiplerden oluşabilir. Bu durumda onların birden fazla parçaya sahip olabileceğini göstermektedir.</p><p>🔸Referans tipli değişkenler sınıflardan oluşmaktadır. Referans tipli değişkenler adı üstünde bir sınıfa adreslerini yönlendirip o adrese ait değer tipli değişkenlere (nesne değişkenleri) nesnesi aracılığıyla ulaşır. Böylece nesneye hafızada artık referansıyla erişim mümkün olmaktadır. Nesne temelde <strong>özelliğe (nesne değişkeni, field)</strong> ve <strong>davranışa (metot)</strong> sahiptir.</p><p>🔸Önceki bölümde değer tipli değişkenler sadece kendilerine atanan bir değeri tutabilirler demiştim. Ancak referans tipli değişkenlerin tuttuğu değer nesnenin adresidir.</p><p>✍Bir sonraki yazımda görüşmek dileğiyle …</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6334763148d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>