<?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 Omkar Kulkarni on Medium]]></title>
        <description><![CDATA[Stories by Omkar Kulkarni on Medium]]></description>
        <link>https://medium.com/@omkar15525?source=rss-908f3fe675b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*_J0JUqhWqRMsddKc.jpg</url>
            <title>Stories by Omkar Kulkarni on Medium</title>
            <link>https://medium.com/@omkar15525?source=rss-908f3fe675b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 07:51:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@omkar15525/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[Java Streams for Beginners]]></title>
            <link>https://medium.com/javarevisited/java-streams-for-beginners-105ed3aa2f74?source=rss-908f3fe675b------2</link>
            <guid isPermaLink="false">https://medium.com/p/105ed3aa2f74</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[stream]]></category>
            <category><![CDATA[java-8-feature]]></category>
            <category><![CDATA[java8]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Omkar Kulkarni]]></dc:creator>
            <pubDate>Sun, 07 Feb 2021 13:21:51 GMT</pubDate>
            <atom:updated>2021-02-07T14:31:40.324Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZivgMuoVKGP1-b_PKt1yDg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@w_s?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Wjatscheslaw Spiemann</a> on <a href="https://unsplash.com/s/photos/stream?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Stream API was introduced in Java 8. It is used to process the collections of objects. With the help of Streams and Lambda functions, we can write clean, concise and understandable code.</p><p>Streams is pipeline of operations, which we can use to evaluate the data.</p><figure><a href="https://javarevisited.blogspot.com/2018/08/top-5-java-8-courses-to-learn-online.html"><img alt="" src="https://cdn-images-1.medium.com/max/805/1*T6EGTlyOvMOoOIgn9xGybA.png" /></a></figure><p><a href="https://medium.com/javarevisited/7-best-java-tutorials-and-books-to-learn-lambda-expression-and-stream-api-and-other-features-3083e6038e14?source=---------14------------------">Streams </a>have intermediate and terminal operations which we can use as per our requirement. Here’s a list of Operations:</p><p><strong>Intermediate</strong> <strong>Operations</strong>: peek, flatMap, limit, sort, distinct, map, filter etc</p><p><strong>Terminal</strong> <strong>Operations</strong>: noneMatch, allMatch, collect, findAny, findFirst, anyMatch, toArray, reduce, min, max, forEach, collect, count etc.</p><h4>How do we create a Stream object?</h4><pre>List&lt;Integer&gt; numbers = Arrays.<em>asList</em>(1,2,3,4,5,6,7,8,9,10);<br>Stream&lt;Integer&gt; numberStream = numbers.stream();<br>Stream&lt;Integer&gt; newNumberStream = Stream.<em>of</em>(1,2,3,4,5,6,7,8,9,10);</pre><p>Both the ways mentioned above provide us the stream object. Either we call the<strong><em> stream()</em></strong> method over the <a href="https://medium.com/javarevisited/50-java-collections-interview-questions-for-beginners-and-experienced-programmers-4d2c224cc5ab">collection object</a> or we pass the values directly to the <strong>Stream.of()</strong> method.</p><h4>Lets see how the<strong> intermediate methods </strong>in the Streams Work:</h4><ol><li><strong>Map:</strong></li></ol><p><a href="https://medium.com/javarevisited/how-to-use-streams-map-filter-and-collect-methods-in-java-1e13609a318b">map() </a>method is used to perform an operation over the collection list. Lets see how can we create a list of cubes of the number provided in the given list.</p><pre>List&lt;Integer&gt; numbers = Arrays.<em>asList</em>(1,2,3,4,5,6,7,8,9,10);<br><br>List&lt;Integer&gt; cubedNumbers= numbers.stream()<br>        .map(x -&gt; x*x*x).collect(Collectors.<em>toList</em>());<br><br>System.<em>out</em>.print(cubedNumbers);</pre><p>The output that the we see here is :</p><pre>[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]</pre><p><strong>2. Filter:</strong></p><p><a href="https://www.java67.com/2018/03/java-8-stream-find-first-and-filter-example.html">filter(</a>) method used to filter out the results as per our conditions. Now lets consider we want to filter out even numbers from the list of numbers from 1 to 10.</p><pre>List&lt;Integer&gt; numbers = Arrays.<em>asList</em>(1,2,3,4,5,6,7,8,9,10);<br><br>List&lt;Integer&gt; evenNumbers = numbers.stream()<br>        .filter(x -&gt; x%2==0).collect(Collectors.<em>toList</em>());<br><br><br> System.<em>out</em>.print(evenNumbers);</pre><p>The output would be:</p><pre>[2, 4, 6, 8, 10]</pre><p><strong>3. Sort:</strong></p><p>Now if you wish to sort the given collection, <a href="https://medium.com/javarevisited/7-best-java-collections-and-stream-api-courses-for-beginners-in-2020-3ad18d52c38">Streams </a>at your service!! You can use the sorted() method as an intermediate function for the sorting.</p><pre>List&lt;Integer&gt; numbers = Arrays.<em>asList</em>(6,7,8,1,4,5,9,10,2,3);</pre><pre>List&lt;Integer&gt; sortedList = numbers.stream().sorted().collect(Collectors.<em>toList</em>());<br><br>System.<em>out</em>.print(sortedList);</pre><p>The output here would be:</p><pre>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]</pre><p><strong>4. FlatMap:</strong></p><p><a href="http://www.java67.com/2016/03/how-to-use-flatmap-in-java-8-stream.html">flatMap()</a> is used to convert 2 levels of stream into 1 level of stream. In simple words if we have a collection of arrayList which consists of arrayList, then with the help of flatMap() we can convert them into a single ArrayList.</p><pre>List&lt;Integer&gt; list1 = Arrays.<em>asList</em>(1,2,3);<br>List&lt;Integer&gt; list2 = Arrays.<em>asList</em>(4,5,6);<br>List&lt;Integer&gt; list3 = Arrays.<em>asList</em>(7,8,9);<br><br>List&lt;List&lt;Integer&gt;&gt; listOfNumbers = Arrays.<em>asList</em>(list1, list2, list3);<br><br>List&lt;Integer&gt; listOfAllIntegers = listOfNumbers.stream()<br>        .flatMap(x -&gt; x.stream())<br>        .collect(Collectors.<em>toList</em>());<br><br>System.<em>out</em>.println(listOfAllIntegers);</pre><p>The output would be like this:</p><pre>[1, 2, 3, 4, 5, 6, 7, 8, 9]</pre><p><strong>5. Distinct:</strong></p><p>If the given collection has duplicate items, we can use the distinct() method to remove the duplicate items and have a filtered collection.</p><pre>List&lt;String&gt; countries = Arrays.<em>asList</em>(&quot;India&quot;, &quot;Australia&quot;, &quot;SriLanka&quot;,&quot;Russia&quot;, &quot;Australia&quot;,&quot;SriLanka&quot;,&quot;India&quot;);<br><br>List&lt;String&gt; distinctCountries = countries.stream().distinct()<br>.collect(Collectors.<em>toList</em>());<br>    System.<em>out</em>.println(distinctCountries);<br>}</pre><p>The Output here would be :</p><pre>[India, Australia, SriLanka, Russia]</pre><p><strong>6. Peek:</strong></p><p><strong>peek()</strong> is an <strong>intermediate </strong>action. <a href="https://www.java67.com/2016/09/java-8-streampeek-example.html"><strong>peek()</strong></a> returns a stream consisting of the elements of the traversed stream, additionally performing the provided action on each element as elements are consumed from the resulting stream.</p><p>peek() operation does nothing if we do not specify a terminal operation.</p><pre>Stream.<em>of</em>(1,2,3,4,5,6,7,8,9,0)<br>        .filter(x -&gt; x%2 ==0)<br>        .peek(e -&gt; System.<em>out</em>.println(&quot;The even numbers <br>         are : &quot; + e))<br>        .collect(Collectors.<em>toList</em>());</pre><p>This provides the output :</p><pre>The even numbers are : 2<br>The even numbers are : 4<br>The even numbers are : 6<br>The even numbers are : 8<br>The even numbers are : 0</pre><h4>Now lets have a look with the terminal operations:</h4><ol><li><strong>Collect:</strong></li></ol><p><a href="https://www.java67.com/2018/06/java-8-streamcollect-example.html">collect()</a> operation helps to collect the stream into a collection. This method takes a Collector implementation that provides useful reduction operations.</p><pre>List listOfCountries = Arrays.<em>asList</em>(&quot;India&quot;, &quot;Indonesia&quot;, &quot;Nepal&quot;, &quot;Afghanistan&quot;);<br><br>List output = (List) listOfCountries.stream()<br>        .filter(x-&gt; x.toString().startsWith(&quot;I&quot;))<br>        .collect(Collectors.<em>toList</em>());<br>System.<em>out</em>.println(output);</pre><p>Output :</p><pre>[India, Indonesia]</pre><p><strong>2. Count:</strong></p><p><strong>count()</strong> terminal operation helps us to find the count of the processed collection.</p><pre>List listOfCountries = Arrays.<em>asList</em>(&quot;India&quot;, &quot;Indonesia&quot;, &quot;Nepal&quot;, &quot;Afghanistan&quot;);<br><br>long output = listOfCountries.stream()<br>        .filter(x-&gt; x.toString().startsWith(&quot;I&quot;))<br>        .count();<br><br>System.<em>out</em>.println(output);</pre><p>Output :</p><pre>2</pre><p><strong>3. AllMatch:</strong></p><p>allMatch() operation helps us to get the answer:<strong><em> Do all the elements of the stream match the condition?</em></strong></p><pre>List listOfCountries = Arrays.<em>asList</em>(&quot;India&quot;, &quot;Indonesia&quot;, &quot;Nepal&quot;, &quot;Afghanistan&quot;);<br><br>boolean areAllElementsStartingWithI = listOfCountries.stream()<br>        .allMatch(x -&gt; x.toString().startsWith(&quot;I&quot;));<br><br>System.<em>out</em>.println(areAllElementsStartingWithI);</pre><p>Output:</p><pre>false</pre><p><strong>4. AnyMatch:</strong></p><p>As compared to the allMatch() anyMatch() helps to check if either one of the elements in the stream matched the condition.</p><pre>List listOfCountries = Arrays.<em>asList</em>(&quot;India&quot;, &quot;Indonesia&quot;, &quot;Nepal&quot;, &quot;Afghanistan&quot;);<br><br>boolean areAllElementsStartingWithI = listOfCountries.stream()<br>        .anyMatch(x -&gt; x.toString().startsWith(&quot;I&quot;));<br><br>System.<em>out</em>.println(areAllElementsStartingWithI);</pre><p>Output:</p><pre>true</pre><p><strong>5. ForEach:</strong></p><p><a href="https://www.java67.com/2016/01/how-to-use-foreach-method-in-java-8-examples.html">forEach()</a> method is used to iterate over the resultant collection, same as that of the traditional for loop.</p><pre>List listOfCountries = Arrays.<em>asList</em>(&quot;India&quot;, &quot;Indonesia&quot;, &quot;Nepal&quot;, &quot;Afghanistan&quot;);<br><br>listOfCountries.stream()<br>         .filter(x-&gt; x.toString().startsWith(&quot;I&quot;))<br>         .forEach(System.<em>out</em>::println);</pre><p>Output:</p><pre>India<br>Indonesia</pre><p>That was it!! Have fun use the streams very often henceforth!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=105ed3aa2f74" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/java-streams-for-beginners-105ed3aa2f74">Java Streams for Beginners</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bridge Design Pattern for Begineers]]></title>
            <link>https://medium.com/javarevisited/bridge-design-pattern-for-begineers-aabd85e103e8?source=rss-908f3fe675b------2</link>
            <guid isPermaLink="false">https://medium.com/p/aabd85e103e8</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Omkar Kulkarni]]></dc:creator>
            <pubDate>Mon, 25 Jan 2021 07:01:18 GMT</pubDate>
            <atom:updated>2021-01-25T07:01:18.733Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*guT8Cm1NMuaqgNteAmzD4w.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@jack_anstey?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Jack Anstey</a> on <a href="https://unsplash.com/s/photos/bridges?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Bridge Design Pattern is one of the gang-of-four-design-patterns.</p><p>Bridge Design Pattern comes under the Structural Design pattern. It helps us to decouple the abstraction and implementation.</p><p>Due to which the abstraction and implementation can be developed and fixed separately.</p><p>Let&#39;s look at the real-time example. Say you go to a hotel and order some food.</p><p>Food being prepared is <a href="https://javarevisited.blogspot.com/2010/10/abstraction-in-java.html">Abstraction</a>. You do not care about what&#39;s happening inside. The only thing you care about is, is the implementation correctly done and is the food being served to you in proper time.</p><p>The waiter who serves you the food forms the Bridge between the chefs that prepare the food and you the one who is going to enjoy it.</p><p>Let&#39;s get the hands dirty and see how this pattern is being implemented.</p><p>Consider an example of <strong>Notifications</strong>. There are push notifications in Android Mobiles and we can get notified using text messages as well.</p><pre>package bridgedesignpattern;<br><br>public abstract class Notification {<br>    NotificationSender notificationSender;<br><br>    public Notification(NotificationSender notificationSender) {<br>        this.notificationSender = notificationSender;<br>    }<br><br>    abstract public void send();<br>}</pre><p>Notification class would have a data member as NotificationSender, and would also have a send() method. NotificationSender class would look like this.</p><pre>public interface NotificationSender {<br>    public void sendNotification();<br>}</pre><p>Now we would have two different classes for “TextNotification” and “PushNotification”.</p><pre>package bridgedesignpattern;<br><br>public class PushNotification extends Notification {<br>    public PushNotification(NotificationSender notificationSender) {<br>        super(notificationSender);<br>    }<br><br>    @Override<br>    public void send() {<br>        notificationSender.sendNotification();<br>    }<br>}</pre><p>And here goes the “TextNotification” class.</p><pre>public class TextNotification extends Notification {<br><br>    public TextNotification(NotificationSender notificationSender) {<br>        super(notificationSender);<br>    }<br><br>    @Override<br>    public void send() {<br>        notificationSender.sendNotification();<br>    }<br>}</pre><p>We would have a PushNotificationSender class which would send notification.</p><pre>package bridgedesignpattern;<br><br>public class PushNotificationSender implements NotificationSender {<br>    @Override<br>    public void sendNotification() {<br>        System.<em>out</em>.println(&quot;Push Notification sending.......&quot;);<br>    }<br>}</pre><p>On similiar lines TextNotificationSender class would send text notification.</p><pre>package bridgedesignpattern;</pre><pre>public class TextNotificationSender implements NotificationSender {<br>    @Override<br>    public void sendNotification() {<br>        System.<em>out</em>.println(&quot;Text Notification sending.......&quot;);<br>    }<br>}</pre><p>Now lets if the code works:</p><pre>package bridgedesignpattern;<br><br>public class NotificationSenderImplementation {<br>    public static void main(String[] args) {<br>        <em>//For push notification<br>        </em>NotificationSender notificationSender = new PushNotificationSender();<br>        Notification notification = new PushNotification(notificationSender);<br>        notification.send();<br><br>        <em>//For text notification<br>        </em>NotificationSender textNotificationSender = new TextNotificationSender();<br>        Notification textNotification = new TextNotification(textNotificationSender);<br>        textNotification.send();<br>    }<br>}</pre><p>And its done, we have the output as:</p><pre>Push Notification sending.......<br>Text Notification sending.......</pre><h3>What have we achieved?</h3><ul><li>Decoupling: The implementation and <a href="https://javarevisited.blogspot.com/2017/04/difference-between-abstraction-and-encapsulation-in-java-oop.html">abstraction </a>is decoupled and both can be developed separately.</li><li>A better solution for cross-platform development.</li><li>It helps two incompatible interfaces to work together.</li></ul><p>Happy Coding!!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aabd85e103e8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/bridge-design-pattern-for-begineers-aabd85e103e8">Bridge Design Pattern for Begineers</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Most Favorite Topic in Indian Java Interviews :HashMap]]></title>
            <link>https://omkar15525.medium.com/the-most-favorite-topic-in-indian-java-interviews-hashmap-1053808f0eef?source=rss-908f3fe675b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1053808f0eef</guid>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[interview-tips]]></category>
            <category><![CDATA[interview-preparation]]></category>
            <category><![CDATA[java8]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Omkar Kulkarni]]></dc:creator>
            <pubDate>Sun, 17 Jan 2021 15:02:54 GMT</pubDate>
            <atom:updated>2021-01-17T15:02:54.666Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Most Favorite Topic in Indian Java Interviews :HashMap</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GbhoZe-G1552CxXtz7b2ZA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@clemono?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Clem Onojeghuo</a> on <a href="https://unsplash.com/s/photos/job-interview?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Recently I had started searching for new opportunities and started giving interviews. I think I gave 30+ interviews and this topic was present in almost every interview which I attended.</p><p>HashMap is one of the dearest topic of all the technical interviewers all over India. After the basics you get hit by any one of the HashMap questions.</p><p>Lets explore the HashMap topic and the questions related to it.</p><h4><strong>Q.</strong> What is the underlying DataStructure of HashMap?</h4><p><strong>Ans: </strong>Hashmap is the implementation of Map interface and the underlying Data structure is the HashTable.</p><h4><strong>Q. </strong>What are the features of HashMap?</h4><p>Ans: The features of the HashMap are listed below :</p><ul><li>Values in HashMap are stored in Key Value pairs. Each Key Value pair is called the EntrySet.</li><li>Insertion order is preserved in HashMap and the order is based on the hashcode of the keys.</li></ul><blockquote>In Hashmap duplicate keys are not allowed but values can be duplicate.</blockquote><ul><li>Null value is allowed for the key only once, but allowed more than once times for the values.</li><li>Heterogenous objects can be stored for both keys and values.</li><li>HashMap implements <strong><em>Serializable </em></strong>&amp; <strong><em>Cloneable </em></strong>interfaces but not random access.</li></ul><h4>Q. When should HashMap be used?</h4><p>Ans: If frequent operation is searching, HashMap is the best collection choice.</p><h4>Q.What is the default capacity of HashMap? What is the fill ratio for HashMap?</h4><p>Ans: The default capacity is 16. And the fill ratio is 0.75.</p><h4>Q. Is HashMap synchronized? If not, How can we get synchronized version of HashMap?</h4><p>Ans: By default HashMap is not synchronized.</p><pre>HashMap&lt;Integer, String&gt; hashMap = <strong>new </strong>HashMap();<br>Map&lt;Integer, String&gt; synchronizedHashMap = Collections.<em>synchronizedMap</em>(hashMap);</pre><p>We can make it synchronized by passing map to Collections.<em>synchronizedMap() , </em>the return type of this method is map.</p><h4>Q. What is the internal working of HashMap?</h4><p>Ans: HashMap works on the technique of hashing. Hashing is a technique where we convert the object into the integer value called as the hashcode with the help of the method hashcode().</p><p>The hashcode() method returns the integer value of the memory address of that object. Each EntrySet in the HashMap has a separate hashCode assigned to it.</p><p>Lets get our hands dirty and see the implementation of HashMap.</p><pre>HashMap&lt;Integer, String&gt; hashMap = <strong>new </strong>HashMap();<br>hashMap.put(1, <strong>&quot;a&quot;</strong>);<br>hashMap.put(2, <strong>&quot;b&quot;</strong>);<br>hashMap.put(3, <strong>&quot;c&quot;</strong>);<br>hashMap.put(4, <strong>&quot;d&quot;</strong>);<br>System.<strong><em>out</em></strong>.println(<strong>&quot;1. The value of the hashmap is ::&quot; </strong>+ hashMap);</pre><p>Here we have entered values in the hashMap object and the <strong>output </strong>as we can see here would be like :</p><pre>1. The value of the hashmap is ::{1=a, 2=b, 3=c, 4=d}</pre><p>Now If we try to add one more value for the key “4”, the value gets updated.</p><pre>hashMap.put(4, <strong>&quot;e&quot;</strong>);<br><br>System.<strong><em>out</em></strong>.println(<strong>&quot;2. The value of the hashmap is ::&quot; </strong>+ hashMap);</pre><p><strong>Output:</strong></p><pre>1. The value of the hashmap is ::{1=a, 2=b, 3=c, 4=d}<br>2. The value of the hashmap is ::{1=a, 2=b, 3=c, 4=e}</pre><p>Now lets try adding a <strong><em>null </em></strong>key and see how the hashmap behaves:</p><pre>hashMap.put(<strong>null</strong>, <strong>&quot;f&quot;</strong>);<br>System.<strong><em>out</em></strong>.println(<strong>&quot;3. The value of the hashmap is ::&quot; </strong>+ hashMap);</pre><p><strong>Output:</strong></p><pre>3. The value of the hashmap is ::{null=f, 1=a, 2=b, 3=c, 4=e}</pre><p>If we try to add one more null value then the value already presetn against the null is overridden.</p><pre>hashMap.put(<strong>null</strong>, <strong>&quot;g&quot;</strong>);<br>System.<strong><em>out</em></strong>.println(<strong>&quot;4. The value of the hashmap is ::&quot; </strong>+ hashMap);</pre><p><strong>Output:</strong></p><pre>4. The value of the hashmap is ::{null=g, 1=a, 2=b, 3=c, 4=e}</pre><p>There are few more questions that are asked related to the HashMap</p><h4>Q. What is the difference between the HashMap and the HashTable?</h4><p>Ans: The differences are as listed below:</p><ul><li><strong>Every method in the HashTable is synchronized</strong> whereas in HashMap every method is not synchronized.</li><li>HashTable is <strong>Thread Safe</strong> whereas HashMap is not Thread Safe.</li><li>HashTable being Thread Safe it is <strong>lower in performance</strong> as compared to the HashMap</li><li><strong>HashTable </strong>was present in the Java Libraries since <strong>1.0 version</strong> whereas <strong>HashMap </strong>was introduced in <strong>1.2 version</strong>.</li></ul><p>I have tried to cover all the questions that were asked to me in the interview span. I would be covering LinkedHashMap and ConcurrentHashMap in another article.</p><p>Get these questions prepared and impress the interviewers. Cheers!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1053808f0eef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Singleton Design Pattern for Beginners]]></title>
            <link>https://medium.com/javarevisited/singleton-design-pattern-for-beginners-3ababda0fe8c?source=rss-908f3fe675b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ababda0fe8c</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Omkar Kulkarni]]></dc:creator>
            <pubDate>Wed, 13 Jan 2021 07:11:36 GMT</pubDate>
            <atom:updated>2021-01-13T07:11:36.854Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zsQwe3VA4Qc0qt-TOOlSIw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@dkosta4?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Deepak Kosta</a> on <a href="https://unsplash.com/s/photos/architecture-indian?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Singleton is one of the Creational Design Patterns in Java. Creational Design pattern are those which are used to create objects.</p><p>With the help of a singleton design pattern, we can restrict the object creation to only one instance. And once the object is instantiated, the same object is reused all over the application.</p><p>Singleton Design pattern is also one of the hot topics of the <a href="https://medium.com/javarevisited/21-spring-mvc-rest-interview-questions-answers-for-beginners-and-experienced-developers-21ad3d4c9b82">interviews</a>. Right from the beginner level to the experienced ones you ought to find a question about this design pattern.</p><h3>Implementation</h3><p>Let&#39;s see how the <a href="https://www.java67.com/2020/05/5-ways-to-implement-singleton-design.html">Singleton Design Pattern</a> is implemented. For implementing Singleton we need to make the constructor of the class private and the object instance is returned from the static getInstance() method.</p><p>There are basically three approaches to implement the Singleton Design Pattern.</p><h4>Eager Instantiation:</h4><p>Here the object is created at the instant it is declared. Because of this approach, memory is consumed unnecessarily. The memory is kept occupied since the start of the application execution, even though the <a href="https://javarevisited.blogspot.com/2011/03/10-interview-questions-on-singleton.html">Singleton object</a> is used in the far later part. This is basically an memory costly approach, which may lead to a <a href="https://medium.com/javarevisited/7-best-courses-to-learn-jvm-garbage-collection-and-performance-tuning-for-experienced-java-331705180686">performance </a>decrease.</p><pre>public class SingletonEagerInstantiationExample {<br>    private static final SingletonEagerInstantiationExample <em>instance </em>= new SingletonEagerInstantiationExample();<br><br>    private SingletonEagerInstantiationExample() {<br>    }<br><br>    public SingletonEagerInstantiationExample getInstance() {<br>        return <em>instance</em>;<br>    }<br>}</pre><h4>Lazy Instantiation:</h4><p>As the name suggests, the object is instantiated only when the getInstance() method is called. This is memory efficient approach. It ensures that the memory is utilized only when the execution needs to be done.</p><pre>public class SingletonLazyInstantiationExample {<br>    private static SingletonLazyInstantiationExample <em>instance </em>= null;<br><br>    private SingletonLazyInstantiationExample() {}<br><br>    private static SingletonLazyInstantiationExample getInstance() {<br>        if (<em>instance </em>== null) {<br>            <em>instance </em>= new SingletonLazyInstantiationExample();<br>        }<br>        return <em>instance</em>;<br>    }<br>}</pre><p>The above Lazy Instantiation is not efficient when it comes to <a href="https://www.java67.com/2015/09/thread-safe-singleton-in-java-using-double-checked-locking-pattern.html">thread safety</a>. Multiple threads can create multiple objects which may negate the thought of having a singleton approach. So there is one more approach of Singleton to be followed for Thread Safety.</p><pre>public class ThreadSafeSingleton {<br>    private static volatile ThreadSafeSingleton <em>threadSafeSingleton</em>;<br><br>    private ThreadSafeSingleton() {}<br><br>    synchronized public static ThreadSafeSingleton getInstance() {<br>        if (<em>threadSafeSingleton </em>== null) {<br>            <em>threadSafeSingleton </em>= new ThreadSafeSingleton();<br>        }<br>        return <em>threadSafeSingleton</em>;<br>    }<br>}</pre><p>The keyword <a href="https://javarevisited.blogspot.com/2011/06/volatile-keyword-java-example-tutorial.html"><strong><em>volatile </em></strong></a>is used here so that just in case if any thread makes any changes to the object, the change gets reflected across all the threads.</p><p>That was it, folks!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ababda0fe8c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/singleton-design-pattern-for-beginners-3ababda0fe8c">Singleton Design Pattern for Beginners</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Facade Design pattern for Beginners]]></title>
            <link>https://medium.com/javarevisited/facade-design-pattern-for-beginners-7dde0612d069?source=rss-908f3fe675b------2</link>
            <guid isPermaLink="false">https://medium.com/p/7dde0612d069</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java8]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Omkar Kulkarni]]></dc:creator>
            <pubDate>Sun, 10 Jan 2021 07:09:19 GMT</pubDate>
            <atom:updated>2021-01-10T07:09:19.027Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-yfPkXYrZED73Wz3b-Ysow.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@ymwang?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Yunming Wang</a> on <a href="https://unsplash.com/s/photos/dog-leash?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Facade Design Pattern is one of the subtypes of Structural Design Pattern. It is used to expose minimal implementation to the client, that too in a simple way which he can be able to understand.</p><p>Facade provides an interface that the client can use to access the system. The business logic complexities can be hidden behind the interface.</p><p><strong>Lets directly dive in and see how can we implement the Facade Design Pattern:</strong></p><p>Consider a requirement where we have to generate different reports and the data for these reports is stored on different ORM’s like <a href="https://medium.com/@javinpaul/top-5-courses-to-learn-mysql-in-2020-4ffada70656f">MYSQL </a>and DB2. So here while generating the report we will have to first establish a connection and get the data from the DB. Once the data is populated we can send the data over to the method which generates the report.</p><p>Here we will create an interface and define the common methods that can be utilized all over.</p><pre>public interface Reports {<br>    public void getDataForReports(String reportType);<br>    public void generateReport();<br>}</pre><p>We will consider two types of Reports : Customer report and Orders report. The CustomerReport class would be defined like this.</p><pre>public class CustomerReport implements Reports {<br><br>    @Override<br>    public void getDataForReports(String reportType) {<br>        <em>// BusinessLogic for getting the data for Customer Report<br>    </em>}<br><br>    @Override<br>    public void generateReport() {<br>        <em>// Business Logic for generating report;<br>    </em>}<br>}</pre><p>And the OrdersReport would be defined like this.</p><pre>public class OrderReports implements Reports{<br><br>    @Override<br>    public void getDataForReports(String reportType) {<br>        <em>// BusinessLogic for getting the data for Customer Report<br>    </em>}<br><br>    @Override<br>    public void generateReport() {<br>        <em>// Business Logic for generating report;<br>    </em>}<br>}</pre><p>Now would come the ReportsGenerator class which would act as the facade. This class would hide the actual implementation of data fetching and generating the report.</p><pre>public class ReportsGenerator {<br>    public static String generateReport(String reportType) {<br>        switch(reportType) {<br>            case &quot;Customer&quot;:<br>                Reports customerReport = new CustomerReport();<br>                customerReport.getDataForReports(reportType);<br>                customerReport.generateReport();<br>                return reportType + &quot;generated successfully!&quot;;<br><br>            case &quot;OrderReport&quot;:<br>                Reports orderReport = new OrderReports();<br>                orderReport.getDataForReports(reportType);<br>                orderReport.generateReport();<br>                return reportType + &quot;generated successfully!&quot;;<br>        }<br>        return &quot;Invalid Report Type, Please select the correct one!&quot;;<br>    }<br>}</pre><p>Now lets design the ApiHandler class which would inturn call the generateReport() method of the ReportsGenerator class.</p><pre>public class ApiHandler {<br>    public static void main(String[] args) {<br>        System.<em>out</em>.println(ReportsGenerator.<em>generateReport</em>(&quot;Customer&quot;));<br>        System.<em>out</em>.println(ReportsGenerator.<em>generateReport</em>(&quot;Order&quot;));<br>    }<br>}</pre><h4>When to use the Facade Design Pattern?</h4><p>Facade should be used when we have a complex business logic in place and we have to expose only the simplified apis to the customer.</p><h4>Advantages of Facade Desing Pattern :</h4><ul><li>We can decouple the complex system logic from the clients.</li><li>Wrapping the complex system logic is achieved using the Facade Design pattern.</li></ul><h4>Disadvantages of Facade Design Pattern :</h4><ul><li>The Facade class might become the super class in long run.</li><li>Extra level of abstraction gets added because of Facade.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7dde0612d069" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/facade-design-pattern-for-beginners-7dde0612d069">Facade Design pattern for Beginners</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Factory Design Pattern For Beginners]]></title>
            <link>https://medium.com/javarevisited/factory-design-pattern-for-beginners-addfe60aed02?source=rss-908f3fe675b------2</link>
            <guid isPermaLink="false">https://medium.com/p/addfe60aed02</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Omkar Kulkarni]]></dc:creator>
            <pubDate>Wed, 06 Jan 2021 06:19:13 GMT</pubDate>
            <atom:updated>2021-01-06T06:19:13.513Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k_8jG79dp14x2sh47vGI9g.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@rozetsky?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Ant Rozetsky</a> on <a href="https://unsplash.com/s/photos/factory?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Factory Design pattern comes under the Creational Design Pattern category of the <a href="https://medium.com/javarevisited/7-best-online-courses-to-learn-object-oriented-design-pattern-in-java-749b6399af59">Design patterns</a> along with the Builder and the Singleton Design patterns.</p><p>It provides us a mechanism where a factory method helps to create and instantiate the objects. The parent class would hold the reference to the child class in this case.</p><p>In better words, we are providing <strong><em>abstraction </em></strong>where the object creation is hidden inside the factory method. We just pass the parameter which would indicate which object needs to be created and then the factory would return the created object for us.</p><p>The construction of the objects is <strong><em>decoupled </em></strong>from the objects which forms the added advantage while following this <a href="https://javarevisited.blogspot.com/2015/06/difference-between-dependency-injection.html">Factory Design pattern</a>.</p><p>The common implementation of the child classes can be kept inside the parent class and hence code maintainability can also be achieved here. Code Duplicity is removed hence we can achieve the Don’t Repeat Yourself (D.R.Y) principle.</p><p>Let’s get our hands dirty and see how this pattern is implemented.</p><p>First things first let’s create an <a href="https://javarevisited.blogspot.com/2011/08/enum-in-java-example-tutorial.html">enum</a> that would have the language types. This enum would have the language Id and the language name.</p><pre><strong>public enum </strong>LanguageType {<br>    <strong><em>GERMAN</em></strong>(1, <strong>&quot;German&quot;</strong>),<br>    <strong><em>FRENCH</em></strong>(2, <strong>&quot;French&quot;</strong>);<br><br>    <strong>private int languageId</strong>;<br>    <strong>private </strong>String <strong>languageName</strong>;<br><br>    LanguageType(<strong>int </strong>languageId, String languageName) {<br>        <strong>this</strong>.<strong>languageId </strong>= languageId;<br>        <strong>this</strong>.<strong>languageName </strong>= languageName;<br>    }<br>}</pre><p>Now we require to have a <strong><em>super </em></strong>class Language. The super class can be an <a href="http://javarevisited.blogspot.sg/2013/05/difference-between-abstract-class-vs-interface-java-when-prefer-over-design-oops.html#axzz4pk4W5ie3"><strong>abstract class or an interface</strong></a><strong>.</strong></p><pre><strong>public abstract class </strong>Language {<br>    <strong>public abstract </strong>String greet();<br>}</pre><p>Now when the Superclass or the Parent class is created let&#39;s create the child class which would extend out parent class. This is the German Language class :</p><pre><strong>public class </strong>GermanLanguage <strong>extends </strong>Language{<br>    @Override<br>    <strong>public </strong>String greet() {<br>        <strong>return &quot;Guten Morgen&quot;</strong>;<br>    }<br>}</pre><p>And this would be the French Language class:</p><pre><strong>public class </strong>FrenchLanguage <strong>extends </strong>Language{<br>    @Override<br>    <strong>public </strong>String greet() {<br>        <strong>return &quot;Bonjour&quot;</strong>;<br>    }<br>}</pre><p>Now that the Parent class and the Child classes are in place, lets see how the factory class would be created. Here comes the LanguageFactory class:</p><pre><strong>public class </strong>LanguageFactory {<br>    <strong>public static </strong>Language getLanguage(<strong>int </strong>languageId) {<br>        <strong>if </strong>(languageId == <strong><em>GERMAN</em></strong>.getLanguageId())<br>            <strong>return new </strong>GermanLanguage();<br>        <strong>else if </strong>(languageId == <strong><em>FRENCH</em></strong>.getLanguageId())<br>            <strong>return new </strong>FrenchLanguage();<br>        <strong>return null</strong>;<br>    }<br>}</pre><p>In this case we match the languageId passed to the getLanguage() method and create the object accordingly.</p><p>And now lets see how would this implementation work.</p><pre><strong>public class </strong>LanguageImplementation {<br>    <strong>public static void </strong>main(String[] args) {<br>        Language germanLanguage = LanguageFactory.<em>getLanguage</em>(LanguageType.<strong><em>GERMAN</em></strong>.getLanguageId());<br>        Language frenchLanguage = LanguageFactory.<em>getLanguage</em>(LanguageType.<strong><em>FRENCH</em></strong>.getLanguageId());<br><br>        System.<strong><em>out</em></strong>.println(<strong>&quot;German Language Greeting : &quot; </strong>+ germanLanguage.greet());<br>        System.<strong><em>out</em></strong>.println(<strong>&quot;French Language Greeting : &quot; </strong>+ frenchLanguage.greet());<br>    }<br>}</pre><p>The output that we see here is :</p><pre>German Language Greeting : Guten Morgen<br>French Language Greeting : Bonjour</pre><p>And here we are with the Implementation.</p><p>Things we achieved using the Factory Design Pattern :</p><ol><li>Decoupling of the creation of the object from the objects.</li><li>Abstraction.</li><li>Don’t Repeat Yourself principle followed.</li></ol><p>That’s it then. Do let me know if you have any questions, in the comments box.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=addfe60aed02" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/factory-design-pattern-for-beginners-addfe60aed02">Factory Design Pattern For Beginners</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Builder Design Pattern in Java for Beginners]]></title>
            <link>https://medium.com/javarevisited/builder-design-pattern-in-java-for-beginners-9b93d2a15440?source=rss-908f3fe675b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b93d2a15440</guid>
            <category><![CDATA[builder-design-pattern]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[java8]]></category>
            <category><![CDATA[creational-design-pattern]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Omkar Kulkarni]]></dc:creator>
            <pubDate>Sat, 02 Jan 2021 04:57:44 GMT</pubDate>
            <atom:updated>2021-01-08T08:15:57.957Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="https://medium.com/javarevisited/7-best-online-courses-to-learn-object-oriented-design-pattern-in-java-749b6399af59"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r8RXECPcFPuViUNrsgV5tA.jpeg" /></a><figcaption>Photo by <a href="https://unsplash.com/@guiccunha?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Guilherme Cunha</a> on <a href="https://unsplash.com/s/photos/builder?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Builder Design Pattern is a creational design pattern used for the creation of complex objects. While creating objects from a constructor with more than four parameters we are more prone to making errors. Even if one parameter gets switched or missed, a considerable amount of time is consumed to find out what has gone wrong.</p><pre><strong>public class </strong>Customer {<br>    <strong>public </strong>String <strong>name</strong>;<br>    <strong>public </strong>String <strong>firstName</strong>;<br>    <strong>public </strong>String <strong>lastName</strong>;<br>    <strong>public int age</strong>;<br>    <strong>public </strong>String <strong>address</strong>;<br>    <strong>public </strong>String <strong>city</strong>;<br>    <strong>public </strong>String <strong>mobileNumber</strong>;<br>    <strong>public </strong>String <strong>pincode</strong>;<br><br>    <strong>public </strong>Customer(String name, <br>                    String firstName, <br>                    String lastName, <br>                    <strong>int </strong>age, <br>                    String address, <br>                    String city, <br>                    String mobileNumber,<br>                    String pincode) {<br>        <strong>this</strong>.<strong>name </strong>= name;<br>        <strong>this</strong>.<strong>firstName </strong>= firstName;<br>        <strong>this</strong>.<strong>lastName </strong>= lastName;<br>        <strong>this</strong>.<strong>age </strong>= age;<br>        <strong>this</strong>.<strong>address </strong>= address;<br>        <strong>this</strong>.<strong>city </strong>= city;<br>        <strong>this</strong>.<strong>mobileNumber </strong>= mobileNumber;<br>        <strong>this</strong>.<strong>pincode </strong>= pincode;<br>    }<br>}</pre><p>Consider the above example, the <a href="https://javarevisited.blogspot.com/2012/12/what-is-object-in-java-or-oops-example.html#axzz6ikhp68Le">object creation</a> requires eight parameters, if you miss even one then be ready to spend time on finding what is going wrong. Now, what if the customer does not provide firstName and lastName explicitly? We would have to create one more constructor, which would not accept those two parameters.</p><pre><strong>public </strong>Customer(String name, <strong>int </strong>age, String address, String city, String mobileNumber, String pincode) {<br>    <strong>this</strong>.<strong>name </strong>= name;<br>    <strong>this</strong>.<strong>age </strong>= age;<br>    <strong>this</strong>.<strong>address </strong>= address;<br>    <strong>this</strong>.<strong>city </strong>= city;<br>    <strong>this</strong>.<strong>mobileNumber </strong>= mobileNumber;<br>    <strong>this</strong>.<strong>pincode </strong>= pincode;<br>}</pre><p>If in the near future one more parameter gets added we will have to add one more constructor or edit the previous one and also add the parameter wherever the constructor has been used. Enter the <a href="http://javarevisited.blogspot.sg/2012/06/builder-design-pattern-in-java-example.html">Builder Design pattern</a> our savior. It not only helps to create objects easily, but it also helps us to maintain the code in the long run. Let&#39;s see how this is implemented.</p><pre><strong>public class </strong>Customer {<br>    <strong>public </strong>String <strong>name</strong>;<br>    <strong>public </strong>String <strong>firstName</strong>;<br>    <strong>public </strong>String <strong>lastName</strong>;<br>    <strong>public int age</strong>;<br>    <strong>public </strong>String <strong>address</strong>;<br>    <strong>public </strong>String <strong>city</strong>;<br>    <strong>public </strong>String <strong>mobileNumber</strong>;<br>    <strong>public </strong>String <strong>pincode</strong>;<br><br>    <strong>public </strong>String getName() {<br>        <strong>return name</strong>;<br>    }<br><br>    <strong>public </strong>String getFirstName() {<br>        <strong>return firstName</strong>;<br>    }<br><br>    <strong>public </strong>String getLastName() {<br>        <strong>return lastName</strong>;<br>    }<br><br>    <strong>public int </strong>getAge() {<br>        <strong>return age</strong>;<br>    }<br><br>    <strong>public </strong>String getAddress() {<br>        <strong>return address</strong>;<br>    }<br><br>    <strong>public </strong>String getCity() {<br>        <strong>return city</strong>;<br>    }<br><br>    <strong>public </strong>String getMobileNumber() {<br>        <strong>return mobileNumber</strong>;<br>    }<br><br>    <strong>public </strong>String getPincode() {<br>        <strong>return pincode</strong>;<br>    }<br><br>    @Override<br>    <strong>public </strong>String toString() {<br>        <strong>return &quot;Customer{&quot; </strong>+<br>                <strong>&quot;name=&#39;&quot; </strong>+ <strong>name </strong>+ <strong>&#39;\&#39;&#39; </strong>+<br>                <strong>&quot;, firstName=&#39;&quot; </strong>+ <strong>firstName </strong>+ <strong>&#39;\&#39;&#39; </strong>+<br>                <strong>&quot;, lastName=&#39;&quot; </strong>+ <strong>lastName </strong>+ <strong>&#39;\&#39;&#39; </strong>+<br>                <strong>&quot;, age=&quot; </strong>+ <strong>age </strong>+<br>                <strong>&quot;, address=&#39;&quot; </strong>+ <strong>address </strong>+ <strong>&#39;\&#39;&#39; </strong>+<br>                <strong>&quot;, city=&#39;&quot; </strong>+ <strong>city </strong>+ <strong>&#39;\&#39;&#39; </strong>+<br>                <strong>&quot;, mobileNumber=&#39;&quot; </strong>+ <strong>mobileNumber </strong>+ <strong>&#39;\&#39;&#39; </strong>+<br>                <strong>&quot;, pincode=&#39;&quot; </strong>+ <strong>pincode </strong>+ <strong>&#39;\&#39;&#39; </strong>+<br>                <strong>&#39;}&#39;</strong>;<br>    }<br><br>    <strong>private </strong>Customer(CustomerBuilder customerBuilder) {<br>        <strong>this</strong>.<strong>name </strong>= customerBuilder.<strong>name</strong>;<br>        <strong>this</strong>.<strong>firstName </strong>= customerBuilder.<strong>firstName</strong>;<br>        <strong>this</strong>.<strong>lastName </strong>= customerBuilder.<strong>lastName</strong>;<br>        <strong>this</strong>.<strong>pincode </strong>= customerBuilder.<strong>pincode</strong>;<br>        <strong>this</strong>.<strong>address </strong>= customerBuilder.<strong>address</strong>;<br>        <strong>this</strong>.<strong>mobileNumber </strong>= customerBuilder.<strong>mobileNumber</strong>;<br>        <strong>this</strong>.<strong>age </strong>= customerBuilder.<strong>age</strong>;<br>        <strong>this</strong>.<strong>city </strong>= customerBuilder.<strong>city</strong>;<br>    }<br><br>    <strong>public static class </strong>CustomerBuilder {<br>        <strong>private </strong>String <strong>name</strong>;<br>        <strong>private </strong>String <strong>firstName</strong>;<br>        <strong>private </strong>String <strong>lastName</strong>;<br>        <strong>private int age</strong>;<br>        <strong>private </strong>String <strong>address</strong>;<br>        <strong>private </strong>String <strong>city</strong>;<br>        <strong>private </strong>String <strong>mobileNumber</strong>;<br>        <strong>private </strong>String <strong>pincode</strong>;<br><br>        <strong>public </strong>CustomerBuilder() {<br>        }<br><br>        <strong>public </strong>CustomerBuilder setName(String name) {<br>            <strong>this</strong>.<strong>name </strong>= name;<br>            <strong>return this</strong>;<br>        }<br><br>        <strong>public </strong>CustomerBuilder setFirstName(String firstName) {<br>            <strong>this</strong>.<strong>firstName </strong>= firstName;<br>            <strong>return this</strong>;<br>        }<br><br>        <strong>public </strong>CustomerBuilder setLastName(String lastName) {<br>            <strong>this</strong>.<strong>lastName </strong>= lastName;<br>            <strong>return this</strong>;<br>        }<br><br>        <strong>public </strong>CustomerBuilder setAge(<strong>int </strong>age) {<br>            <strong>this</strong>.<strong>age </strong>= age;<br>            <strong>return this</strong>;<br>        }<br><br>        <strong>public </strong>CustomerBuilder setAddress(String address) {<br>            <strong>this</strong>.<strong>address </strong>= address;<br>            <strong>return this</strong>;<br>        }<br><br>        <strong>public </strong>CustomerBuilder setCity(String city) {<br>            <strong>this</strong>.<strong>city </strong>= city;<br>            <strong>return this</strong>;<br>        }<br><br>        <strong>public </strong>CustomerBuilder setMobileNumber(String mobileNumber) {<br>            <strong>this</strong>.<strong>mobileNumber </strong>= mobileNumber;<br>            <strong>return this</strong>;<br>        }<br><br>        <strong>public </strong>CustomerBuilder setPincode(String pincode) {<br>            <strong>this</strong>.<strong>pincode </strong>= pincode;<br>            <strong>return this</strong>;<br>        }<br><br>        <strong>public </strong>Customer build() {<br>            <strong>return new </strong>Customer(<strong>this</strong>);<br>        }<br>    }<br>}</pre><p>Things to note:</p><ol><li>There is a static inner class that can return the object.</li><li>The static class has the setters and has also had a build() method which would return the new Customer object.</li><li>The outer class only has getters which helps us to fetch the fields that are set.</li></ol><p><strong>Let&#39;s see how would we instantiate the Customer Object</strong></p><pre><strong>public class </strong>BuilderClassImplementation {<br>    <strong>public static void </strong>main(String[] args) {<br>        Customer customer = <strong>new </strong>Customer.CustomerBuilder()<br>                .setName(<strong>&quot;Omkar Kulkarni&quot;</strong>)<br>                .setFirstName(<strong>&quot;Omkar&quot;</strong>)<br>                .setLastName(<strong>&quot;Kulkarni&quot;</strong>)<br>                .setMobileNumber(<strong>&quot;8551223****&quot;</strong>)<br>                .build();<br>    }<br>}</pre><p><strong>Advantages :</strong></p><ol><li>Passing so many parameters to the constructor is eliminated.</li><li>We do not have to pass null inside the constructor.</li><li>Code is <strong><em>maintainable</em></strong>.</li><li>We can force <strong><em>immutability</em></strong> once the object is created.</li></ol><p><strong>Disadvantages :</strong></p><ol><li>Code has been duplicated inside the inner and the outer class.</li><li>The instance might get created without the parameters as well.</li></ol><p>There might be a case where we need to have some parameters mandatory but with the above implementation, the object might get created parameterless.</p><p>So in that case we need a bit of tweaking inside the builder class implementation. Instead of having an <a href="https://javarevisited.blogspot.com/2012/01/what-is-constructor-overloading-in-java.html">empty constructor</a>, we pass the mandatory fields that might be required for the object creation.</p><p>Here goes the constructor implementation.</p><pre><strong>public </strong>CustomerBuilder(String name, <strong>int </strong>age, String city) {<br>    <strong>this</strong>.<strong>name </strong>= name;<br>    <strong>this</strong>.<strong>age </strong>= age;<br>    <strong>this</strong>.<strong>city </strong>= city;<br>}</pre><p>And the object instantiation would also change because of this.</p><pre>Customer customer = <strong>new </strong>Customer<br>        .CustomerBuilder(<strong>&quot;Omkar&quot;</strong>, 29, <strong>&quot;Pune&quot;</strong>)<br>        .setMobileNumber(<strong>&quot;987*******&quot;</strong>)<br>        .build();</pre><h4><strong>Conclusion:</strong></h4><p>Builder Design Pattern a creational Design Pattern should be used for creating complex objects. The code becomes maintainable and less error-prone.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b93d2a15440" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/builder-design-pattern-in-java-for-beginners-9b93d2a15440">Builder Design Pattern in Java for Beginners</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Much Needed Getaway to Kokan, India]]></title>
            <link>https://omkar15525.medium.com/much-needed-getaway-to-kokan-india-fb0a8446de2?source=rss-908f3fe675b------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb0a8446de2</guid>
            <category><![CDATA[kokan]]></category>
            <category><![CDATA[india]]></category>
            <category><![CDATA[travel]]></category>
            <category><![CDATA[maharashtra]]></category>
            <category><![CDATA[trip]]></category>
            <dc:creator><![CDATA[Omkar Kulkarni]]></dc:creator>
            <pubDate>Fri, 01 Jan 2021 07:42:31 GMT</pubDate>
            <atom:updated>2021-01-02T04:50:27.121Z</atom:updated>
            <content:encoded><![CDATA[<p>Since March 2020 the whole world had come to a standstill. Businesses were affected, people had started getting affected with the Covid-19 virus. And the worst part was we all were locked up in our own houses. And work from started for the longest duration had started in every software professionals career.</p><p>After months of being harassed, tortured and mentally stressed me and my friend thought of having a trip (like we usually have every year). After lots of phone calls and frantic discussions we fixed the location as Kokan or to be more precise Ganpatipule, Guhaghar and Ratnagiri.</p><p>There is a folklore that Lord Parshuram hit an arrow and had created this pristine location on the coastal side of Maharashtra. Recently due to the findings as well, Kokan has become the hotspot for the archeologists. The rock carvings that have found in recent days has pointed out that there was a lost civilization residing in this location. We were basically drawn to Kokan just because of two main things:</p><ol><li>Beaches</li><li>Temples</li></ol><p>We had selected the long weekend of 25th December for our trip and hence we started our journey on 24th of December from Pune. And our first location was Ganpatipule. A.C Bus travel costs round about 1000 INR from Pune. You reach there by 8 or 9 A.M in the morning. The village of this Ganpatipule is basically known for the Ganpati Temple which is situated on the seashore.</p><p>It is said that this idol of Ganpati is self made and is being there since last 400 years. It also finds its mention in the Mudgal Purana. We got ready and visited the temple and then straight headed to the beach. Ganpatipule beach is one of the cleanest beaches of Maharashtra. Previously it was a calm and secluded beach, but due to its proximity from Pune and Mumbai many people are drawn to it. And where there is crowd there is business. The beachline is flocked with shops selling eateries, coconuts and other items that the children can get attracted to. Camel back rides, Tonga rides have also made it to Ganpatipule now.</p><p>Having water rides there was quite a surprise for us. We did try the scooter ride and the boat ride. It was a high tide when we visited and that added to more excitement for the rides. After chilling for some time and having lunch we retired to our hotel rooms and had a quick nap time.</p><p>In the evening we again visited the beach and had a nice view of sunset. The sound of waves crashing on the beach, the soft breeze and the setting sun transport you to all new world. Standing in shallow water and watching the sun fade away, nothing can replace this feeling. After the beach grew dark or rather the coast guards drove us away from the water we came back to the hotel, had dinner and ended our day.</p><p>There are few things to remember while you visit there. First and foremost you need a private vehicle if you want to visit the Kokan side of Maharashtra. Because public transport sucks. The roads too suck. If you are too much into making something dare devilish then try your luck for it. Secondly the hotels. Usually we tend to have our bookings done before we visit a place. But in Kokan there are very few places mentioned on the booking websites, and there are ample cheap options for stays there. So opt for the later part.</p><p>The next day started with 18 km rickshaw drive from Ganpatipule to Jaigad. And we were planning to have a jetty ride from Jaigad to Guhagar. We got to know that this would be a short cut to reach Guhagar, other wise we would have to reach back to Ratnagiri and then head back to Guhagar by MSRTC buses. That cost us 500 INR and the local Rickshaw and the tam tam costed 700 INR from Jaigad to Guhagar. This was actually a bad choice because once the Jetty reaches the shore of Jaigad you do not find a vehicle to get to Guhagar which is 21 km from Jaigad. We had to plead and bargain the tam tam (local vehicle) to take us to Guhagar.</p><p>In the mid transit we missed visiting Hedvi Ganpati and Velneshwar Mandir because we were unaware that we would be surpassing them in between the travel. Guhagar is a small town straight out of the 80s or the 90s era. You get a Malgudi days vibe there. The narrow lanes and the houses with front and back arenas, the betel nut and coconut trees in the backyard just make this town a Instagram worthy.</p><p>We checked in the hotel and after a quick bite straight headed to the beach. The beach bug in us never gets enough of the beach vibe. It was mid noon but still we enjoyed the time soaking in the sea waters. After like an hour or two we had the lunch and headed back to the Hotel rooms.</p><p>We returned back to the beach in the evening time and had the fullest share of watching the pale yellow, red sun setting in the sea. If you are in Kokan and do not purchase the local goodies then your trip is wasted. The Fanas Poli, The Amba Poli, Kokam juice, raw Kokams, Mango pulps every single thing makes its share in your bag and makes the wallet lighter by 1k or 2k. (But its totally worth it)</p><p>Third day we headed to Chiplun as we got to know that the frequency of the buses to Ratnagiri is higher from there. But as I said public transport sucks, the wait for the public transport made us loose our 3 hours. And we reached Ratnagiri by 5 P.M. Exhausted and drained we headed to the Mandavi Beach. Not so clean and adorable like the other beaches but this is also one the calmest beach. Not to forget this is one of the crowdest beach.</p><p>Nonetheless the sunset made us forget the soul sucking wait and the bus ride trauma from Chiplun to Ratnagiri. And we returned to Pune by the bus on 28th morning.</p><p>This way our yearly trip got to an end with recharged mind and lessons learnt.</p><p>Every trip teaches us somethings, you have to gather the experiences and learn from the mistakes you have committed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e9aW9Cs6uDkC-J4LSwrHKw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h3ZGBsPMi57rZdHLiaQGmw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-nUsWNnOHG8rbiZVtJrJjg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-EsbNHxPfNRekV9wTeQAvA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B0X3d2jmuToEO1kRK39oUw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PzFDEi_EPetDmQAtueumFA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B0X3d2jmuToEO1kRK39oUw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb0a8446de2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>