<?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 Hüseyin K. on Medium]]></title>
        <description><![CDATA[Stories by Hüseyin K. on Medium]]></description>
        <link>https://medium.com/@kicchi?source=rss-54616ba631f4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*b2gxrGXwf9hL4UPvs9zwXg.png</url>
            <title>Stories by Hüseyin K. on Medium</title>
            <link>https://medium.com/@kicchi?source=rss-54616ba631f4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 23:34:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kicchi/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[Full Java Course Document]]></title>
            <link>https://kicchi.medium.com/full-java-course-document-1c15f2413569?source=rss-54616ba631f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c15f2413569</guid>
            <category><![CDATA[java-tutorial]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[mentoring]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[online-courses]]></category>
            <dc:creator><![CDATA[Hüseyin K.]]></dc:creator>
            <pubDate>Wed, 10 Sep 2025 17:00:38 GMT</pubDate>
            <atom:updated>2025-09-10T17:32:32.004Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fRls0E34TkZcRUfdVF39JQ.png" /></figure><p>Sharing full Java Course content including homework and solutions in one well-organized custom document (500 pages).</p><p>🚀 Exciting News!</p><p>Over the past months, I’ve been preparing a comprehensive <strong>Java learning resource</strong> in both <strong>English</strong> and <strong>Turkish</strong>, along with access to a <strong>GitHub repository</strong> full of lessons and homework materials.</p><p>Some features of the doc;</p><ul><li>Real-life examples that make understanding easier and more relatable</li><li>Plenty of explained homework assignments to provide practice and reinforce learning</li><li>Detailed documentation (at around 500 pages) with all the code from lessons, enabling easy review — even during commutes without a computer</li><li>Interconnected examples and code across lessons to create a smooth transition between topics, including implicit reviews</li><li>Well-organized project structure containing all code as a single project, homework, and solutions, making it easy to locate topics</li><li>A single consolidated document instead of multiple fragmented ones, simplifying tracking and quick reviews</li></ul><p>Originally, I planned to publish this as a Udemy course, but I’ve decided instead to <strong>share it freely with the developer community</strong>. My goal is simple: to contribute, support, and help others grow on their Java journey.</p><p>📂 You can access both documents here:</p><ul><li><a href="https://drive.google.com/file/d/1cxRk1bEKSGpzwOeOMmJYX1bFjgFG0K9o/view?usp=sharing">English version</a></li><li><a href="https://drive.google.com/file/d/1SzMYiOHQeYLipJ78Qf2D_o8Tu7kO1e1z/view?usp=sharing">Turkish version</a></li></ul><p>The course material has been prepared according to specific readability standards to ensure it’s readable even on public transport. This way, you can save time by browsing the document even when you’re on the go.</p><p>💡 Each code example in the PDF can be opened directly on GitHub by clicking the corner link.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kRfaJ4gsP_XQvv1Sy3qT4w.png" /><figcaption>Click the link to open the code page on GitHub</figcaption></figure><p>💡You will see HOMEWORK ALERT in the page if there is a homework related to the lesson. See below;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5nToH-olkpZdx92v2pvK6g.png" /><figcaption>Homework indicator</figcaption></figure><p>💡When you click on that indicator, you will see your homework and its solution in separate files;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*37npaVH4VPCYAZKfu60JDA.png" /><figcaption>Homework and its solution</figcaption></figure><p>💡That way, you can also access my provided solutions for the homework after trying them yourself.</p><p>And since we’re already in the age of AI, you know what to do whenever you get stuck. 😉</p><p>💡 Additionally, if you’d like to go deeper, I’m planning to organize <strong>review sessions in English</strong>. If you’re interested, just send me an email — I’ll create a group and share details. As a former student mentor I really missed mentoring :)</p><p>Let’s learn and grow together! 🌱</p><p>#Java #LearningTogether #DevelopersCommunity #OpenSource</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c15f2413569" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Test Account Picking Strategies (Test Automation Experiences 1)]]></title>
            <link>https://kicchi.medium.com/test-account-picking-strategies-test-automation-experiences-1-47838c44d379?source=rss-54616ba631f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/47838c44d379</guid>
            <category><![CDATA[test-automation-framework]]></category>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[qa-testing]]></category>
            <category><![CDATA[sdet]]></category>
            <category><![CDATA[qa-engineering]]></category>
            <dc:creator><![CDATA[Hüseyin K.]]></dc:creator>
            <pubDate>Sun, 10 Mar 2024 20:19:02 GMT</pubDate>
            <atom:updated>2024-03-10T20:23:10.643Z</atom:updated>
            <content:encoded><![CDATA[<p>Creating an effective way of test account management is discussed in this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0WMsXFNNFutZXaiEqDJd-w.png" /></figure><p>I am Huseyin. Have been a .Net, Java backend and Android developer for 6 years as well as a QA Automation Engineer for several projects for last 6 years.</p><p>This is the first article of Test Automation Experiences Series in which you will find my experiences about Test Automation Fundamentals.</p><h3>Test account</h3><p>Test account is the account which is used for either manual test or automated test. For a proper management of those accounts, manual test accounts should be differentiated from automation accounts. In this article, account strategies are explained in regards to test automation.</p><p>I have been engaged in numerous test automation projects. I created the test user/account picking strategy for some of them and consumed a pre-created strategy for some others.</p><p>Generally, the first test data to consider while a test implementation is being held, is the account data.</p><p>There have been several ways for picking the test account. Test account picking strategy is generally decided by considering the application architecture. I don’t mean the code architecture but the flow architecture.</p><p>One of the most important things is the role of the test user which generally is the most important dependency for the rest of the test case.</p><p>Another dependency may be the user’s data, like its age, gender, residency location etc. based on the application’s needs.</p><h3><strong>Accounts in terms of session management</strong></h3><p>Almost in all cases, applications do not allow duplicate sessions at the same time for a single account. That is, if a user logs in with Chrome, for example, and the same user tries to login from another Chrome instance or browser, then the <strong>earlier user’s active session is ended automatically</strong> in regards to security issues. That will not allow the already logged in Chrome test automation to go further. That user will definitely see a login screen when a new session is created with the same credentials.</p><p>This is one important thing to consider when a test needs to run in parallel through multiple devices/browsers.</p><p>So, that means we need <strong>multiple accounts for a single test</strong>. For example, if the test would be executed through Desktop Chrome, Desktop Safari, Mobile Chrome browsers, then 3 different users with the same role/prerequisite are needed. And we also need to ensure that each test execution will use a different account with the same role/prerequisite.</p><p>Let’s analyze some of the strategies by sharing my experiences about this topic.</p><h3><strong>Account Pool Strategy</strong></h3><p>Let’s assume you have 20 test cases in your smoke suite, 5 of them need a user with an ADMIN role, 15 of them need a user with a MANAGER role.</p><p>Each test will run through <em>Desktop Chrome</em> and <em>Desktop Edge</em> in <strong>parallel</strong> which means there should be two accounts for each test.</p><p>You create 5x2 (10) admin and 15x2 (30) manager accounts in the application database, or via a user interface, or they are provided by the database team to you. Then all those users are <strong>declared</strong> in the test automation framework with their roles and credentials as <strong>constant</strong> User objects. So, all accounts were <strong>pre-created</strong> and <strong>pre-declared</strong>. This is the basic idea behind the Account Pool approach.</p><p>Account Pool Strategy ensures that a <strong>non-locked</strong> account will be picked up for <strong>each</strong> <strong>test execution </strong>(<em>not for each test but for each test execution</em>). That means we need to implement a LOCK-RELEASE mechanism in the test automation framework in order not to end the session of an account while it is being used for a test execution instance. Here, we should give importance to locking the account being used in one test execution instance, and we should unlock this account once the test execution is finished either with success or failure. Another important thing to implement is that we need to pick the non-locked account from the available users which match the role/prerequisite condition.</p><h4>Flow would be like this when we execute TestA in parallel;</h4><ul><li>TestA starts through Chrome =&gt; Needs an ADMIN account =&gt; gets the first non-locked ADMIN account (ADMIN-<strong>A</strong>) =&gt; locks account (ADMIN-<strong>A</strong>)</li><li>TestA starts through Edge =&gt; Needs an ADMIN account =&gt; gets the first non-locked ADMIN account (ADMIN-<strong>B</strong>) =&gt; locks account (ADMIN-<strong>B</strong>)</li></ul><h4>Flow would be like this when we execute TestA and TestB at the same time;</h4><ul><li>The same with above for TestA,</li><li>TestB starts through Chrome =&gt; Needs an ADMIN account =&gt; gets the first non-locked ADMIN account (ADMIN-<strong>C</strong>) =&gt; locks account (ADMIN-<strong>C</strong>)</li><li>TestB starts through Edge =&gt; Needs an ADMIN account =&gt; gets the first non-locked ADMIN account (ADMIN-<strong>D</strong>) =&gt; locks account (ADMIN-<strong>D</strong>)</li></ul><p>This strategy ensures that <strong>each test execution</strong> <strong>instance</strong> will use a proper, pre-created account and locks that account to prevent session-dropped issues.</p><p>There are several ways of implementing the LOCK-RELEASE mechanism. One can be using a simple text file in the ci pipeline. Another implementation can be done via a simple database table by updating the LOCK status of the pre-created users.</p><h3><strong>Account-On-Demand Strategy</strong></h3><p>This strategy creates a <strong>new user for each test execution</strong>. A proper API endpoint would be useful for this approach.</p><p>Let’s say you need an ADMIN account for a specific test case, then you just call the “Create User” api endpoint with a role parameter like ADMIN, then it returns to you a newly created ADMIN account with all its related data and credentials.</p><p>On the contrary to the Account Pool Strategy, all users are created in the beginning of the test execution, like, as a precondition. All accounts are being used only one time. There is no need for a lock mechanism for this strategy and you also do not need to create a lot of accounts and declare those accounts in the test framework.</p><h3><strong>Assigned Account Strategy</strong></h3><p>In this strategy, all accounts are <strong>pre-created</strong> at backend and <strong>pre-defined</strong> in automation framework like Account Pool Strategy. But there is a big difference when it comes to picking the right account; all accounts are tied to specific tests and devices.</p><p>Let’s say TestA which uses an ADMIN account, will be executed through Chrome and Edge in <strong>parallel</strong>. Then we create 2 ADMIN accounts and relate ADMIN-A with TestA <strong>for only Chrome execution</strong>, and relate ADMIN-B with TestA <strong>for only Edge execution</strong>. By doing so, we ensure that the same account will not be used for other browsers even if it runs in parallel. And we also ensure other tests will not use those assigned accounts which gives us the freedom to run the <strong>whole test suite at once</strong>.</p><p>This topic is a crucial dependency for all tests when an automation framework is being created. I hope it helps to whom interested. Please share your experiences by commenting.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47838c44d379" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Maven? (Java Why? Article Series 4)]]></title>
            <link>https://kicchi.medium.com/why-maven-java-why-article-series-4-9773a5ed170f?source=rss-54616ba631f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/9773a5ed170f</guid>
            <category><![CDATA[maven]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-development]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[java-maven]]></category>
            <dc:creator><![CDATA[Hüseyin K.]]></dc:creator>
            <pubDate>Fri, 25 Nov 2022 20:02:09 GMT</pubDate>
            <atom:updated>2022-11-25T20:02:09.463Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi Java people. Ready for analyzing why we need Maven?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F8fckomdPUkX9A5ZuwawrQ.png" /></figure><p>I am Huseyin. Have been a .Net developer for years and Java backend and Android developer for 6 years as well as a QA Automation Engineer team member for several projects for 3 years.</p><p>Have been observing that some of my friends , especially junior developers, are <strong>not completely aware</strong> of the point of using a structure a tool. As a developer, by experiencing the reusability, abstraction and the maintainability issues for years, I decided to implement the same structure in my life and <strong>abstract myself</strong> from answering similar questions 🙂. Thus, put my effort into creating this <strong>“Why Java? Article Series”</strong>. I just wanna to help developers to code consciously.</p><p>The <strong>target audience</strong> of “Why Java? Article Series” is the ones who already know coding with Java, but also want to understand the underlying language and the system.</p><p><strong>Main purpose</strong> of these articles is to <strong>understand why we need</strong> some structures or tools in our framework in order to be conscious while using them. Of course there are a lot of sources about Java on the internet. What I experienced is that some <strong>different approaches</strong> while explaining the same thing helps people to understand the topics. What I am trying to do is actually that. A different kind of explanation from WHY point.</p><p>Articles are prepared to achieve the understanding of the topic from a step by step approach.</p><p>If these articles help you to understand a concept, I definitely feel very happy. Feel free to share and comment.</p><p>Sharing is learning at the same time! Enjoy.</p><h3>I need a ready code</h3><p>I have a lot of work to do.</p><p>At some point, I needed to check if a number is power of two.</p><p>Since I have a lot to do, I do not want to spent time on that issue. Rather than that, I decided to search if there is a pre-written code snippet.</p><p>If I wrote a method to find whether a number is power of two or not, I would name it as “isPowerOfTwo”. So I decided to search these words on Google; “isPowerOfTwo java method” is searched;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hb_UgsC3EgpX2Fkf9CmS4A.png" /></figure><p>I clicked in the first search result</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AUVDi8WmDeQ7QJqHWll9uQ.png" /></figure><p>The explanation was mentioning Guava. <strong>What is this Guava?</strong></p><p>I searched the net and found that this was a <strong>library</strong> made by Google, that includes a lot of <strong>ready methods</strong> for facilitating developers work.</p><p>In order to use the “isPowerOfTwo” method of Guava Library, <strong>first</strong>, I should <strong>add it to my project</strong>. That is not like adding a regular file.</p><h3>Guava in mvnrepository.com</h3><p>I knew that MvnRepository.com is hosting such kind of ready libraries. So, I checked if Guava is included in the mvnrepository.com.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4OWDwwk4oeAwR3pVNoPmyA.png" /><figcaption>Bundle is downloaded</figcaption></figure><p>Yes, it is. Then I downloaded the latest version jar file of Guava Library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/0*iraU7HXFRyrVaQuY" /></figure><p><strong>Manually Adding A Library To Java Project</strong></p><p>Since I do not use any build tool/dependency manager (like Maven), I need to download the jar file and add it to my project as a dependency.</p><p>In IntelliJ, navigated to File&gt;Project Settings&gt;Modules&gt;Dependency;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oZfcom6by4eaRWY6vqdAmg.png" /></figure><p>Then I added the jar file that I downloaded from mvnrepository.com;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HuI7PWt38RLfibw3rJcK0w.png" /></figure><p>I checked the website that explains my requirement. And, I found this code snippet that uses isPowerOfTwo method of the IntMath class which belongs to Guava Library;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/0*8I_epHpPJCzTPjun" /></figure><p>Let’s use this isPowerOfTwo method in my project like the example above;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/0*Cxcij6O64djFiBkm" /></figure><p>Voila! Works well. I checked the External Libraries. Guava was added to my project as a jar file;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*O13WbP6faa1GMhb04ZTmXg.png" /></figure><h3>Not enough!</h3><p>You know what? I really bored with downloading jar files and uploading to my project as dependency.</p><p>Rather than downloading, I decided to create a new Maven project and let the maven do all these things with a couple of lines.</p><p>Moreover, I really do not know if there is a new version of the Guava Library is published. In order to check this I should manually search Guava on mvnrepository.com and I should compare the versions. If there is a new one I have to repeat the same process when I did for the first jar file addition.</p><p><strong>Maven power!</strong></p><blockquote>In order to learn how to create a Maven project you can check this <a href="https://www.jetbrains.com/idea/guide/tutorials/working-with-maven/creating-a-project/">link</a>.</blockquote><p>After creating a Maven project I checked the mvnrepository.com for Guava, and copied the Maven content (red rectangle) for adding it to my POM.XML file which is the heart of my Maven Project for build and dependency management.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IAJ8VPjO9QJQRyCSVj4YGA.png" /></figure><p><strong>Adding dependency to POM</strong></p><p>After pasting the copied content between “dependencies” tags, then I need to click the refresh button to let the maven download and add the Guava Library to my project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*srjZHzUfjGruL3A_vRCH1A.png" /></figure><p><strong>Guava is added through Maven</strong></p><p>After refreshing Maven, I checked the External Libraries, I saw a couple of new libraries were added to my project which are somehow related to Guava and Guava it is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h2qa5kxTTWDeaE8NMdSdsA.png" /></figure><p><strong>Ultimate Voila!</strong></p><p>I was able to use Guava classes and methods that bring me a lot time and efficient code;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3WSPAb-FrX-Rrsz_GYQ_kQ.png" /></figure><p>This is not the only way but the most effective way, since it is much easier than manual jar file addition.</p><p>Thanks for reading. Hope this helps! See you in the next articles.</p><p>PS: Really benefited from especially Baeldung and other Java Tutorial Websites.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*XOiRadomSXMFaJuh9cMCHg.png" /><figcaption>Dedicated to Dirty Java Rangers</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9773a5ed170f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Generics? 2 (Java Why? Article Series 3)]]></title>
            <link>https://kicchi.medium.com/why-generics-2-java-why-article-series-3-e8b2072943f?source=rss-54616ba631f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8b2072943f</guid>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[java-development]]></category>
            <category><![CDATA[java-generic]]></category>
            <category><![CDATA[type-safety]]></category>
            <category><![CDATA[generics-in-java]]></category>
            <dc:creator><![CDATA[Hüseyin K.]]></dc:creator>
            <pubDate>Tue, 22 Nov 2022 20:24:15 GMT</pubDate>
            <atom:updated>2022-11-22T20:24:15.973Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi Java people. Ready for analyzing why we need Generics?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5BxMQjKzn_GJu-cZ9IaPMA.png" /></figure><p>I am Huseyin. Have been a .Net developer for years and Java backend and Android developer for 6 years as well as a QA Automation Engineer team member for several projects for 3 years.</p><p>Have been observing that some of my friends , especially junior developers, are <strong>not completely aware</strong> of the point of using a structure a tool. As a developer, by experiencing the reusability, abstraction and the maintainability issues for years, I decided to implement the same structure in my life and <strong>abstract myself</strong> from answering similar questions 🙂. Thus, put my effort into creating this <strong>“Why Java? Article Series”</strong>. I just wanna to help developers to code consciously.</p><p>The <strong>target audience</strong> of “Why Java? Article Series” is the ones who already know coding with Java, but also want to understand the underlying language and the system.</p><p><strong>Main purpose</strong> of these articles is to <strong>understand why we need</strong> some structures or tools in our framework in order to be conscious while using them. Of course there are a lot of sources about Java on the internet. What I experienced is that some <strong>different approaches</strong> while explaining the same thing helps people to understand the topics. What I am trying to do is actually that. A different kind of explanation from WHY point.</p><p>Articles are prepared to achieve the understanding of the topic from a step by step approach.</p><p>If these articles help you to understand a concept, I definitely feel very happy. Feel free to share and comment.</p><p>Sharing is learning at the same time! Enjoy.</p><p>If you did not read “Why Generics? 1” article, I strongly recommend to read it first.</p><h3>Need for Generic Class</h3><p>Let’s imagine a scenario where we want to create a list in Java to store <em>Integer</em>. We might try to write the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/0*KlqEbOV1GzUdkKzG" /></figure><p>Surprisingly, the compiler will complain about the last line. Because, it doesn’t know what data type is returned. So it can not assign it to i directly, without checking the data type.</p><p><strong>Analysis</strong></p><p>There is <strong>no contract</strong> that could guarantee that the return type of the list is an <em>Integer</em>.</p><p>The defined list could hold <strong>any object</strong>. We only know that we are retrieving a list by inspecting the context.</p><p>When looking at types, it can only guarantee that it is an <em>Object</em> and therefore requires an <strong>explicit cast</strong> to ensure that the type is safe.</p><p>This cast can be <strong>annoying</strong> — we <strong>know</strong> that the data type in this list is an <em>Integer</em>. The cast is also cluttering our code. It can cause <strong>type-related runtime errors</strong> if a programmer makes a mistake with the explicit casting.</p><p>It would be much easier if programmers could express their intention to use <strong>specific types</strong> and the compiler ensured the correctness of such types. <strong>This is the core idea behind generics.</strong></p><p><strong>Refactoring the code</strong></p><p>Let’s modify the first line of the previous code snippet;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/0*eQEBNvja5O6LdAOv" /></figure><p>By adding the diamond operator &lt;&gt; containing the type, we <strong>narrow</strong> the <strong>specialization</strong> of this list to only <em>Integer</em> type.</p><p>In other words, we <strong>specify the type held inside the list</strong>. The compiler can <strong>enforce</strong> the type at <strong>compile time</strong>.</p><p>In small programs, this might seem like a <strong>trivial</strong> addition. But in larger programs, this can add <strong>significant robustness</strong> and makes the program easier to read.</p><h3>Need for Wildcard (?) with Generics</h3><p>Wildcards are represented by the question mark <em>?</em> in Java, and we use them to refer to an <strong>unknown type</strong>. Wildcards are particularly useful with generics and <strong>can be used as a parameter type</strong>.</p><p>But first, there is an important note to consider.</p><p><strong>We know that <em>Object</em> is the super-type of all Java classes.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*uC97ctfoZzy18D9XVEl7Dg.png" /><figcaption>Assigning a String object to Object is fine</figcaption></figure><blockquote><strong>However, a collection of <em>Object</em> is not the supertype of any collection.</strong></blockquote><p>For example, a List&lt;Object&gt; is not the super-type of List&lt;String&gt;, and assigning a variable of type List&lt;String&gt; to a variable of type List&lt;Object&gt; will cause a compiler error. Look at this code;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/0*kVRuQ0ZG9XXdXtHy" /><figcaption>Assigning a String List to Object List is impossible</figcaption></figure><p>This is to prevent possible conflicts that can happen if we add heterogeneous types to the same collection.</p><p><strong>Custom Class Lists</strong></p><p>The <strong>same</strong> rule applies to any <strong>collection</strong> of a <strong>type</strong> and its <strong>subtypes</strong>. Let’s give an example;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*W04F4eibwUai1wqkLC4Yog.png" /></figure><p>Animal class has an abstract feedAnimal method, which is implemented by the Animal extenders; Budgie and Dog. Let’s think about a method which takes <strong>Animal List</strong>, and runs abstract method through <strong>Animal reference type</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*ACOGMQqII77fCVm_nGgMTw.png" /></figure><p>This method works well with a List of Animal referenced objects;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*hatU8ftc7dKzLk6IYA6-Yg.png" /></figure><p><strong>But</strong>, a subtype of <em>Animal</em>, such as a <em>Budgie</em>, we can’t use this method with a list of <em>Budgie</em>, even though <em>Budgie</em> is a <strong>subtype</strong> of <em>Animal</em>. Have a look below;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/0*gaxIqoCHt2jmWrOs" /><figcaption>Method accepts a List of Animal, not List of Budgie</figcaption></figure><blockquote><strong>REMEMBER: A collection of <em>Object</em> is not the super-type of any collection.</strong></blockquote><p>If we need to use this feeadAnimal() method with type <em>Animal</em> and all its <strong>subtypes</strong>, the bounded wildcard can do the <strong>magic;</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P3tLDuqDZ9GoO_KcKCHVBQ.png" /></figure><p>Now this method will work with type <em>Animal</em> and all its subtypes.</p><p>“&lt;? extends Animal&gt;” is called an upper-bounded wildcard, where type <em>Animal</em> is the <strong>upper bound</strong>.</p><p>We can also specify wildcards with a lower bound, where the unknown type has to be a super-type of the specified type.</p><p>Lower bounds can be specified using the <em>super</em> keyword followed by the specific type. For example; “<em>&lt;? super T&gt;”</em> means unknown type that is a superclass of <em>T</em> (= T and all its parents).</p><p>Thanks for reading. Hope this helps! See you in the next articles.</p><p>PS: Really benefited from especially Baeldung and other Java Tutorial Websites, as well as Official Java Documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*XOiRadomSXMFaJuh9cMCHg.png" /><figcaption>Dedicated to Dirty Java Rangers</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8b2072943f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java Streams 5 Q&A (Need to know about Java Q&A Article Series 10)]]></title>
            <link>https://kicchi.medium.com/java-streams-5-q-a-need-to-know-about-java-q-a-article-series-10-697456cd86a6?source=rss-54616ba631f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/697456cd86a6</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-stream-api]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[java-development]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Hüseyin K.]]></dc:creator>
            <pubDate>Mon, 21 Nov 2022 11:36:37 GMT</pubDate>
            <atom:updated>2022-11-21T11:36:37.177Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi Java people.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Y1T7MwJ6_OKL2E5pwZv1g.png" /></figure><p>I am Huseyin. Have been a .Net developer for years and Java backend and Android developer for 6 years as well as a QA Automation Engineer team member for several projects for 3 years.</p><p>Have been getting a reasonable amount of questions from any level of Java developers for years. In the end, decided to write my own answers instead of spending my time over the same thing again and again. As a developer, by experiencing the reusability, abstraction and the maintainability issues for years, I decided to implement the same structure in my life and <strong>abstract myself</strong> from answering similar questions 🙂. Thus, put my effort into creating this <strong>“Need to know about Java Q&amp;A Article Series”</strong>. By doing so, I am comfortable about answering similar questions by just sending a link to these articles 🙂. It helped me to understand many very important concepts of Java as well.</p><p>The <strong>target audience</strong> of “Need to know about Java Q&amp;A Article Series” is the ones who already know coding with Java, but also want to improve his/her knowledge or to prepare for Java Interviews. If you are a new bee, I believe these articles may be a couple of levels higher for you.</p><p><strong>Main purpose</strong> of these articles is not to explain topics in detail. Of course there are a lot of sources about Java on the internet. What I experienced is that some <strong>different approaches</strong> while explaining the same thing helps people to understand the topics. What I am trying to do is actually that. A different kind of explanation.</p><p>Articles are prepared by Question &amp; Answer structure which I do believe is an <strong>efficient way of learning</strong>.</p><p>If these articles help you to understand a concept, I definitely feel very happy. Feel free to share and comment.</p><p>Sharing is learning at the same time! Enjoy.</p><h3>What is the “Java Collectors” class?</h3><p>Collectors class is one of the <strong>utility</strong> classes in JDK which contains a lot of utility functions. It is a final class that is part of the <strong>Stream package</strong>, and mostly used with Stream API <strong>as a final step</strong>. For example there are some functions which return a <strong>Collector</strong> by applying a <strong>reduction</strong> operation over the stream items;</p><pre><em>people.stream().map(Person::getName).collect(Collectors.toList());</em></pre><p>Here, Collectors.toList() method creates a <strong>list</strong> object and adds elements one after another and returns a Collector object. A couple of examples;</p><p>This returns a <strong>set</strong> of names;</p><pre><em>people.stream()<br>      .map(Person::getName)<br>      .collect(Collectors.toCollection(TreeSet::new));</em></pre><p>This returns a <strong>combined</strong> strings of the underlying objects;</p><pre><em>things.stream()<br>             .map(Object::toString)<br>             .collect(Collectors.joining(“, “));</em></pre><h3>What are the takeWhile() and dropWhile() methods?</h3><p>takeWhile() and dropWhile() methods of Stream API accepts a <strong>Predicate</strong> interface implementation.</p><p>Let’s run this code;</p><pre><em>Stream.of(11, 4, 8)<br>      .takeWhile(integer -&gt; integer %2 == 0)<br>      .forEach(System.out::print);</em></pre><p>Output; <em>NOTHING PRINTED</em></p><p>Let’s run with different values;</p><pre><em>Stream.of(10, 5, 8)<br>      .takeWhile(integer -&gt; integer %2 == 0)<br>      .forEach(System.out::print);</em></pre><p>Output; <em>10</em></p><p>Analysis; first example stops by checking 11 since it is odd. Thus, takeWhile did not iterate over 4 and 8. When <strong>the first unmatching element is found then it does not go further</strong>. Second example checks 10 and then checks 5, since 5 is odd it stopped without checking the rest. That’s why only 10 is printed.</p><p>Since both inputs are <strong>unordered</strong>; <strong>subset</strong> of the stream’s elements returned, but not the longest prefix.</p><p><strong>Longest prefix</strong> means a contiguous sequence of elements of the stream that match the given predicate. It always starts with the first element of the stream. But if the predicate is false for the first element, then takeWhile stops working and you will get an empty stream.</p><p>Let’s apply takeWhile to an <strong>ordered</strong> stream;</p><pre><em>Stream.of(11, 4, 8).sorted(Integer::compareTo)<br>                   .takeWhile(integer -&gt; integer %2 == 0)<br>                   .forEach(System.out::print);</em></pre><p>Output; <em>48</em></p><p>Analysis; since the stream is <strong>sorted</strong> before takeWhile operation, take while checked 4, it was even and it continued with the next one; 8. After 8 it checked 11 and since it is odd <strong>stopped at that point</strong>.</p><p>Since the stream was <strong>ordered</strong>; the <strong>longest prefix</strong> of these elements returned, not just a subset. So, it is meaningful to use the takeWhile method over an ordered stream, otherwise it will just give a subset.</p><p>One last example to understand fully;</p><pre><em>Stream.of(11, 4, 8, 7).sorted(Integer::compareTo)<br>                      .takeWhile(integer -&gt; integer %2 == 0)<br>                      .forEach(System.out::print);</em></pre><p>Output; <em>4</em></p><p>Explanation; <strong>takeWhile stops taking on the first predicate’s false</strong>.</p><p><strong>DropWhile</strong> method does exactly the <strong>opposite</strong> of takeWhile. <strong>If a stream is ordered</strong>, the dropWile returns a stream consisting of the remaining elements of this Stream after dropping the <strong>longest prefix</strong> of elements that match the given predicate.</p><p>Otherwise, if a Stream is <strong>unordered</strong>, the dropWile returns a stream consisting of the remaining elements of this Stream after dropping a <strong>subset</strong> of elements that match the given predicate.</p><p>Let’s run this code to understand dropWhile;</p><pre><em>Stream.of(2, 4, 8)<br>       .dropWhile(integer -&gt;integer %2 == 0)<br>        .forEach(System.out::print);</em></pre><p>Output; <em>NOTHING PRINTED</em></p><p>Analysis; dropWhile executed for 2, 4 and 8 because it did not encounter any false condition. So it did not stop at a point. Recall that; <strong>dropWhile stops removing on the first predicate’s false</strong>.</p><p>Another example;</p><pre><em>Stream.of(9, 4, 8)<br>       .dropWhile(integer -&gt;integer %2 == 0)<br>        .forEach(System.out::print);</em></pre><p>Output; <em>948</em></p><p>Analysis; dropWhile checked 9 and this condition was false. Then it stopped working (stopped dropping). Recall that; <strong>dropWhile stops removing on the first predicate’s false</strong>.</p><p>Applying dropWhile to an ordered stream;</p><pre><em>Stream.of(7, 4, 2, 8).sorted(Integer::compareTo)<br>                      .dropWhile(integer -&gt; integer %2 == 0)<br>                       .forEach(System.out::print);</em></pre><p>Output; <em>78</em></p><p>Analysis; Stream is sorted first, it becomes; 2, 4, 7, 8. Drop condition for 2 is true, so 2 is dropped. Drop condition for 4 is true, so 4 is dropped. Drop condition for 7 is false, so it is not dropped and dropWhile stops working at that point.</p><p>So, likewise takeWhile, it is meaningful to use the dropWhile method over an ordered stream, otherwise it will just give a subset.</p><p>Thanks for reading. Hope this helps! See you in the next articles.</p><p>PS: Really benefited from especially Baeldung and other Java Tutorial Websites, as well as Official Java Documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*XOiRadomSXMFaJuh9cMCHg.png" /><figcaption>Dedicated to Dirt Java Rangers</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=697456cd86a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java Type Inference Q&A (Need to know about Java Q&A Article Series 9)]]></title>
            <link>https://kicchi.medium.com/java-type-inference-q-a-need-to-know-about-java-q-a-article-series-9-432ce581361e?source=rss-54616ba631f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/432ce581361e</guid>
            <category><![CDATA[java-updates]]></category>
            <category><![CDATA[java-development]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[type-inference]]></category>
            <dc:creator><![CDATA[Hüseyin K.]]></dc:creator>
            <pubDate>Thu, 17 Nov 2022 18:20:20 GMT</pubDate>
            <atom:updated>2022-11-17T18:20:20.655Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi Java people.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PYbPthGnSdeO54hhgRwwNw.png" /></figure><p>I am Huseyin. Have been a .Net developer for years and Java backend and Android developer for 6 years as well as a QA Automation Engineer team member for several projects for 3 years.</p><p>Have been getting a reasonable amount of questions from any level of Java developers for years. In the end, decided to write my own answers instead of spending my time over the same thing again and again. As a developer, by experiencing the reusability, abstraction and the maintainability issues for years, I decided to implement the same structure in my life and <strong>abstract myself</strong> from answering similar questions 🙂. Thus, put my effort into creating this <strong>“Need to know about Java Q&amp;A Article Series”</strong>. By doing so, I am comfortable about answering similar questions by just sending a link to these articles 🙂. It helped me to understand many very important concepts of Java as well.</p><p>The <strong>target audience</strong> of “Need to know about Java Q&amp;A Article Series” is the ones who already know coding with Java, but also want to improve his/her knowledge or to prepare for Java Interviews. If you are a new bee, I believe these articles may be a couple of levels higher for you.</p><p><strong>Main purpose</strong> of these articles is not to explain topics in detail. Of course there are a lot of sources about Java on the internet. What I experienced is that some <strong>different approaches</strong> while explaining the same thing helps people to understand the topics. What I am trying to do is actually that. A different kind of explanation.</p><p>Articles are prepared by Question &amp; Answer structure which I do believe is an <strong>efficient way of learning</strong>.</p><p>If these articles help you to understand a concept, I definitely feel very happy. Feel free to share and comment.</p><p>Sharing is learning at the same time! Enjoy.</p><h3>What is Type inference?</h3><p>Type Inference is the process of <strong>automatically deducing unspecified data</strong> types of an expression based on the <strong>contextual information</strong>.</p><p>It has two applications;</p><ul><li>Generic Type Inference,</li><li>Local Variable Type Inference</li></ul><p><strong>(1) Generic Type Inference;</strong></p><p>Before Java 7, a List of Integers was declared like that;</p><pre><em>List&lt;Integer&gt; list1 = new ArrayList&lt;Integer&gt;();</em></pre><p>With Java 7, it is not needed to explicitly declare object type any more;</p><pre><em>List&lt;Integer&gt; list2 = new ArrayList&lt;&gt;();</em></pre><p>Java 8 supports inference using Target-Type in a method context which is called <strong>Improved Type Inference</strong>;</p><pre><em>showList(new ArrayList&lt;&gt;());</em></pre><p>In this case, while invoking a generic method <strong>without explicit type </strong>arguments, the inference algorithm of the compiler can look at the method invocation and corresponding method declarations to <strong>determine the type argument</strong> (or arguments) that make the invocation applicable.</p><p>The inference algorithm tries to find the <strong>most specific type</strong> that works with all of the arguments. Thus, boilerplate code is reduced.</p><p><strong>(2) Local Variable Type Inference;</strong></p><p>With JDK 10, type inference of <strong>local variables with initializers</strong> was introduced. Until Java 9, we had to mention the type of the local variable explicitly and ensure it was compatible with the initializer used to initialize it:</p><pre><em>String message = “Good bye, Java 9”;</em></pre><p>In Java 10, We don’t provide the data type of message. Instead, we mark the message as a var, and the compiler infers the type of message from the type of the initializer present on the right-hand side;</p><pre><em>var message = “Hello, Java 10”;</em></pre><pre><em>assertTrue(message instanceof String); // output: true</em></pre><p>Note that this feature is available <strong>only for local variables with the initializer</strong>.</p><p>Local variable without initializer</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/0*S7nzrneV2Kb69ITZ" /><figcaption>Pay attention to the error</figcaption></figure><p>Class level var declaration</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/0*6ozwGIYF8ICi9blA" /></figure><h3>What is Local Variable Type inference ? Give one example</h3><p>With JDK 10, type inference of <strong>local variables with initializers</strong> was introduced. Until Java 9, we had to mention the type of the local variable explicitly and ensure it was compatible with the initializer used to initialize it:</p><pre><em>String message = “Good bye, Java 9”;</em></pre><p>In Java 10, We don’t provide the data type of message. Instead, we mark the message as a var, and the compiler infers the type of message from the type of the initializer present on the right-hand side;</p><pre><em>var message = “Hello, Java 10”;</em></pre><pre><em>assertTrue(message instanceof String); // output: true</em></pre><p>Note that this feature is available <strong>only for local variables with the initializer</strong>.</p><p>Local variable without initializer;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/0*xERITArSioXJF-_z" /></figure><p>Class level var declaration:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/0*9d1uye533pMbmBuu" /></figure><h3>Can we use local var type inference for member variable and method parameters?</h3><p>Local variable type inference is achieved with <strong>var</strong> keyword. This keyword can not be used for member variables and method parameters. This feature is available <strong>only for local variables with the initializer</strong>.</p><p>Class level var declaration:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/0*mkAYHkzRYGVDaz2B" /></figure><p>Method parameter declaration with var keyword;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/0*vZdVXGG9WAR5xuzI" /></figure><p>Thanks for reading. Hope this helps! See you in the next articles.</p><p>PS: Really benefited from especially Baeldung and other Java Tutorial Websites, as well as Official Java Documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*XOiRadomSXMFaJuh9cMCHg.png" /><figcaption>Dedicated to Dirty Java Rangers</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=432ce581361e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java Updates Q&A (Need to know about Java Q&A Article Series 8)]]></title>
            <link>https://kicchi.medium.com/java-updates-q-a-need-to-know-about-java-q-a-article-series-8-fec1fded167c?source=rss-54616ba631f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/fec1fded167c</guid>
            <category><![CDATA[java-8-feature]]></category>
            <category><![CDATA[java-development]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[java-updates]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Hüseyin K.]]></dc:creator>
            <pubDate>Wed, 16 Nov 2022 07:19:37 GMT</pubDate>
            <atom:updated>2022-11-16T07:19:37.998Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi Java people.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qBxSHOZOBrfNhpooevi1ow.png" /></figure><p>I am Huseyin. Have been a .Net developer for years and Java backend and Android developer for 6 years as well as a QA Automation Engineer team member for several projects for 3 years.</p><p>Have been getting a reasonable amount of questions from any level of Java developers for years. In the end, decided to write my own answers instead of spending my time over the same thing again and again. As a developer, by experiencing the reusability, abstraction and the maintainability issues for years, I decided to implement the same structure in my life and <strong>abstract myself</strong> from answering similar questions 🙂. Thus, put my effort into creating this <strong>“Need to know about Java Q&amp;A Article Series”</strong>. By doing so, I am comfortable about answering similar questions by just sending a link to these articles 🙂. It helped me to understand many very important concepts of Java as well.</p><p>The <strong>target audience</strong> of “Need to know about Java Q&amp;A Article Series” is the ones who already know coding with Java, but also want to improve his/her knowledge or to prepare for Java Interviews. If you are a new bee, I believe these articles may be a couple of levels higher for you.</p><p><strong>Main purpose</strong> of these articles is not to explain topics in detail. Of course there are a lot of sources about Java on the internet. What I experienced is that some <strong>different approaches</strong> while explaining the same thing helps people to understand the topics. What I am trying to do is actually that. A different kind of explanation.</p><p>Articles are prepared by Question &amp; Answer structure which I do believe is an <strong>efficient way of learning</strong>.</p><p>If these articles help you to understand a concept, I definitely feel very happy. Feel free to share and comment.</p><p>Sharing is learning at the same time! Enjoy.</p><h3>Explain the release cycle of Java versions</h3><p>First of all, there are a couple of implementations of the same Java specification. Most popular ones are; <strong>OpenJDK</strong> and <strong>Oracle JDK</strong>. Both OpenJDK and Oracle JDK are created and maintained by <strong>Oracle</strong>. <strong>OpenJDK is a free and open-source</strong> implementation of the Java SE Platform Edition, while Oracle JDK was licensed under the Oracle Binary Code License Agreement.</p><p>Oracle JDK delivers releases every three years, while OpenJDK releases every six months.</p><p>Oracle JDK provides long term support for its releases. On the other hand, OpenJDK only supports the changes to a release until the next version is released.</p><p>So OpenJDK, compared to Oracle JDK, delivers releases more often.</p><p>In the past, Java release cycles were much longer, up to 3–5 years.</p><p>As of September 2022, Java 19 is the latest released Java version. In March 2023, Java 20 will follow. The last long-term support version (LTS) of Java is Java 17, released in September 2021. Open JDK 8, 11 and 17 are the last three LTS versions of Java.</p><p>AdoptOpenJDK, Amazon Corretto and Azul Zulu are other open-source popular JDK implementations.</p><h3>What is Modularity in Java?</h3><p>Modularity is a general concept which applies to the development of software in a fashion which allows <strong>individual modules</strong> to be developed. This technique focuses on separating the program functionality into <strong>independent, interchangeable</strong> modules.</p><p>A module is more like an <strong>independent</strong> <strong>partition</strong> of software that is communicated through an <strong>interface</strong>. Modularity explores the creation of a program by using different modules than a single legacy architecture.</p><p>Java 9 introduces a new level of abstraction <strong>above packages</strong>; Modules.</p><p>Advantages of Modularity in Java;</p><ul><li>More readable and independently testable code,</li><li>Enhanced reusability,</li><li>Development time reduction,</li><li>Provides parallel development,</li><li>Update risks lowered,</li><li>Code-fix enhanced.</li></ul><p>Modularity is useful as a general concept to <strong>break down</strong> an application into different parts, which can then be tested (and evolved) <strong>separately</strong>.</p><h3>How can we create a module in Java?</h3><p>A module descriptor is the compiled version of a module declaration that’s defined in a file named <strong>module-info.java</strong> which is added to the module’s root folder. Each module declaration begins with the keyword module, followed by a unique module name and a module body enclosed in braces:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/0*AZDQxluw3CQx63md" /></figure><p>Here’s how to set up the project structure dialog from within IntelliJ:</p><p>Right click on the project root and select New&gt;Modules, then specify the SDK, and name the module (general naming convention is reverse-domain-name like net.kicchi.core).</p><p>Each module has it’s <strong>own</strong> main and test folder as well as it’s <strong>own</strong> pom.xml file (if it is a maven project). Recall that modularity simplifies testing by segregation.</p><h3>What features can interfaces have In Java 9 and later versions?</h3><p>Interfaces in Java 1.0 include only two types of items — <strong>constants</strong> and public <strong>abstract methods</strong>.</p><p>Java 1.1 introduced the concept that Interfaces can <strong>contain</strong> other interfaces and classes.</p><p>With Java 5 <strong>Enum</strong> and <strong>Annotation</strong> declarations allowed in interfaces, and <strong>generic</strong> interface declarations introduced.</p><p>Java 8 introduced <strong>default</strong> and <strong>static</strong> methods in interfaces.</p><p>Java 9 introduced <strong>private static/non-static method</strong> declarations in interfaces.</p><p>With Java 15, the <strong>sealed</strong> keyword becomes available for interfaces as well as classes (The sealed keyword is used in conjunction with the “permits” keyword to determine exactly which classes are allowed to implement this interface).</p><h3>What is the structure of the Switch-Case Expression that came with Java 14?</h3><p>Regular switch-case usage;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/0*tvGDDhvxbGSP0bUk" /></figure><p>For this usage, you should end your cases with a break statement, otherwise all cases will run, finally the default part will always run.</p><p>New switch-case usage;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/0*7Fcj3kkSgLb8d9vy" /></figure><p>Notice that the new syntax uses the <strong>-&gt;</strong> operator instead of the colon we’re used to with switch statements. Multiple cases are merged with <strong>commas</strong>. Also, there’s <strong>no break keyword</strong>: The switch expression doesn’t fall through cases. Moreover, we are able to <strong>assign</strong> the returning value to a variable.</p><h3>What is “Records”?</h3><p>Record is introduced in Java 14 to <strong>reduce boilerplate code and improve the reliability</strong> of immutable classes. <strong>Immutable</strong> classes means that the classes whose main purpose is to <strong>hold data</strong> such as database results, query results, or information from a service that <strong>will not be changed in the program flow</strong>.</p><p>For such immutable classes, instead of writing getters, toString method, equals method, constructors <strong>again and again</strong> records can be used. Records <strong>automatically</strong> <strong>generates</strong> <strong>getters</strong>, <strong>toString</strong> method, <strong>equals</strong> method, <strong>hashCode</strong> method and all-args <strong>constructor</strong>. So you do not have to write all of them for immutable classes and you will gain time.</p><p>Record declaration is done like that;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*lTsYcGwM5Ex073n-" /></figure><p>Can be used like that;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/0*hz5nASAhjGc3CelR" /></figure><p>Pay attention that there are no compiler-generated <strong>setter</strong> methods.</p><p>Record’s power is more understandable when you <strong>add a new field</strong>. If you have a class instead of a record, you <strong>have to update</strong> your toString, equals and hashCode implementations when you add a new field. That is something that you can <strong>forget</strong>. But for records, after adding a new field, all these methods are <strong>updated by the compiler</strong>.</p><p>Thanks for reading. Hope this helps! See you in the next articles.</p><p>PS: Really benefited from especially Baeldung and other Java Tutorial Websites, as well as Official Java Documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*XOiRadomSXMFaJuh9cMCHg.png" /><figcaption>Dedicated to Dirty Java Rangers</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fec1fded167c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java Streams 4 Q&A (Need to know about Java Q&A Article Series 7)]]></title>
            <link>https://kicchi.medium.com/java-streams-4-q-a-need-to-know-about-java-q-a-article-series-7-ca85a9193aa2?source=rss-54616ba631f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca85a9193aa2</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-stream-api]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[java-development]]></category>
            <dc:creator><![CDATA[Hüseyin K.]]></dc:creator>
            <pubDate>Wed, 09 Nov 2022 17:09:42 GMT</pubDate>
            <atom:updated>2022-11-09T17:09:42.764Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi Java people.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Y1T7MwJ6_OKL2E5pwZv1g.png" /></figure><p>I am Huseyin. Have been a .Net developer for years and Java backend and Android developer for 6 years as well as a QA Automation Engineer team member for several projects for 3 years.</p><p>Have been getting a reasonable amount of questions from any level of Java developers for years. In the end, decided to write my own answers instead of spending my time over the same thing again and again. As a developer, by experiencing the reusability, abstraction and the maintainability issues for years, I decided to implement the same structure in my life and <strong>abstract myself</strong> from answering similar questions 🙂. Thus, put my effort into creating this <strong>“Need to know about Java Q&amp;A Article Series”</strong>. By doing so, I am comfortable about answering similar questions by just sending a link to these articles 🙂. It helped me to understand many very important concepts of Java as well.</p><p>The <strong>target audience</strong> of “Need to know about Java Q&amp;A Article Series” is the ones who already know coding with Java, but also want to improve his/her knowledge or to prepare for Java Interviews. If you are a new bee, I believe these articles may be a couple of levels higher for you.</p><p><strong>Main purpose</strong> of these articles is not to explain topics in detail. Of course there are a lot of sources about Java on the internet. What I experienced is that some <strong>different approaches</strong> while explaining the same thing helps people to understand the topics. What I am trying to do is actually that. A different kind of explanation.</p><p>Articles are prepared by Question &amp; Answer structure which I do believe is an <strong>efficient way of learning</strong>.</p><p>If these articles help you to understand a concept, I definitely feel very happy. Feel free to share and comment.</p><p>Sharing is learning at the same time! Enjoy.</p><h3>Which interface in Java is used to sort a list of objects based on custom order?</h3><p>First of all let’s analyze the Collections.sort() method.</p><p>String List sorting;</p><pre><em>List&lt;String&gt; list = <br>               new ArrayList&lt;&gt;(List.of(“Rangers”, “Dirty”, “Java”));</em></pre><pre><em>Collections.sort(list);</em></pre><pre><em>System.out.println(list);</em></pre><p>Output; <em>[Dirty, Java, Rangers]</em></p><p>Employee list sorting;</p><pre><em>List&lt;Employee&gt; employees =<br>                       new ArrayList&lt;&gt;(List.of(new Employee(“Mike”),   <br>                                             new Employee(“Adam”)));</em></pre><p>When I wanna use; Collections.sort(employees);</p><p>I got this compile time error;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QmbgfQeJqUcF9o1A" /></figure><p>The compiler says; Employee class does not implement Comparable interface. Collections.sort() method explanation;</p><p><em>Sorts the specified list into ascending order, according to the natural ordering of its elements. All elements in the list </em><strong><em>must implement the Comparable interface</em></strong><em>.</em></p><p>In the first example (String List sorting) the compiler did not complain, because String class <strong>already implements Comparable interface</strong>;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*txHaGP-nVxRykdWq" /></figure><p>Comparable interface is a Functional Interface, it only contains <strong>compareTo()</strong> method which takes generic type object as parameter;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/0*4Hyc2NuMlUEHjiOz" /></figure><p>compareTo() method explanation;</p><p><em>Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.</em></p><p>Let’s look at the String class to see how it implemented compareTo() method;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/0*bTKi44lc98YHNOyF" /></figure><p>To sum up, using Collections.sort() method with wrapper classes doesn’t create compile time errors since they already implemented Comparable Interface. But, when we want to use the <strong>Collections.sort()</strong> method with <strong>custom types</strong> we <strong>must implement the Comparable Interface</strong>.</p><p>The Comparable interface provides <strong>natural order</strong> like the lexicographic order of String.</p><p>To sort employee list with Comparable interface, firstly, implement it;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/0*FW99dM2J-Clnwwc_" /></figure><p>Then, the compiler does not complain about the Collections.sort() method usage;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nu_hKXqfPU9QyfPK" /></figure><p>Output; <em>[Employee{name=’Adam’}, Employee{name=’Mike’}]</em></p><p>As you see the output; it is ordered naturally. For <strong>reverse</strong> ordering;</p><pre><em>Collections.sort(employees, Collections.reverseOrder());</em></pre><p>Output; <em>[Employee{name=’Mike’}, Employee{name=’Adam’}]</em></p><p>Up to now, we analyzed the first approach for sorting a list of objects based on custom order.</p><p><strong>Second approach is to implement Comparator Functional Interface</strong>. Comparator interface explanation;</p><p><em>A comparison function, which imposes a total ordering on some collection of objects. Comparators can be passed to a sort method (such as Collections.sort or Arrays.sort) to allow precise control over the sort order.</em></p><p>As it is explained, we can pass Comparator Interface implementation as an argument to <strong>sort method of List Interface</strong>;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/0*kODvEDTp_8PiwVXD" /></figure><p>And <strong>sort method of Collections utility class</strong>;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*i_MSrNUuZGgGRiLB" /></figure><p>So, what we have in this Comparator Interface is <strong>compare() method</strong>;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/0*etb_2b8sbK39Pr0s" /></figure><p>Method explanation;</p><p><em>Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.</em></p><p>Sorting employee list by their names applying Comparator interface implementation over <strong>sort method of List Interface</strong>;</p><pre><em>employees.sort((o1, o2) -&gt; o1.name.compareTo(o2.name));</em></pre><p>Output; <em>[Employee{name=’Adam’}, Employee{name=’Mike’}]</em></p><p>Sorting employee list <strong>reverse</strong> by their names applying Comparator interface implementation over <strong>sort method of Collections class</strong>;</p><pre><em>Collections<br>   .sort(employees, Collections<br>                       .reverseOrder((o1, o2) -&gt; <br>                                       o1.name.compareTo(o2.name)));</em></pre><p>Output; <em>[Employee{name=’Mike’}, Employee{name=’Adam’}]</em></p><p>To sum up; sorting a list of objects based on custom order can be achieved by implementing <strong>Comparator interface or Comparable interface</strong>.</p><h3>Which static method in Java accepts a Function and returns a Comparator for the type which contains the sort key?</h3><p>The static <strong>comparing()</strong> method of the <strong>Comparator interface</strong> accepts a <strong>function</strong> (Function Interface implementation whose apply function takes an object and returns a value by executing the implementation code). That function interface extracts a <strong>Comparable sort key</strong> from a type T, and returns a Comparator that compares by that sort key;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IRCogcQa3SohL5bH" /></figure><p>“Extracting sort key” means; returning a value that will be <strong>applied to sort</strong> the underlying type of list. Since the Function interface is the parameter, we are free to apply any kind of logic. For example if our aim is to sort employees by their names’ length;</p><pre><em>List&lt;Employee&gt; employees =<br>                     new ArrayList&lt;&gt;(List.of(new Employee(“Kicchi”), <br>                                             new Employee(“Mike”)));</em></pre><pre><em>Comparator&lt;Employee&gt; comparator = Comparator<br>                     .comparing(employee -&gt; employee.name.length());</em></pre><pre><em>Collections.sort(employees, comparator);</em></pre><pre><em>System.out.println(employees);</em></pre><p>Output; <em>[Employee{name=’Mike’}, Employee{name=’Kicchi’}]</em></p><p>Another example can be sorting the employees by their names’ characters’ ascii decimal sum;</p><pre><em>List&lt;Employee&gt; employees =<br>                     new ArrayList&lt;&gt;(List.of(new Employee(“Kicchi”), <br>                                             new Employee(“Mike”)));</em></pre><pre><em>Comparator&lt;Employee&gt; comparator = Comparator<br>                .comparing(employee -&gt; employee.name.chars().sum());</em></pre><pre><em>Collections.sort(employees, comparator);</em></pre><pre><em>employees<br>     .forEach(employee -&gt; System.out.println(<br>                                         employee.name.chars().sum() <br>                                               + “ : “ + employee));</em></pre><p>Output;</p><p><em>390 : Employee{name=’Mike’}</em></p><p><em>587 : Employee{name=’Kicchi’}</em></p><p>So, the comparing method is much more flexible than the compare method in that it enables a developer to <strong>apply a logic for getting a new kind of sort key</strong> rather than just using the field values.</p><h3>Can we chain Comparators? Give one example</h3><p>Comparators <strong>can be chained</strong>. Imagine this scenario; We want to order employees by their ages, and we want to <strong>order sorted age groups by their name</strong>;</p><pre><em>List&lt;Employee&gt; employees =<br>                   new ArrayList&lt;&gt;(List.of(new Employee(“Otto”, 18),<br>                                        new Employee(“Kicchi”, 18),<br>                                        new Employee(“Mike”, 50)));</em></pre><pre><em>Comparator&lt;Employee&gt; sortByAge = Comparator<br>                                       .comparing(Employee::getAge);</em></pre><pre><em>Comparator&lt;Employee&gt; sortByName = Comparator<br>                                      .comparing(Employee::getName);</em></pre><pre><em>employees.sort(sortByAge.thenComparing(sortByName));</em></pre><pre><em>employees.forEach(System.out::println);</em></pre><p>Output;</p><p><em>Employee{name=’Kicchi’, age=18}</em></p><p><em>Employee{name=’Otto’, age=18}</em></p><p><em>Employee{name=’Mike’, age=50}</em></p><p>Here the <strong>ordering will be done by age</strong>, and for the <strong>values with the same age</strong>, the <strong>ordering will be done by name</strong>.</p><p>Thanks for reading. Hope this helps! See you in the next articles.</p><p>PS: Really benefited from especially Baeldung and other Java Tutorial Websites, as well as Official Java Documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*XOiRadomSXMFaJuh9cMCHg.png" /><figcaption>Dedicated to Dirty Java Rangers</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca85a9193aa2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Generics? 1 (Java Why? Article Series 2)]]></title>
            <link>https://kicchi.medium.com/why-generics-1-java-why-article-series-2-f81cd9cc0ec5?source=rss-54616ba631f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/f81cd9cc0ec5</guid>
            <category><![CDATA[generics]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[java-generic]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-development]]></category>
            <dc:creator><![CDATA[Hüseyin K.]]></dc:creator>
            <pubDate>Tue, 08 Nov 2022 08:57:38 GMT</pubDate>
            <atom:updated>2022-11-08T08:57:38.119Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi Java people. Ready for analyzing why we need Generics?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5BxMQjKzn_GJu-cZ9IaPMA.png" /></figure><p>I am Huseyin. Have been a .Net developer for years and Java backend and Android developer for 6 years as well as a QA Automation Engineer team member for several projects for 3 years.</p><p>Have been observing that some of my friends , especially junior developers, are <strong>not completely aware</strong> of the point of using a structure a tool. As a developer, by experiencing the reusability, abstraction and the maintainability issues for years, I decided to implement the same structure in my life and <strong>abstract myself</strong> from answering similar questions 🙂. Thus, put my effort into creating this <strong>“Why Java? Article Series”</strong>. I just wanna to help developers to code consciously.</p><p>The <strong>target audience</strong> of “Why Java? Article Series” is the ones who already know coding with Java, but also want to understand the underlying language and the system.</p><p><strong>Main purpose</strong> of these articles is to <strong>understand why we need</strong> some structures or tools in our framework in order to be conscious while using them. Of course there are a lot of sources about Java on the internet. What I experienced is that some <strong>different approaches</strong> while explaining the same thing helps people to understand the topics. What I am trying to do is actually that. A different kind of explanation from WHY point.</p><p>Articles are prepared to achieve the understanding of the topic from a step by step approach.</p><p>If these articles help you to understand a concept, I definitely feel very happy. Feel free to share and comment.</p><p>Sharing is learning at the same time! Enjoy.</p><h3>Analyzing type-specific methods</h3><p><strong>Requirement:</strong> Make a function that takes a <strong>String</strong> array and a <strong>String</strong> Collection parameter, And copies all array elements to provided collection parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*46oD0Ox6Fn_ppNBWPZSNnQ.png" /><figcaption>Note that this method is specific to String type</figcaption></figure><p><strong>Requirement</strong>: Make a function that takes an <strong>Integer</strong> array and a <strong>Integer</strong> Collection parameter, And copies all array elements to provided collection parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rPZDHQHxdWsqIjBQC3GGOw.png" /><figcaption>Note that this method is specific to Integer type</figcaption></figure><p>I wrote <strong>two</strong> different <strong>type-specific</strong> methods, each of them performing the <strong>same process</strong>.</p><h3>Is it possible to write a type-independent method?</h3><blockquote><strong>REMEMBER:</strong> In coding world, everything is designed to write less code with high efficiency.</blockquote><p><strong>Requirement</strong>: Make a <strong>type-independent</strong> method, that will accept all Non-primitive types of arrays and all types of collections, and performs the same operation <strong>without needing to cast</strong>.</p><p><strong>Solution attempt with Object</strong></p><p>Since Object is the top level parent class for all types, Why do not we use Object type that can accept all kinds of type without complaining. Let’s try!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aBOdMOJPP8RxJG5IoBkCnw.png" /></figure><p>Method looks good. Let’s call this method;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZMsAuxnA-0e50Saw4gqkRA.png" /></figure><p>It seems I achieved my goal. This method can accept any kind of object. What about the Object List that I populated? You know, I passed integer values as object. I wanna get first two items (1 and 2) and sum them up. Let’s try;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vVUH691tlKEYK1pSucH4ZA.png" /></figure><p>OMG! It seems a need casting. Everything was good until I perform a summation operation (not applicable to Object type). Since I have an Object collection, I need to cast every object to Integer before such operations.</p><p><strong>Solution attempt with Unknown Type</strong></p><p>Since we need something type-independent Let’s try unknown type collection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OLwcx_pn7lbSNZYuVb92jg.png" /></figure><p>As you see, unknown type did not work in our case. Summation operation is applicable to Number derived classes like Integer. If you doesn’t explicitly define the type, like Integer, compiler can not apply this operation.</p><h3>Generic Method</h3><p>As we see, the <strong>Object-type</strong> method and <strong>unknown-type</strong> did not help us. We need something type-independent, and moreover, <strong>we do not need to cast elements</strong>.</p><p>It means if we pass String-type Collection parameter, the method should process String-type Collection, if we pass Integer-type Collection parameter, the method should process Integer-type Collection. Thus, we do not need to cast elements for type-specific operations such as summation of two Integer elements, or concatenation of two Strings elements.</p><p><strong>Solution</strong>: Generic Method (kind of type-independent)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rTIZfPCeTAA0GEDZDWHpBQ.png" /></figure><p>Let’s create an Integer list with our brand-new generic method and apply a summation operation;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SIIs2NsTn_rc_bo5_7pQAg.png" /></figure><p>As you see, I defined the type of the ArrayList as Integer. So the method accepted that specific type. Moreover, I do not need to cast anything else. Compiler did not complain. I am happy :)</p><p>Let’s create a String list this time and apply a concatenation operation;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8weuUQwmf55vtfdWFJvfvg.png" /></figure><p>So, it is working with any kind of type. No need to cast. Type is not important any more. I can perform the same operation over different types with the help of Generic method.</p><p>I will continue explaining ‘why we need generics’, with Generic Class in the next article.</p><p>Thanks for reading. Hope this helps! See you in the next articles.</p><p>PS: Really benefited from especially Baeldung and other Java Tutorial Websites, as well as Official Java Documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*XOiRadomSXMFaJuh9cMCHg.png" /><figcaption>Dedicated to Dirty Java Rangers</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f81cd9cc0ec5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java Streams 3 Q&A (Need to know about Java Q&A Article Series 6)]]></title>
            <link>https://kicchi.medium.com/java-streams-3-q-a-need-to-know-about-java-q-a-article-series-6-4de80b052e54?source=rss-54616ba631f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/4de80b052e54</guid>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[java-stream-api]]></category>
            <category><![CDATA[java-development]]></category>
            <dc:creator><![CDATA[Hüseyin K.]]></dc:creator>
            <pubDate>Mon, 07 Nov 2022 09:06:04 GMT</pubDate>
            <atom:updated>2022-11-07T09:06:04.990Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi Java people.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Y1T7MwJ6_OKL2E5pwZv1g.png" /></figure><p>I am Huseyin. Have been a .Net developer for years and Java backend and Android developer for 6 years as well as a QA Automation Engineer team member for several projects for 3 years.</p><p>Have been getting a reasonable amount of questions from any level of Java developers for years. In the end, decided to write my own answers instead of spending my time over the same thing again and again. As a developer, by experiencing the reusability, abstraction and the maintainability issues for years, I decided to implement the same structure in my life and <strong>abstract myself</strong> from answering similar questions 🙂. Thus, put my effort into creating this <strong>“Need to know about Java Q&amp;A Article Series”</strong>. By doing so, I am comfortable about answering similar questions by just sending a link to these articles 🙂. It helped me to understand many very important concepts of Java as well.</p><p>The <strong>target audience</strong> of “Need to know about Java Q&amp;A Article Series” is the ones who already know coding with Java, but also want to improve his/her knowledge or to prepare for Java Interviews. If you are a new bee, I believe these articles may be a couple of levels higher for you.</p><p><strong>Main purpose</strong> of these articles is not to explain topics in detail. Of course there are a lot of sources about Java on the internet. What I experienced is that some <strong>different approaches</strong> while explaining the same thing helps people to understand the topics. What I am trying to do is actually that. A different kind of explanation.</p><p>Articles are prepared by Question &amp; Answer structure which I do believe is an <strong>efficient way of learning</strong>.</p><p>If these articles help you to understand a concept, I definitely feel very happy. Feel free to share and comment.</p><p>Sharing is learning at the same time! Enjoy.</p><h3>How to convert a stream of elements into a new list?</h3><p>There are a couple of ways to convert a stream to a list.</p><p>Collectors.toList() can be used since Java 8. It collects the Stream elements into an ArrayList:;</p><pre>Stream.of(“A”, “B”, “C”, “D”).collect(Collectors.toList());</pre><p>Collectors.toUnmodifiableList() can be used since Java 10;</p><pre><em>Stream.of(“A”, “B”, “C”, “D”)<br>      .collect(Collectors.toUnmodifiableList());</em></pre><p>Note that this produces an unmodifiable list. That is, add and remove methods are not allowed, if you use them, you will get an UnsupportedOperationException.</p><p>Stream.toList() can be used since Java 16 which again returns an immutable list like above;</p><pre><em>Stream.of(“A”, “B”, “C”, “D”).toList();</em></pre><p>If we need different Set implementation of List interface, then we can use Collectors.toSet();</p><pre><em>Stream.of(“A”, “B”, “C”, “D”).collect(Collectors.toSet());</em></pre><h3>What is the difference between groupingBy() and partitioningBy() methods?</h3><p>groupingBy and partitioning by are completely different methods except for they both return a map.</p><p>partitioningBy takes a <strong>Predicate</strong> interface implementation, and will <strong>always return a map with two entries</strong>, one for where the predicate is true and one for where it is false. So the <strong>key of the Map is Boolean</strong>. And the value is a <strong>List of the Stream source data type</strong>. It is possible that both entries will have empty lists, but they will <strong>exist</strong>. Example;</p><pre><em>Map&lt;Boolean, List&lt;Integer&gt;&gt; partBy = <br>   Stream<br>   .of(1, 4, 5)<br>   .collect(Collectors.partitioningBy(integer -&gt; integer % 2 == 0));</em></pre><p>In this example, partBy map has two entries, one for the true condition of the predicate, one for the false condition of the predicate. And the corresponding Lists will contain the Integer values that match the predicate. Output; <em>{false=[1, 5], true=[4]}</em></p><p>On the other hand, groupingBy method takes a <strong>Function</strong> interface implementation, and will return a map. This map’s <strong>key’s data type is Object</strong> <strong>by all means</strong>. Key’s value is determined by the <strong>output of the provided Function interface implementation</strong>. Data type of the values in this map will be the data type of the underlying data source. For example;</p><pre><em>Map&lt;Object, List&lt;Integer&gt;&gt; groupBy = <br>             Stream<br>             .of(1, 4, 5)<br>             .collect(Collectors.groupingBy(integer -&gt; integer/2));</em></pre><p>In this example, groupBy map has two entries based on the output of the lambda expression, which will produce 0 for item 1, 2 for item 4, and 2 for item 5. That means there should be two entries since there are 2 different keys; 1 and 2.</p><p>Output; <em>{0=[1], 2=[4, 5]}</em></p><p>Let’s try groupingBy with different input;</p><pre><em>Map&lt;Object, List&lt;Integer&gt;&gt; groupBy = <br>             Stream<br>              .of(4, 4, 5)<br>              .collect(Collectors.groupingBy(integer -&gt; integer/2));</em></pre><p>Output; <em>{2=[4, 4, 5]}</em></p><p>So, you will <strong>always</strong> get a <strong>map with two entries</strong> from partitioningBy method, but when groupingBy method is used the <strong>size of the returning map will depen</strong>d on the Function interface implementation. It can even return an empty map.</p><p>In the extreme case, if you send an <strong>empty</strong> stream to partitioningBy you will <strong>still get two entries</strong> in the map whereas groupingBy will return an <strong>empty map</strong>.</p><h3>Explain the Optional class and it’s methods?</h3><p><strong>Java 8</strong> introduced the final and value-based Optional class in java.util package. It is used to deal with <strong>NullPointerException</strong> in java applications which is very hard to avoid without using too many null checks. It is <strong>commonly</strong> used for checking the returning value of Stream terminal operations.</p><p>Optional is a <strong>container</strong> object which may or may not contain a non-null value. Optional provides the methods to easily <strong>check</strong> whether a variable has null value or not.</p><p>If a value is present, the <strong>isPresent()</strong> method will return true and the <strong>get()</strong> method will return the value. The <strong>orElse()</strong> method returns a default value if value is not present, <strong>ifPresent()</strong> executes a block of code if the value is present. So, these methods depend on the value presence that the optional object wraps.</p><p>Optional class has <strong>static</strong> methods like <strong>of()</strong> which creates an optional object by the provided value, and <strong>empty()</strong> which creates an empty optional object.</p><p>By using Optional, we can specify <strong>alternate</strong> <strong>values</strong> to return or <strong>alternate</strong> <strong>code</strong> to run. This makes the code more <strong>readable</strong> because the facts which were hidden are now visible to the developer.</p><h3>What is the “ :: “ operator?</h3><p>The double colon (::) operator is the <strong>method reference operator</strong> in Java. Method references are a <strong>special type of lambda expressions</strong>. Lambda expressions are used to create <strong>anonymous methods</strong>. Sometimes, however, a lambda expression does nothing but call an <strong>existing</strong> method like this example;</p><pre><em>messages.forEach(word -&gt; StringUtils.capitalize(word));</em></pre><p>In those cases, it’s often clearer to refer to the <strong>existing method by name</strong> like this example;</p><pre><em>messages.forEach(StringUtils::capitalize);</em></pre><p><em>Syntax; &lt;Class name&gt;::&lt;method name&gt;</em></p><p><strong>Static methods</strong> (like above example), <strong>instance methods</strong> and <strong>constructors</strong> can be referenced with double colon operator;</p><h3>Explain the types of Method References with implementation.</h3><p><strong>Static method </strong>referencing;</p><pre><em>messages.forEach(StringUtils::capitalize);</em></pre><p><strong>instance method </strong>referencing<strong>;</strong></p><pre><em>animals.stream().map(Animal::getKind).collect(Collectors.toSet());</em></pre><p><strong>constructor</strong> referencing;</p><pre><em>people.stream().collect(Collectors.toCollection(TreeSet::new));</em></pre><h3>How to create a reference to an existing constructor with :: operator?</h3><p>Constructor referencing can be achieved with new keyword after double colon operator;</p><pre><em>people.stream().collect(Collectors.toCollection(TreeSet::new));</em></pre><p>The example below creates a set of pets by invoking the constructor of Pet class for each animal name of the underlying String type stream;</p><pre><em>Stream.of(“Chikki The Second”, “Crazy Budgie”)<br>      .map(Pet::new)<br>      .collect(Collectors.toSet());</em></pre><p>Thanks for reading. Hope this helps! See you in the next articles.</p><p>PS: Really benefited from especially Baeldung and other Java Tutorial Websites, as well as Official Java Documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*XOiRadomSXMFaJuh9cMCHg.png" /><figcaption>Dedicated to Dirty Java Rangers</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4de80b052e54" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>