<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: vikneswaran</title>
    <description>The latest articles on DEV Community by vikneswaran (@vikneswaran).</description>
    <link>https://dev.to/vikneswaran</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F231653%2F7b0701ff-8c70-44b1-a867-0a9caaeb6565.jpeg</url>
      <title>DEV Community: vikneswaran</title>
      <link>https://dev.to/vikneswaran</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vikneswaran"/>
    <language>en</language>
    <item>
      <title>5 eLearning Platforms, You Should Never Miss Out</title>
      <dc:creator>vikneswaran</dc:creator>
      <pubDate>Sun, 27 Oct 2019 16:57:03 +0000</pubDate>
      <link>https://dev.to/vikneswaran/5-elearning-platforms-you-should-never-miss-out-434j</link>
      <guid>https://dev.to/vikneswaran/5-elearning-platforms-you-should-never-miss-out-434j</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Formal education will make you a living; self-education will make you a fortune — Jim Rohn&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;E-Learning platforms are influencing the current day’s education scenarios. But the plenty of available eLearning resources made it difficult to choose one. Let me walk through some of the best eLearning platforms I come across all over these days.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1.Udemy&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fc77p8ugd0566605qa35g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fc77p8ugd0566605qa35g.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Whenever I need to learn something new, the first thing that comes to my mind is Udemy. It covers a wide variety of courses from instructors all around the world. Udemy provides both paid and free courses. You can see lots of discounts for most of the paid courses lets you spend a few bucks for your favorite courses.&lt;/p&gt;

&lt;p&gt;The best part is you can take the courses at your own pace. Discussion forums and private chat with instructors make it interactive and engaging. Upon successful completion, you will get your course completion certificate from Udemy. If you are well enough to create your own course, then take a chance from Udemy letting you create and publish it.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://www.udemy.com" rel="noopener noreferrer"&gt;Udemy&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2.Udacity&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Foh6qn1dbhf1zm5pn0gst.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Foh6qn1dbhf1zm5pn0gst.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Udacity provides one of the finest eLearning solutions. Its main focus towards the particular target group related to technology. Top companies and universities created the courses at higher standard and industry oriented. All the courses are free except nano degrees.&lt;/p&gt;

&lt;p&gt;Nano degrees are awesome, which ends up landing you in a better job. The course contents are well organized with clear instructions and real-world hands-on. You can take these courses at your own pace. With an interactive forum, you can engage with your colleagues and instructor(s).&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://www.udacity.com" rel="noopener noreferrer"&gt;Udacity&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;3.edX&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fnkmynvjrp4rcjuebbuhl.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fnkmynvjrp4rcjuebbuhl.jpeg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
edX is the huge eLearning platform comprises of lots of courses from the world’s top university at the free of cost. It covers both academic and industry-oriented courses. Instructors have sound knowledge of the subject. Most of the instructors are professors from the top universities.&lt;/p&gt;

&lt;p&gt;Some of the courses are self-paced and some of them are only available in a particular time frame. The only thing you need to pay for the optional verified certificate. The course contents are nicely framed for easy understanding.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://www.edx.org" rel="noopener noreferrer"&gt;edX&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;4.Coursera&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcdpjo19kaxpsbw99shzt.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcdpjo19kaxpsbw99shzt.jpeg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Coursera is a collection of eLearning courses from a wide range of concepts. Usually, it contains a series of courses on a particular topic. Coursera is for serious learners who stick to a course timetable. Professors and industry experts are most of the trainers. You will have restricted access to courses unless you pay for it.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://www.coursera.org" rel="noopener noreferrer"&gt;Coursera&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;5.Khan Academy&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fjpnyhmrztfgezwll5uh9.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fjpnyhmrztfgezwll5uh9.jpeg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Khan academy is an online educational organization, where you can learn almost everything. The motive is to educate the students online from all grades at free of cost. They prepare their own short videos and exercises for every course. The course contents are more understandable and self-paced.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://www.khanacademy.org" rel="noopener noreferrer"&gt;Khan Academy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Online medium makes education with endless possibilities — let anyone can learn anything out of the box.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Also, leave comments about your best eLearning platforms and their experience.&lt;/p&gt;

</description>
      <category>selflearn</category>
      <category>education</category>
      <category>beginners</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Boost Your Personal Computing Experience With Linux</title>
      <dc:creator>vikneswaran</dc:creator>
      <pubDate>Sat, 21 Sep 2019 08:31:14 +0000</pubDate>
      <link>https://dev.to/vikneswaran/boost-your-personal-computing-experience-with-linux-1ke4</link>
      <guid>https://dev.to/vikneswaran/boost-your-personal-computing-experience-with-linux-1ke4</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1280%2F1%2AhxIrOHuVp27f0p-kp0WJXg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1280%2F1%2AhxIrOHuVp27f0p-kp0WJXg.png" alt="Linux"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When comes to personal computing most of us will prefer Microsoft Windows. Microsoft Windows is ruling the world of personal computing as it holds more than 90% of the market share. Although we don’t know why we are using Windows, we rather think of it using for personal computing. Since most of the Laptops are shipped with windows or our colleagues and friends will be using it. We need to revisit our personal computing habits.&lt;/p&gt;

&lt;p&gt;Well, Windows is equipped with lots of functionalities and an amazing user experience and frequent updates. I must admit it. But every Operating System has its own pros and cons. Also, we have an alternative operating system to watch out.&lt;/p&gt;

&lt;h1&gt;
  
  
  Linux Operating System
&lt;/h1&gt;

&lt;p&gt;Linux is an open-source operating system which available at free of cost. It is lightweight when compared to Windows. You don't need to spend an additional penny on some anti-virus program to safeguard your PC, you just need to depend on some security updates to stay safe. But working with Linux OS needs some learning curve. If you are getting familiar with it, you can sense your productivity increase.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1280%2F1%2AgV7MvD5-Eo4ackzsgNFkHg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1280%2F1%2AgV7MvD5-Eo4ackzsgNFkHg.png" alt="Linux"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Which Linux?
&lt;/h1&gt;

&lt;p&gt;Next, the one big question, which Linux distros should I choose? Well, it depends. Based on your needs it will vary. Ubuntu is one of the most popular Linux distro for personal computing as of now. But there are other distros also you could use Fedora, CentOS, OpenSUSE. If you’re serious windows users, you can prefer ChaletOS or Linux Mint. I have also found this interesting site that can suggest you a Linux distro based on your preferences — &lt;a href="https://distrochooser.de/en" rel="noopener noreferrer"&gt;Distro Chooser&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Linux Alternatives to Windows Apps
&lt;/h1&gt;

&lt;p&gt;Let’s think about productivity, we rely on some applications on a daily basis. Does that achievable with Linux? Why not, even you can improve your productivity. Let me walk through it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Office Suite
&lt;/h2&gt;

&lt;p&gt;Any sort of computer-based work is incomplete without an Office Suite. &lt;a href="https://www.libreoffice.org" rel="noopener noreferrer"&gt;LibreOffice&lt;/a&gt; is an alternative to Microsoft Office. It is compatible with almost all MS Office files formats. Available for free of cost.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/3KC0ZdcA6s8"&gt;
&lt;/iframe&gt;
&lt;br&gt;
Other Software like WPS Office, Apache Open Office, AbiWord is some of its alternatives.&lt;/p&gt;

&lt;h2&gt;
  
  
  Email Client
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1024%2F1%2A3QwieP3Q5Uuz_LT8t6xrhw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1024%2F1%2A3QwieP3Q5Uuz_LT8t6xrhw.jpeg" alt="Thunderbird"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.thunderbird.net/en-US/" rel="noopener noreferrer"&gt;Mozilla Thunderbird&lt;/a&gt; is an email client alternative to Microsoft Outlook or Windows Mail. It has stunning features to manage your emails.&lt;/p&gt;

&lt;h2&gt;
  
  
  Graphics and Image Processing
&lt;/h2&gt;

&lt;p&gt;We have some alternatives to Adobe products for graphics.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.gimp.org/" rel="noopener noreferrer"&gt;GIMP&lt;/a&gt; is a fully-featured image processing software alternative to Adobe Photoshop.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://inkscape.org/" rel="noopener noreferrer"&gt;Inkscape&lt;/a&gt; is a professional vector graphics editor alternative to Adobe Illustrator.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.tuxpaint.org/" rel="noopener noreferrer"&gt;Tux Paint&lt;/a&gt; and &lt;a href="http://kolourpaint.sourceforge.net/" rel="noopener noreferrer"&gt;Kolor Paint&lt;/a&gt; are alternatives to MS Paint.&lt;/p&gt;

&lt;h2&gt;
  
  
  Media Players and editors
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://www.videolan.org/vlc/" rel="noopener noreferrer"&gt;VLC media player&lt;/a&gt; is the popular option for a media player.&lt;/p&gt;

&lt;p&gt;If you are looking for a video editing tool, then &lt;a href="https://www.openshot.org/" rel="noopener noreferrer"&gt;OpenShot&lt;/a&gt; is a video editing tool will be an alternative to Windows Movie Maker. For editing audio, you can pick &lt;a href="https://www.audacityteam.org/" rel="noopener noreferrer"&gt;Audacity&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Text Editors and IDE
&lt;/h2&gt;

&lt;p&gt;If you are a developer you will definitely rely on Text Editors and IDE.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://notepadqq.com/s/" rel="noopener noreferrer"&gt;Notepadqq&lt;/a&gt; is an alternative to Notepad++. All Other popular text editors like Sublime, VSCode, Atom, Brackets are also available in Linux Platform. You can also try some of the best Linux based editor like VIM, Nano, Gedit.&lt;/p&gt;

&lt;p&gt;As far as IDE is concerned, all major IDE is available for Linux. You have Linux support for IntelliJ, Pycharm, Netbeans, Eclipse, Android Studio, RStudio.&lt;/p&gt;

&lt;h2&gt;
  
  
  Browsers
&lt;/h2&gt;

&lt;p&gt;Almost all modern web browsers will be available in Linux. Mozilla Firefox, Google Chrome, Opera.&lt;/p&gt;

&lt;h2&gt;
  
  
  Readers
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://okular.kde.org/" rel="noopener noreferrer"&gt;Okular&lt;/a&gt;, &lt;a href="https://wiki.gnome.org/action/show/Apps/Evince" rel="noopener noreferrer"&gt;Evience&lt;/a&gt; are some of the popular picks. Adobe Reader is also available for Linux platform.&lt;/p&gt;

&lt;p&gt;I have suggested some of the famous alternatives. If you are looking for a specific alternative, I recommend you to have a look into this &lt;a href="https://alternativeto.net" rel="noopener noreferrer"&gt;site&lt;/a&gt;. It has crowdsourced alternative software recommendations.&lt;/p&gt;

&lt;p&gt;Opensource technologies are evolving at a rapid rate in today's world. Also, Linux is gaining more and more community support to keep you updated and safe. Keep an eye over it, It will save lots of money and improves your productivity.&lt;/p&gt;

</description>
      <category>linux</category>
    </item>
    <item>
      <title>Mitigate Null Pointer Exceptions in Java with Optional class</title>
      <dc:creator>vikneswaran</dc:creator>
      <pubDate>Fri, 20 Sep 2019 06:16:26 +0000</pubDate>
      <link>https://dev.to/vikneswaran/mitigate-null-pointer-exceptions-in-java-with-optional-class-52od</link>
      <guid>https://dev.to/vikneswaran/mitigate-null-pointer-exceptions-in-java-with-optional-class-52od</guid>
      <description>&lt;p&gt;Null pointer exceptions are quite annoying as every java developer should have faced at least once. As the code grows, handling these null pointer exceptions will become tedious with numerous null checks. &lt;/p&gt;

&lt;p&gt;Optional class has been introduced in java 8 to provide a type-level solution for representing optional values instead of using null references. Before java 8 Optional class is the part of google's Guava library.&lt;/p&gt;

&lt;p&gt;Let's look into some of the implementations with &lt;em&gt;java.util.Optional&lt;/em&gt; class&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating an empty Object
&lt;/h2&gt;

&lt;p&gt;Empty Optional object can be created by calling &lt;em&gt;empty&lt;/em&gt; static method of Optional class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Test&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;createEmptyOptional&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;empty&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;empty&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;assertFalse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;empty&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isPresent&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;&lt;span class="c1"&gt;//Also we can use the opposite one empty.isEmpty() from java 10&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;isPresent()&lt;/em&gt; will return true only if the object in Optional is not null;&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating Optional class with objects
&lt;/h2&gt;

&lt;p&gt;Optional class can be created with &lt;em&gt;Optional.of()&lt;/em&gt; or &lt;em&gt;Optional.ofNullable()&lt;/em&gt; static methods&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Test&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;createOptionalObject&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Optional"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;opt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ofNullable&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;assertTrue&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;opt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isPresent&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;

    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;title2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;opt1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ofNullable&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;title2&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;assertFalse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;opt1&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isPresent&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Optional.of(title)&lt;/em&gt; will throw NullPointerException if the title was null.&lt;/p&gt;

&lt;h2&gt;
  
  
  Remove null checks while accessing objects with Optional.ifPresent()
&lt;/h2&gt;

&lt;p&gt;It will enable us to run some code on the wrapped value if the Object wrapped in the Optional is found to be not null.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;checkOptionalIfPresent&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Color&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ColorFactoryProvider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getColor&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"red"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Color&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;red&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ofNullable&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;red&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ifPresent&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getColorCode&lt;/span&gt;&lt;span class="o"&gt;()));&lt;/span&gt;&lt;span class="c1"&gt;//wrapped code will get executed&lt;/span&gt;

    &lt;span class="nc"&gt;Color&lt;/span&gt; &lt;span class="n"&gt;empty&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Color&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;emptyColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ofNullable&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;empty&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;emptyColor&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ifPresent&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getColorCode&lt;/span&gt;&lt;span class="o"&gt;()));&lt;/span&gt;&lt;span class="c1"&gt;// wrapped code will not get executed&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Can you see how the Optional class will allow us to get rid of the null checks so that the wrapped code will not get executed if the object is null?&lt;/p&gt;

&lt;h2&gt;
  
  
  Accessing the Objects from Optional class
&lt;/h2&gt;

&lt;p&gt;There are various methods which also comes with Optional class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* 
Optional.get() 
It returns the wrapped object.
it throws a no such element exception if the wrapped object is null.
*/&lt;/span&gt;
&lt;span class="nd"&gt;@Test&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;getValue&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
  &lt;span class="nc"&gt;Color&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ColorFactoryProvider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getColor&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"blue"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Color&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;optionalColor&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ofNullable&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="n"&gt;assertEquals&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;optionalColor&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/*
Optional.orElse()
It is like assigning default value for the object. 
if the wrapped object is null then default value will be returned.
*/&lt;/span&gt;
&lt;span class="nd"&gt;@Test&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;OptionalorElseCheck&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
  &lt;span class="nc"&gt;Color&lt;/span&gt; &lt;span class="n"&gt;defaultColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ColorFactoryProvider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getColor&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"red"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="nc"&gt;Color&lt;/span&gt; &lt;span class="n"&gt;blue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ColorFactoryProvider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getColor&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"blue"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Color&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;optionalColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ofNullable&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blue&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="n"&gt;assertEquals&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blue&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;optionalColor&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;orElse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;defaultColor&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;

  &lt;span class="nc"&gt;Color&lt;/span&gt; &lt;span class="n"&gt;empty&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Color&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;emptyColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ofNullable&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;empty&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="n"&gt;assertEquals&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;defaultColor&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;emptyColor&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;orElse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;defaultColor&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Also we have some other useful methods&lt;br&gt;
&lt;em&gt;Optional.orElseGet()&lt;/em&gt; - which is similar to &lt;em&gt;orElse()&lt;/em&gt; the only difference is it takes a supplier functional interface as input and invokes only if the wrapper object in Optional is null.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Optional.orElseThrow()&lt;/em&gt; - which is similar to &lt;em&gt;orElse()&lt;/em&gt; the only difference is it take Exception Object as input and it will throw given exception if the wrapped object in Optional is null.&lt;/p&gt;

&lt;p&gt;So start refactoring your code with Optional class which provides the best practices for handling null in java.&lt;/p&gt;

&lt;p&gt;For more detailed reference check the official &lt;a href="https://www.oracle.com/technetwork/articles/java/java8-optional-2175753.html"&gt;documentation&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>codequality</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
