<?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 Mret on Medium]]></title>
        <description><![CDATA[Stories by Mret on Medium]]></description>
        <link>https://medium.com/@ductin.tran?source=rss-b8a5fc6c09e5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*k1MafNanMdpCEFqCuoLDGw.jpeg</url>
            <title>Stories by Mret on Medium</title>
            <link>https://medium.com/@ductin.tran?source=rss-b8a5fc6c09e5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 09:46:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ductin.tran/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[Quarkus in practice — Starting with Quarkus]]></title>
            <link>https://medium.com/javaholic/quarkus-in-practice-starting-with-quarkus-14a94da948fc?source=rss-b8a5fc6c09e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/14a94da948fc</guid>
            <category><![CDATA[quarkus]]></category>
            <category><![CDATA[cloud-services]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[rest-api]]></category>
            <dc:creator><![CDATA[Mret]]></dc:creator>
            <pubDate>Sat, 28 Nov 2020 13:38:42 GMT</pubDate>
            <atom:updated>2020-11-28T13:41:32.123Z</atom:updated>
            <content:encoded><![CDATA[<h3>Quarkus in practice — Starting with Quarkus</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O2FRdbztVqIWvVh7oLy0Pg.png" /></figure><blockquote>Quarkus is SUPERSONIC SUBATOMIC JAVA, A Kubernetes Native Java stack tailored for OpenJDK HotSpot and GraalVM, crafted from the best of breed Java libraries and standards.</blockquote><h3>Prerequisites</h3><ul><li>Less than 10 minutes in reading.</li><li>15 minus in practice</li><li>Experience on Java, Rest Services.</li></ul><h3><strong>Introduction</strong></h3><p>Recently, Quarkus has been becoming a very popular framework that wrapped Java stacks to help you quickly develop and containerize your REST services with native images that is lightweight and reactive. When combined with <a href="https://www.baeldung.com/graal-java-jit-compiler">GraalVM</a>, Quarkus will compile ahead-of-time (AOT), you can even hotload your application without restarting it. In this series, we will go step by step from creating very first services endpoint to publish them on cloud.</p><h3><strong>Create first quarkus application</strong></h3><p>Quarkus support you quickly generate project at <a href="https://code.quarkus.io/">https://code.quarkus.io/</a></p><p>You can choose either Maven or Gradle as your dependency management ( I use gradle), then tick on <strong>RESTEasy JAX-RS </strong>to create a basic rest service ( we will add more extensions later.</p><p>Click on <strong>Generate your application</strong>, download it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UOdlxfzmLNHjIG2_eP4ICg.png" /></figure><p>Open your project and you can see the structure</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*mzjDZAvkucYMTT8kqE3nZg.png" /></figure><p>Your main code will be located in src/main/java, let’s discover ExampleResource.java, you can see quarkus generate for you an endpoint, now we will try to run it.</p><p>To start the application, open your command line and use this command:</p><p>Maven</p><blockquote>./mvnw quarkus:dev</blockquote><p>Gradle</p><blockquote>./gradlew quarkusDev</blockquote><p>By default quarkus will start application on port 8080. Go to <a href="http://localhost:8080/">http://localhost:8080</a> you will see this page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*28vEjR01TlWpVn8pzoYJiQ.png" /></figure><p>Now we will access our rest endpoint, you postman or type directly on browser : <a href="http://localhost:8080/resteasy/hello">http://localhost:8080/resteasy/hello</a> . You will see “hello” printed out on the seen, so our endpoint was started successfully, pretty straightforward, right ? ;)</p><h3><strong>Hot reload</strong></h3><p>The most interesting part , hot reload in java :) . You may hear a lot about it in React, Vue, or in modern languages,.. now Quarkus brings it to Java.</p><p>Keep your application running, go to ExampleResource.java, modify the code to print out new text e.g : Hello Quarkus</p><pre>@GET<br>@Produces(MediaType.<em>TEXT_PLAIN</em>)<br>public String hello() {<br>    return &quot;hello Quarkus&quot;;<br>}</pre><p>Reload <a href="http://localhost:8080/resteasy/hello">http://localhost:8080/resteasy/hello</a> and you will see the magic. You don’t even need to restart your application to have the new code applied, everything is compiled ahead-of-time.</p><h3><strong>Conclusion</strong></h3><p>Good start with Quarkus, I will come with the next topic, how we can create a CRUD demo Rest service using Quarkus.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14a94da948fc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javaholic/quarkus-in-practice-starting-with-quarkus-14a94da948fc">Quarkus in practice — Starting with Quarkus</a> was originally published in <a href="https://medium.com/javaholic">javaholic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use Java Optional OrElse and OrElseGet wisely]]></title>
            <link>https://medium.com/@ductin.tran/use-java-optional-orelse-and-orelseget-wisely-4eebb50aa12e?source=rss-b8a5fc6c09e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/4eebb50aa12e</guid>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[optional-type]]></category>
            <category><![CDATA[code]]></category>
            <dc:creator><![CDATA[Mret]]></dc:creator>
            <pubDate>Thu, 09 Jul 2020 17:33:32 GMT</pubDate>
            <atom:updated>2020-07-09T17:36:18.419Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JahdNdHZ2myDp5dSv9KIxA.jpeg" /></figure><h3>1. Introduction</h3><p>Optional was introduced in Java 8 that helps us a lot on handling the Null Object and avoids legendary Null Pointer Exception. There are two common methods that usually get us confused: OrElse() and OrElseGet(). Most of the cases, the developer uses OrElse(), but is it optimized ? What is the benefit of orElseGet() ? Let us take a look through this article.</p><h3>2. OrElse vs. OrElseGet</h3><p>Firstly, let’s dive into the <a href="https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html#orElse-T-">Javadocs</a> :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dac21d87c5ce0e2225a12e61b018a9bd/href">https://medium.com/media/dac21d87c5ce0e2225a12e61b018a9bd/href</a></iframe><p>Ok, both of them will return an object as the answer if the <em>Optional.isPresent() == false,</em> but while orElse() takes any parameter type T, orElseGet() takes a functional interface Supplier for the input. Now let’s dive deeper in their usage by this example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c53b634afe28488d5174be82afc6c5a7/href">https://medium.com/media/c53b634afe28488d5174be82afc6c5a7/href</a></iframe><p>The result is :</p><pre>Use orElse with Object not null<br>-&gt; Optional is not present, return other object<br>Use orElse with Object null<br>-&gt; Optional is not present, return other object<br>Use orElseGet with Object not null<br>Use orElseGet with Object null<br>-&gt; Optional is not present, return other object</pre><p>So now we can see with OrElse(), the function <em>doSomeStuff()</em> will always be called even when the Optional has value, whereas in the OrElseGet(), it only runs when Optional has value as <em>null.</em></p><h3><strong>3. Performance Impact</strong></h3><p>Now we can understand how those two methods work. Obviously, we can recognize that the orElse() will make redundant calls if we don’t use it wisely. Image that if the <em>doSomeStuff() </em>does some heavy stuffs or gets the result of a Rest Service, then it’s absolutely a performance issue. I will give you an example to show how bad it can be, when we misuse orElse.</p><p><em>Suppose that we have some Nodes, each Node will link to its parent. A node is marked as a bad Node by the property isBadNode. We will write a function to find the first BAD ancestor of a given node.</em></p><p>Now we will use the OrElse() and OrElseGet() inside a recursion to compare the performance impact.</p><p>Let’s take a look at the code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd4330b7fc766f84cb2ef45d23360002/href">https://medium.com/media/dd4330b7fc766f84cb2ef45d23360002/href</a></iframe><p>And the output is :</p><pre> — — — — -Find node with orElse — — — — — — <br>checking node: node-1<br>checking node: node-2<br>Found bad node: node-2<br>checking node: node-3<br>checking node: node-4<br>checking node: node-5<br>checking node: node-6<br>checking node: node-7<br>checking node: node-8<br>checking node: node-9<br>checking node: node-10<br>checking node: node-10<br>Bad node is node-2</pre><p>Apparently, since we use orElseGet(), although we found node-2 is the bad node, all the nodes had been travelled. Absolutely a misusing of orElse here !.</p><p>Let’s modify the findNode function to use orElseGet then we have the output :</p><pre>checking node: node-1<br>checking node: node-2<br>Found bad node: node-2<br>Bad node is node-2</pre><p>The code now is definitely optimized !.</p><h3>4.Conclusion</h3><p>In nutshell, orElse is a good choice if the parameter is constant, static variable, or caching result, but in case of calling functions, producing new objects,… then orElseGet is a must-choice.</p><p>Happy &amp; wise coding !.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4eebb50aa12e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>