<?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: Victor Macarios</title>
    <description>The latest articles on DEV Community by Victor Macarios (@vmacarios).</description>
    <link>https://dev.to/vmacarios</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%2F210640%2Fa5e60e85-bc16-4cea-b744-a59a161ccbd6.png</url>
      <title>DEV Community: Victor Macarios</title>
      <link>https://dev.to/vmacarios</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vmacarios"/>
    <language>en</language>
    <item>
      <title>Tips for configuring GitHub in IntelliJ</title>
      <dc:creator>Victor Macarios</dc:creator>
      <pubDate>Mon, 06 Apr 2020 21:12:51 +0000</pubDate>
      <link>https://dev.to/vmacarios/tips-for-configuring-github-in-intellij-4ggc</link>
      <guid>https://dev.to/vmacarios/tips-for-configuring-github-in-intellij-4ggc</guid>
      <description>&lt;p&gt;&lt;em&gt;The steps described in this post were done using IntelliJ IDEA CE 2019.3 and macOS High Sierra (10.13.6).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When setting up GitHub in IntelliJ we have to follow some tricky steps.&lt;br&gt;
I'll show the ones that I have passed by.&lt;/p&gt;

&lt;p&gt;The first step is to configure the GitHub account.&lt;br&gt;
To do that, just click in &lt;strong&gt;Configure&lt;/strong&gt; link on IntelliJ Welcome Screen and then in &lt;strong&gt;Preferences&lt;/strong&gt; option.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gDjPYFZK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/k2t3b7yie0sxqfsmnck3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gDjPYFZK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/k2t3b7yie0sxqfsmnck3.png" alt="IntelliJ Welcome Screen"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open &lt;strong&gt;Version Control&lt;/strong&gt; section and then &lt;strong&gt;GitHub&lt;/strong&gt;.&lt;br&gt;
Click in the &lt;strong&gt;+&lt;/strong&gt; button and add the credentials.&lt;br&gt;
If you want to use SSH (by the way, that is recommended for security reasons), you should tick &lt;em&gt;"Clone git repositories using ssh"&lt;/em&gt; and click &lt;strong&gt;OK&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HC3UbxYZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/f7ovlzlqv4z22i6ddq6n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HC3UbxYZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/f7ovlzlqv4z22i6ddq6n.png" alt="Verson Control Settings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But... &lt;/p&gt;

&lt;p&gt;(Here comes the first trick)&lt;br&gt;
If you don't have added the SSH key for your computer on the GitHub website, you'll not be able to use this option.&lt;/p&gt;

&lt;p&gt;Let's see how to add it then:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the Terminal app&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enter the following line:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-keygen -t rsa
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Press &lt;strong&gt;ENTER&lt;/strong&gt; key to accept the default location to save the files&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a password for your keys (you'll need to type it twice)&lt;br&gt;&lt;br&gt;
Your keys are now saved in &lt;em&gt;.ssh&lt;/em&gt; folder inside your home folder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;To copy it, use the command below:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pbcopy &amp;lt; ~/.ssh/id_rsa.pub
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now, access the &lt;a href="https://www.github.com"&gt;GitHub&lt;/a&gt; website, click in your avatar picture (top-right) and then &lt;strong&gt;Settings&lt;/strong&gt; option.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click in &lt;strong&gt;SSH and GPG key&lt;/strong&gt; then in the green button named &lt;strong&gt;New SSH key&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type a name that identifies your computer, pastes the key and finish by clicking in the &lt;strong&gt;Add SSH key&lt;/strong&gt; button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Your GitHub password will be requested.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--X3aGY8sq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zqp25zxbxbw37xrrswq6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X3aGY8sq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zqp25zxbxbw37xrrswq6.png" alt="GitHub SSH Settings"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With the SSH key added to the GitHub website, you can now clone a repository by using the &lt;strong&gt;Get from Version Control&lt;/strong&gt; option in Welcome to IntelliJ IDEA screen.&lt;/p&gt;

&lt;p&gt;Now that your repository was copied locally, you can commit using &lt;em&gt;VCS&amp;gt;Commit&lt;/em&gt; (⌘ + K) option on the menu and push by using &lt;em&gt;VCS&amp;gt;Git&amp;gt;Push&lt;/em&gt; (⌘ + ⇧ + K).&lt;/p&gt;

&lt;p&gt;And here comes another trick.&lt;br&gt;
For security reasons, GitHub has two options in &lt;strong&gt;Email settings&lt;/strong&gt; that helps protect your privacy (&lt;em&gt;Keep my email addresses private&lt;/em&gt; and &lt;em&gt;Block command line pushes that expose my email&lt;/em&gt;).&lt;br&gt;
If those options are ticked, maybe you receive an error when you try to push your commits.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YUc55ct9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/baej9c8y0g67awgf6zqd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YUc55ct9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/baej9c8y0g67awgf6zqd.png" alt="GitHub Email Settings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Unfortunately, the error notification doesn't always have enough information.&lt;br&gt;
Using the menu &lt;em&gt;View&amp;gt;Tool Windows&amp;gt;Version Control&lt;/em&gt; (⌘ + 9), you can see more detailed information at the Log tab.&lt;br&gt;
You should probably see the below message:&lt;br&gt;
&lt;code&gt;Your push would publish a private email address.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So, how can I push my commits while keeping my privacy?&lt;/strong&gt;&lt;br&gt;
GitHub provides us an email to avoid exposes our private email.&lt;/p&gt;

&lt;p&gt;Let's see the steps to get it and solve the issue:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Access your GitHub &lt;em&gt;Settings&amp;gt;E-mail&lt;/em&gt; and you will see the provided email at the first line of the &lt;em&gt;Keep my email addresses private&lt;/em&gt; section
(highlighted in the image above)&lt;/li&gt;
&lt;li&gt;Copy it to the clipboard&lt;/li&gt;
&lt;li&gt;Open the Terminal app&lt;/li&gt;
&lt;li&gt;Navigate to your local repository directory&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Type the text below (replacing the content between the quotation marks with your email copied in step 2):&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --global user.email "{ID}+{username}@users.noreply.github.com"
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Reset the author information:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit --amend --reset-author
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return to IntelliJ and now you can push by pressing ⌘ + ⇧ + K&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Congratulations. &lt;br&gt;
Now you've finished the IntelliJ/GitHub setup and can start to code.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;br&gt;
Victor Macarios&lt;/p&gt;

&lt;p&gt;Sources: &lt;br&gt;
&lt;a href="https://help.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh"&gt;https://help.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/43863522/your-push-would-publish-a-private-email-address-error/51097104#51097104"&gt;https://stackoverflow.com/questions/43863522/your-push-would-publish-a-private-email-address-error/51097104#51097104&lt;/a&gt;&lt;/p&gt;

</description>
      <category>github</category>
      <category>intellij</category>
      <category>setup</category>
      <category>tips</category>
    </item>
    <item>
      <title>Traversing Graphs</title>
      <dc:creator>Victor Macarios</dc:creator>
      <pubDate>Sat, 25 Jan 2020 22:22:43 +0000</pubDate>
      <link>https://dev.to/vmacarios/traversing-graphs-4ie1</link>
      <guid>https://dev.to/vmacarios/traversing-graphs-4ie1</guid>
      <description>&lt;p&gt;As developers, we are frequently dealing with lists, arrays, and sequence of values. But have you ever had to deal with related data, which are connected to other data? This is also known as a &lt;strong&gt;Graph&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;These days I had to deal with it. It was scary at first.&lt;br&gt;
But after reading this &lt;a href="https://www.baeldung.com/java-graphs"&gt;great article&lt;/a&gt; from &lt;a href="https://www.baeldung.com/author/kumar-chandrakant/"&gt;Kumar Chandrakant&lt;/a&gt;, it became understandable and I felt capable of doing that.&lt;/p&gt;

&lt;p&gt;Of course, there's a lot to learn yet, but I'm gonna show you the basics, so you have a start point to deepen your research. &lt;/p&gt;

&lt;p&gt;A graph is a collection of &lt;strong&gt;Vertices&lt;/strong&gt; (also called Nodes or Points) and &lt;strong&gt;Edges&lt;/strong&gt; (also called Links or Lines), where an edge is the connections between two vertices.&lt;br&gt;
In a social network, each person is a vertex, and each connection between them is the edge.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RaRBULUH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.baeldung.com/wp-content/uploads/2018/11/graph1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RaRBULUH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.baeldung.com/wp-content/uploads/2018/11/graph1.jpg" alt="Kumar's diagram"&gt;&lt;/a&gt;&lt;/p&gt;
Kumar's diagram



&lt;p&gt;In a map, the streets are the edges and their intersections are the vertices.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s_SC9x5Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/o2c3poh0ox7alolmxf4r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s_SC9x5Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/o2c3poh0ox7alolmxf4r.png" alt="Route on map"&gt;&lt;/a&gt;M&amp;amp;M's time!😋&lt;/p&gt;

&lt;p&gt;Using &lt;strong&gt;Kumar's diagram&lt;/strong&gt; as an example, let's code.&lt;br&gt;
The first step is to create a &lt;strong&gt;Vertex&lt;/strong&gt; class:&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Vertex&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;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Vertex&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;name&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="nf"&gt;equals&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;o&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="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;((&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;Vertex&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;(((&lt;/span&gt;&lt;span class="nc"&gt;Vertex&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;hashCode&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;hashCode&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&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;Basically, the vertex has only the &lt;em&gt;"name"&lt;/em&gt; property. &lt;br&gt;
But, since we will work with Java Collections, we have to override the &lt;em&gt;equals&lt;/em&gt;, &lt;em&gt;hashCode&lt;/em&gt;, and &lt;em&gt;toString&lt;/em&gt; methods.&lt;/p&gt;

&lt;p&gt;Now, it's time for &lt;strong&gt;Graph&lt;/strong&gt; class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.ArrayList&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.HashMap&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.List&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.Map&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Graph&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Vertex&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Vertex&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;adjVertices&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Graph&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;adjVertices&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Vertex&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Vertex&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;addVertex&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;name&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;adjVertices&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;putIfAbsent&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Vertex&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ArrayList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;());&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;addEdge&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;name1&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;name2&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Vertex&lt;/span&gt; &lt;span class="n"&gt;v1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Vertex&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="nc"&gt;Vertex&lt;/span&gt; &lt;span class="n"&gt;v2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Vertex&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name2&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;adjVertices&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="n"&gt;v1&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v2&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;adjVertices&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="n"&gt;v2&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Vertex&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getAdjVertices&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;name&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;adjVertices&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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Vertex&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&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="nf"&gt;printGraph&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;StringBuffer&lt;/span&gt; &lt;span class="n"&gt;sb&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StringBuffer&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Vertex&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;adjVertices&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;keySet&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;sb&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;append&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;sb&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;append&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;adjVertices&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="n"&gt;v&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
            &lt;span class="n"&gt;sb&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;append&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"\n"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;sb&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;();&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;We are using a &lt;em&gt;Map&lt;/em&gt; to create an &lt;strong&gt;adjacency list&lt;/strong&gt;. This list will contain all relationship of each vertex.&lt;br&gt;
When adding an edge, we add a vertex on the list of the related vertex.&lt;br&gt;
To represent the graph, we print the adjacency list, creating a string that starts with each vertex and shows the related list in front of it.&lt;/p&gt;

&lt;p&gt;Then we will create a &lt;strong&gt;Travessal&lt;/strong&gt; class, which will contain the methods for traversing our graph. Both methods will receive a &lt;em&gt;graph&lt;/em&gt; and a &lt;em&gt;root&lt;/em&gt; (which will be our start point) as parameters.&lt;br&gt;
There are several ways for traversing a graph, but in this article, we will only show the two most commonly used. They are known as &lt;strong&gt;Depth-First Traversal (DFT)&lt;/strong&gt; and &lt;strong&gt;Breadth-First Traversal (BFT)&lt;/strong&gt;.&lt;br&gt;
The main difference between them is that the &lt;strong&gt;DFT&lt;/strong&gt; visits each &lt;em&gt;child&lt;/em&gt; connection until the end before start visiting the &lt;em&gt;siblings&lt;/em&gt;.&lt;br&gt;
The &lt;strong&gt;BFT&lt;/strong&gt;, on the other hand, visits each &lt;em&gt;sibling&lt;/em&gt; first before visiting their &lt;em&gt;children&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.LinkedHashSet&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.LinkedList&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.Queue&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.Set&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.Stack&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Traversal&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Set&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="nf"&gt;depthFirstTraversal&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Graph&lt;/span&gt; &lt;span class="n"&gt;graph&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;root&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Set&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;visited&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;LinkedHashSet&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="nc"&gt;Stack&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;stack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Stack&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;stack&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="o"&gt;(!&lt;/span&gt;&lt;span class="n"&gt;stack&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isEmpty&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;vertex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;stack&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;pop&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(!&lt;/span&gt;&lt;span class="n"&gt;visited&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;contains&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vertex&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;visited&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vertex&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
                &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Vertex&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getAdjVertices&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vertex&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;stack&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
                &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;visited&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Set&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="nf"&gt;breadthFirstTraversal&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Graph&lt;/span&gt; &lt;span class="n"&gt;graph&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;root&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Set&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;visited&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;LinkedHashSet&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="nc"&gt;Queue&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;queue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;LinkedList&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;queue&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;visited&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;(!&lt;/span&gt;&lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isEmpty&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;vertex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;poll&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Vertex&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getAdjVertices&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vertex&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(!&lt;/span&gt;&lt;span class="n"&gt;visited&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;contains&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;visited&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
                    &lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
                &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;visited&lt;/span&gt;&lt;span class="o"&gt;;&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;Note that to &lt;strong&gt;DFT&lt;/strong&gt; we use a &lt;em&gt;Stack&lt;/em&gt; to store the vertices which will be traversed, which takes us to go deeper in each vertice.&lt;br&gt;
In the &lt;strong&gt;BFT&lt;/strong&gt;, we use a &lt;em&gt;Queue&lt;/em&gt; to store the vertices, which bring us the neighbors first.&lt;/p&gt;

&lt;p&gt;To finish, we create a graph in the main method, defining its vertices and edges and then print the adjacency list and traverse it using both kinds of traversal.&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TraverseGraph&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="nc"&gt;Graph&lt;/span&gt; &lt;span class="n"&gt;graph&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Graph&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addVertex&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Bob"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addVertex&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Alice"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addVertex&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Mark"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addVertex&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Rob"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addVertex&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Maria"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addEdge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Bob"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Alice"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addEdge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Bob"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Rob"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addEdge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Alice"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Mark"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addEdge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Rob"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Mark"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addEdge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Alice"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Maria"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addEdge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Rob"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Maria"&lt;/span&gt;&lt;span class="o"&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;graph&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;printGraph&lt;/span&gt;&lt;span class="o"&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="nc"&gt;Traversal&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;depthFirstTraversal&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Bob"&lt;/span&gt;&lt;span class="o"&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="nc"&gt;Traversal&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;breadthFirstTraversal&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Bob"&lt;/span&gt;&lt;span class="o"&gt;));&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;The result will be the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Bob[Alice, Rob]
Rob[Bob, Mark, Maria]
Mark[Alice, Rob]
Alice[Bob, Mark, Maria]
Maria[Alice, Rob]

[Bob, Rob, Maria, Alice, Mark]
[Bob, Alice, Rob, Mark, Maria]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I hope this article clarifies the usage of &lt;strong&gt;Graphs&lt;/strong&gt;.&lt;br&gt;
Leave your impressions or doubts.&lt;/p&gt;

&lt;p&gt;Sources:&lt;br&gt;
[1]&lt;a href="https://www.baeldung.com/java-graphs"&gt;https://www.baeldung.com/java-graphs&lt;/a&gt;&lt;br&gt;
[2]&lt;a href="https://dev.to/amberjones/intro-to-graph-data-structures-abk"&gt;https://dev.to/amberjones/intro-to-graph-data-structures-abk&lt;/a&gt;&lt;br&gt;
[3]&lt;a href="https://dev.to/vaidehijoshi/going-broad-in-a-graph-bfs-traversal"&gt;https://dev.to/vaidehijoshi/going-broad-in-a-graph-bfs-traversal&lt;/a&gt;&lt;br&gt;
[4]&lt;a href="https://dev.to/jjb/part-9-learning-graphs-4859"&gt;https://dev.to/jjb/part-9-learning-graphs-4859&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>beginners</category>
      <category>algorithms</category>
      <category>datastructures</category>
    </item>
    <item>
      <title>Configuring GitHub in IntelliJ IDEA CE</title>
      <dc:creator>Victor Macarios</dc:creator>
      <pubDate>Sat, 25 Jan 2020 02:08:07 +0000</pubDate>
      <link>https://dev.to/vmacarios/configuring-github-in-intellij-idea-ce-52ih</link>
      <guid>https://dev.to/vmacarios/configuring-github-in-intellij-idea-ce-52ih</guid>
      <description>&lt;p&gt;Hey folks!&lt;/p&gt;

&lt;p&gt;Today I gonna show you how to configure GitHub on IntelliJ IDEA CE.&lt;/p&gt;

&lt;p&gt;It's quite simple.&lt;/p&gt;

&lt;p&gt;The first step is to open IntelliJ and, on the Welcome screen, click on "Configure", at the bottom right.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FIy2enVl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/42oedybm4uqt78fjl5mf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FIy2enVl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/42oedybm4uqt78fjl5mf.png" alt="IntelliJ Welcome Screen"&gt;&lt;/a&gt;IntelliJ Welcome Screen&lt;/p&gt;

&lt;p&gt;Choose the option "Preferences"&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---dSsSWSd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ogsj6e2v6ettmwr8jwzd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---dSsSWSd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ogsj6e2v6ettmwr8jwzd.png" alt="Preferences option"&gt;&lt;/a&gt;Preferences option&lt;/p&gt;

&lt;p&gt;Open the Version Control section by clicking on the triangle at its left&lt;br&gt;
Click on "GitHub"&lt;br&gt;
Click on "Add account" at the center of the window&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I1sRFR7C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/zvm6hzg8lhfuajjotd8z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I1sRFR7C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/zvm6hzg8lhfuajjotd8z.png" alt="Preferences window"&gt;&lt;/a&gt;Preferences window&lt;/p&gt;

&lt;p&gt;Insert your credentials and click on "Log In" button&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BWcqeazA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1x0lh6r8hi10blar7qux.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BWcqeazA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1x0lh6r8hi10blar7qux.png" alt="Credentials"&gt;&lt;/a&gt;Credentials&lt;/p&gt;

&lt;p&gt;If you have the two-factor authentication activated, a window will open asking your authentication code. Insert it and click in OK.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yN4e-Xgd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ydpzs6xedm3lvu94dmkg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yN4e-Xgd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ydpzs6xedm3lvu94dmkg.png" alt="Authentication code"&gt;&lt;/a&gt;Authentication code&lt;/p&gt;

&lt;p&gt;Now, just click OK to close the Preferences window.&lt;/p&gt;

&lt;p&gt;Now your GitHub account is configured.&lt;br&gt;
If you want to download a hosted code, click on "Get from Version Control" in the Welcome screen and select your repository by clicking at GitHub on the left side of the window.&lt;/p&gt;

&lt;p&gt;But, if you want to upload a project, open it, click in VCS menu and choose Import into Version Control &amp;gt; Share Project on GitHub&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_DIYwA74--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ul36tcvdzg2ku2j96fwx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_DIYwA74--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ul36tcvdzg2ku2j96fwx.png" alt="Share Project"&gt;&lt;/a&gt;Share Project&lt;/p&gt;

&lt;p&gt;Fill in the requested information and click on the "Share" button.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9T0f-Qzy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/iheioxo28kbeiq5tgfjt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9T0f-Qzy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/iheioxo28kbeiq5tgfjt.png" alt="Share window"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the next window, select the files you want to upload, fill in the Commit Message and click on the "Add" button.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y4lZPX3g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8zmioigk94id35ncoe3k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y4lZPX3g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8zmioigk94id35ncoe3k.png" alt="Selected files"&gt;&lt;/a&gt;Selected files&lt;/p&gt;

&lt;p&gt;The next edited files can be committed by clicking on VCS menu &amp;gt; Commit.&lt;br&gt;
Check the desired files, fill in the Commit Message and, on the bottom left click on the triangle next to the "Commit" button and click on the "Commit and Push"  option. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3DUX5usE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/wml86i2jdgkwi3lrax6t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3DUX5usE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/wml86i2jdgkwi3lrax6t.png" alt="Commit changes"&gt;&lt;/a&gt;Commit changes&lt;/p&gt;

&lt;p&gt;That way, the files will be versioned in your local machine and on the GitHub server as well.&lt;/p&gt;

&lt;p&gt;Confirm the push on the following screen and you are done.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--utwTX4OJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/wq12xw1x10udbk0epztv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--utwTX4OJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/wq12xw1x10udbk0epztv.png" alt="Push Commits"&gt;&lt;/a&gt;Push Commits&lt;/p&gt;

&lt;p&gt;Happy coding.&lt;/p&gt;

</description>
      <category>setup</category>
      <category>beginners</category>
      <category>github</category>
      <category>ide</category>
    </item>
    <item>
      <title>Starting to learn React-Native #01</title>
      <dc:creator>Victor Macarios</dc:creator>
      <pubDate>Sat, 30 Nov 2019 21:20:43 +0000</pubDate>
      <link>https://dev.to/vmacarios/starting-to-learn-react-native-part-01-42lf</link>
      <guid>https://dev.to/vmacarios/starting-to-learn-react-native-part-01-42lf</guid>
      <description>&lt;p&gt;Hello, folks!&lt;/p&gt;

&lt;p&gt;After great procrastination, I finally wrote my first post sharing my progress on React-Native.&lt;/p&gt;

&lt;p&gt;This text is based on Lex Lemmens's post at:&lt;br&gt;
&lt;a href="https://medium.com/swlh/writing-your-really-first-mobile-app-in-react-native-simple-to-do-app-e67f875f0721"&gt;https://medium.com/swlh/writing-your-really-first-mobile-app-in-react-native-simple-to-do-app-e67f875f0721&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'll use his tutorial to create my version of a To-Do App for iPhone. &lt;br&gt;
The content may differ due to the version of some components.&lt;/p&gt;

&lt;p&gt;So, let's start:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My config:&lt;/strong&gt;&lt;br&gt;
MacBook Pro 2010 (Core 2 Duo 2,4GHz)&lt;br&gt;
macOS Sierra (10.12.6)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Requirements:&lt;/strong&gt;&lt;br&gt;
• iPhone&lt;br&gt;
• Expo App&lt;br&gt;
• IDE/Editor (I will use VSCode)&lt;br&gt;
• Basic knowledge of macOS and Terminal app&lt;/p&gt;

&lt;p&gt;First of all, we need to install npm which is installed with Node.js.&lt;br&gt;
So, let's access &lt;a href="http://www.nodejs.org"&gt;www.nodejs.org&lt;/a&gt; and download node.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ov42E8WG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/kol6yozdyrp7ttq0z6eq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ov42E8WG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/kol6yozdyrp7ttq0z6eq.png" alt="Node JS Website"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on the downloaded installation package and follow the on-screen instructions.&lt;/p&gt;

&lt;p&gt;After that, open Terminal app and type the following commands to check if everything was correctly installed:&lt;/p&gt;

&lt;p&gt;$ node -v&lt;br&gt;
$ npm -v&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---YVtD_xZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1wgy3j46q7tl7csx1e63.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---YVtD_xZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1wgy3j46q7tl7csx1e63.png" alt="Commands to check node installation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then install Expo (a software which will serve our new application to the Expo app on iPhone) by typing:&lt;/p&gt;

&lt;p&gt;$ sudo npm install -g expo-cli&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6PUgKjbW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/yqiuxog4tz5090p5azio.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6PUgKjbW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/yqiuxog4tz5090p5azio.png" alt="Expo-cli installation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create a folder to keep our projects and enter in it:&lt;/p&gt;

&lt;p&gt;$ mkdir React&lt;br&gt;
$ cd React&lt;/p&gt;

&lt;p&gt;Then create a new project using:&lt;/p&gt;

&lt;p&gt;$ expo init ToDo&lt;/p&gt;

&lt;p&gt;Choose &lt;em&gt;"minimal"&lt;/em&gt; to create a default template.&lt;br&gt;
Set the &lt;em&gt;"name"&lt;/em&gt; and &lt;em&gt;"displayName"&lt;/em&gt; of the project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xMH368N0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/7dbzurg8cmqc3p0to1ok.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xMH368N0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/7dbzurg8cmqc3p0to1ok.png" alt="Creating project"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Navigate to the new project folder:&lt;/p&gt;

&lt;p&gt;$ cd ToDo&lt;/p&gt;

&lt;p&gt;And start the project server:&lt;/p&gt;

&lt;p&gt;$ expo start&lt;/p&gt;

&lt;p&gt;Your default web browser will open and the expo server will start running.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8rxutrIG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/pey1s5xr980cj6tq88sd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8rxutrIG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/pey1s5xr980cj6tq88sd.png" alt="Expo server running"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open your iPhone camera app and point it at the QR Code on the lower-left corner.&lt;br&gt;
Click on the notification at the top of the screen to open it in the Expo app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zlouyoUL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/uycpfwwmfqjm2t91hzoe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zlouyoUL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/uycpfwwmfqjm2t91hzoe.png" alt="Scanning QR Code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Wait a few moments for the first build to finish and a blank screen with an example text appears.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3nx5ab_R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/d69op4pbyk9h3wj4ztp1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3nx5ab_R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/d69op4pbyk9h3wj4ztp1.png" alt="First app running"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have our app running, let's open the App.js file with your favorite IDE.&lt;br&gt;
Start by cleaning the template file like the code below.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
App.js - Clean code


&lt;p&gt;Let's add a gradient color on the background and change the status bar to a white text color.&lt;br&gt;
To do that, import "LinearGradient" and "StatusBar" and add the following code:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
App.js - Adding some color


&lt;p&gt;The &lt;code&gt;"style={{ flex: 1 }}"&lt;/code&gt; code is to ensure that the gradient will cover the whole screen.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating the text inputs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The next step is to add text inputs where people will type the To-Do title.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
App.js - Creating and styling the Text Input


&lt;p&gt;Don't forget to import "TextInput".&lt;br&gt;
The &lt;code&gt;&amp;lt;View&amp;gt;&lt;/code&gt; section is the React Native correspondent to HTML &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;.&lt;br&gt;
The "styles" section is very similar to CSS.&lt;br&gt;
The options set in the TextInput component are called "props" in React Native.&lt;br&gt;
Read more about them in the official documentation:&lt;br&gt;
&lt;a href="https://facebook.github.io/react-native/docs/textinput.html#props"&gt;https://facebook.github.io/react-native/docs/textinput.html#props&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is how it should look now:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cCkhNZfq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ay5altrwbbr8h73pfb0x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cCkhNZfq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ay5altrwbbr8h73pfb0x.png" alt="Initial Screen"&gt;&lt;/a&gt;&lt;/p&gt;
Text Input



&lt;p&gt;&lt;strong&gt;The app logic&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now comes the part that will make our app come to life.&lt;br&gt;
The best way to define the logic is by splitting it into little steps.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A variable (state) that holds the text input value should be empty by default.&lt;/li&gt;
&lt;li&gt;The variable should change its value while the user is typing.&lt;/li&gt;
&lt;li&gt;After pressing enter (done) the text input value should be added to a list and be reset to a default empty value.&lt;/li&gt;
&lt;li&gt;By hitting the delete button the item is removed from the list.&lt;/li&gt;
&lt;li&gt;By hitting the edit button the user should be able to edit the entry.&lt;/li&gt;
&lt;li&gt;By marking the checkbox the item should be strikethrough.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Let's start:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, we should create and variable (state) with an empty default value and define that the text input component will use this state to hold its value.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
App.js - Setting state to default empty value


&lt;p&gt;Notice that we create a "state" and add a "value" prop in the text input component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second step&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we have to update the state when the user is typing.&lt;br&gt;
To do that we will use the "onChangeText={this.changeText}" prop, which will call the onChangeText method. This method receives the new value and set the new state of inputValue.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
App.js - Update inputValue with TextInput value


&lt;p&gt;&lt;strong&gt;Third step&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you hit done, the content should be stored in an array and showed on the list. &lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
App.js - Showing the list of saved items when hitting "done" 


&lt;p&gt;We create a new "todos" array in the state.&lt;br&gt;
There is where our To-Do items will be stored.&lt;/p&gt;

&lt;p&gt;We also added an "onSubmitEditing" prop in the Text Input that will call the "addItem" function. That function adds new items to the "todos" state.&lt;/p&gt;

&lt;p&gt;But why did we use concat() instead of push()? &lt;br&gt;
Because of the immutability of the state. &lt;br&gt;
The concat() doesn't modify the array but creates a new one.&lt;br&gt;
Read more at:&lt;br&gt;
&lt;a href="https://medium.com/javascript-in-plain-english/how-to-add-to-an-array-in-react-state-3d08ddb2e1dc"&gt;https://medium.com/javascript-in-plain-english/how-to-add-to-an-array-in-react-state-3d08ddb2e1dc&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the render function, we've added a variable "todos", that will map the whole array to rows with a side checkbox button (we need to import "TouchableOpacity" to make the button touchable). This variable is displayed in a &lt;code&gt;&amp;lt;View&amp;gt;&lt;/code&gt; after the Text Input.&lt;br&gt;
The concat() has been used here again because it's necessary to create a new array before we can reverse() the order. Otherwise, it will keep reversing as you type.&lt;/p&gt;

&lt;p&gt;That's how it looks right now.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--otl40f6D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/xfv1ut4jhdp83wdns21t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--otl40f6D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/xfv1ut4jhdp83wdns21t.png" alt="Items on the list"&gt;&lt;/a&gt;&lt;/p&gt;
Items on the list



&lt;p&gt;&lt;strong&gt;I'll be back!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I hope you are enjoying. &lt;br&gt;
The other steps of the logic will be described in the next post.&lt;br&gt;
If you have any questions or suggestions, feel free to contact me.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>reactnative</category>
    </item>
  </channel>
</rss>
