<?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: Ashley D</title>
    <description>The latest articles on DEV Community by Ashley D (@ashleyd480).</description>
    <link>https://dev.to/ashleyd480</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%2F1399631%2Ff6bf7a77-73eb-4c0e-8c1f-5e8865dea9fc.jpeg</url>
      <title>DEV Community: Ashley D</title>
      <link>https://dev.to/ashleyd480</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ashleyd480"/>
    <language>en</language>
    <item>
      <title>kotlin vs java- the very basics</title>
      <dc:creator>Ashley D</dc:creator>
      <pubDate>Sun, 09 Feb 2025 06:16:36 +0000</pubDate>
      <link>https://dev.to/ashleyd480/kotlin-vs-java-the-very-basics-3lpa</link>
      <guid>https://dev.to/ashleyd480/kotlin-vs-java-the-very-basics-3lpa</guid>
      <description>&lt;p&gt;A few months after bootcamp wrapped up for me, the class attended a career fair, and a few weeks later, I learned I’d be joining a primarily backend team that works in Kotlin. Since Kotlin was a new language to me, I decided to explore Kotlin fundamentals through Codecademy 📚.&lt;/p&gt;

&lt;p&gt;With less than 3 weeks until the start of the internship ⏳, I was initially worried I wouldn’t be able to learn it all in time 😰. But as I went through the intro course, I began to see parallels with Java ☕️—which we explored at a high level in the bootcamp.&lt;/p&gt;

&lt;p&gt;In this post, I’ll share some beginner-friendly insights into how Kotlin compares to Java, focusing on syntactical and practical differences and similarities that stood out to me 🔍.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fre7w54xabzsqwsvl9iom.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fre7w54xabzsqwsvl9iom.jpg" alt="Humorous cartoon of cramming Kotlin, a mountain to learn" width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;p&gt;✍️ &lt;strong&gt;Syntax&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Variable Declaration&lt;br&gt;
No Primitive Types&lt;br&gt;
String Interpolation&lt;br&gt;
Null Safety&lt;br&gt;
When vs Switch&lt;/p&gt;

&lt;p&gt;💿 &lt;strong&gt;Functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Defining Function&lt;br&gt;
Handling Void&lt;br&gt;
Lambda Expressions&lt;/p&gt;

&lt;p&gt;💻 &lt;strong&gt;Misc&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Collections&lt;br&gt;
Class Constructors &amp;amp; init&lt;/p&gt;


&lt;h2&gt;
  
  
  Syntax
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Variable Declaration
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Java Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Java, variables must be explicitly typed, meaning you have to specify the type of data the variable will hold when you declare it. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int age = 25;
String name = "John";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to make a variable immutable (i.e., its value cannot change after it's set), you can use the &lt;code&gt;final&lt;/code&gt; keyword:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final int age = 25; // Immutable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Kotlin Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Kotlin, you don't have to explicitly declare the type in most cases. The compiler automatically infers the type based on the assigned value. &lt;br&gt;
Also, instead of using &lt;code&gt;final&lt;/code&gt;, Kotlin uses &lt;code&gt;val&lt;/code&gt; for immutable variables and &lt;code&gt;var&lt;/code&gt; for mutable variables. &lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;val age = 25 // Immutable
var name = "John" // Mutable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The type inference reduces redundancy, making your code more concise and readable.&lt;br&gt;
However, you can still explicitly define the type if needed, especially when the type is not immediately clear from the value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;val newUser: Person = Person("John", 25)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the type of &lt;code&gt;newUser&lt;/code&gt; is explicitly declared as &lt;code&gt;Person&lt;/code&gt;, making it clear what type the variable will hold.&lt;/p&gt;




&lt;h3&gt;
  
  
  No Primitive Types
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Java Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Java, there are primitive types like &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;double&lt;/code&gt;, and &lt;code&gt;boolean&lt;/code&gt;, which are not objects. But Java also provides wrapper classes for each primitive type (e.g., &lt;code&gt;Integer&lt;/code&gt;, &lt;code&gt;Double&lt;/code&gt;, &lt;code&gt;Boolean&lt;/code&gt;) that allow you to treat them as objects:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int num = 10;
List&amp;lt;Integer&amp;gt; numbers = new ArrayList&amp;lt;&amp;gt;(); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Kotlin Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kotlin treats everything as an object, including types that would be primitive in Java. This allows for  consistent type system, making it easier to work with different kinds of variables without needing to distinguish between primitive types and objects. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;val num: Int = 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  String Interpolation
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Java Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Java, string concatenation requires the &lt;code&gt;+&lt;/code&gt; operator, which can get messy, especially when you need to include variables in strings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String greeting = "Hello, " + name + "!";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Kotlin Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kotlin simplifies string manipulation by allowing string interpolation which can make the code more readable and concise. &lt;br&gt;
This means you can directly embed variables inside strings using &lt;code&gt;${}&lt;/code&gt; for more complex expressions, or &lt;code&gt;$&lt;/code&gt; for simple variable interpolation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;val greeting = "Hello, $name!"
println("You have ${items.size} items in your cart.")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Null Safety
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Java Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Java, if you try to call a method on a &lt;code&gt;null&lt;/code&gt; object, you'll get a &lt;code&gt;NullPointerException&lt;/code&gt;. This is one of the most common runtime errors in Java:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String name = null;
System.out.println(name.length()); // Throws NullPointerException
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Kotlin Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kotlin introduces a safer way to handle nulls. By explicitly declaring whether a variable can be &lt;code&gt;null&lt;/code&gt;, you reduce the risk of &lt;code&gt;NullPointerExceptions&lt;/code&gt;. You can use the &lt;code&gt;?&lt;/code&gt; aka &lt;code&gt;elvis operator&lt;/code&gt; to perform safe calls, which won't crash your program even if the variable is &lt;code&gt;null&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var name: String? = null // Must handle null explicitly
println(name?.length) // Safe call, prints null instead of crashing
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;String?&lt;/code&gt; type means that the variable &lt;code&gt;name&lt;/code&gt; can hold a String or it can be null.

&lt;ul&gt;
&lt;li&gt;By using the &lt;code&gt;?&lt;/code&gt; operator (known as the "safe call operator"), you are telling Kotlin, "Check if &lt;code&gt;name&lt;/code&gt; is not null before accessing its length property." If &lt;code&gt;name&lt;/code&gt; is null, it won’t throw a &lt;code&gt;NullPointerException&lt;/code&gt;; instead, it will return null. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;So in this case, &lt;code&gt;println(name?.length)&lt;/code&gt; will safely print null instead of crashing the program.&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;code&gt;when&lt;/code&gt; vs &lt;code&gt;switch&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Java Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Java, the &lt;code&gt;switch&lt;/code&gt; statement is commonly used to check a variable against multiple possible values. However, it requires multiple &lt;code&gt;case&lt;/code&gt; labels and &lt;code&gt;break&lt;/code&gt; statements to prevent "fall-through”; that means - after each case- there must be a break statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// let’s pretend it’s Monday
switch (day) {

    case "Monday":

        System.out.println("Start of the week");

        // No break statement here, so it "falls through"

    case "Friday":

        System.out.println("Weekend is near");

        break;

    default:

        System.out.println("A regular day");

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Kotlin Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kotlin's &lt;code&gt;when&lt;/code&gt; expression prevents fall-through by design. Once a condition matches, it automatically stops execution without needing a &lt;code&gt;break&lt;/code&gt;. This makes Kotlin's &lt;code&gt;when&lt;/code&gt; expression more predictable and less error-prone, as there's no chance of accidentally executing multiple cases.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;when (day) {
    "Monday" -&amp;gt; println("Start of the week")
    "Friday" -&amp;gt; println("Weekend is near")
    else -&amp;gt; println("A regular day")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Functions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Defining Function
&lt;/h3&gt;

&lt;p&gt;In Java, you need to define functions with a return type, parameters, and an explicit &lt;code&gt;return&lt;/code&gt; statement if the function has a return value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public int addNumbers(int a, int b) {
    return a + b;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Kotlin Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Kotlin, defining functions is more concise. You can specify the types of the parameters and the return type explicitly, just like Java, but Kotlin allows you to simplify the function body.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun multiplyNumbers(a: Int, b: Int): Int {
    val result = a * b
    if (result &amp;gt; 100) {
        println("Result is large")
    }
    return result
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;fun&lt;/code&gt; is used to declare a function in Kotlin, followed by the function name (&lt;code&gt;addNumbers&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt; You define the types of the parameters (&lt;code&gt;a: Int, b: Int&lt;/code&gt;) and the return type (&lt;code&gt;: Int&lt;/code&gt;) just like in Java. This keeps the function strongly typed, ensuring type safety.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the function body contains only one expression aka &lt;code&gt;single expression&lt;/code&gt;, you can omit the &lt;code&gt;return&lt;/code&gt; keyword and simply use the expression after the &lt;code&gt;=&lt;/code&gt; sign, making the function shorter and easier to read.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun addNumbers(a: Int, b: Int): Int = a + b
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Handling Void
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Java Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Java, if a function doesn't return anything, it is defined as &lt;code&gt;void&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public void printMessage(String message) {
    System.out.println(message);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Kotlin Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Kotlin, functions that don't return a value return &lt;code&gt;Unit&lt;/code&gt; (which is similar to Java's &lt;code&gt;void&lt;/code&gt;). You don't need to explicitly declare it in the function signature:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun printMessage(message: String) {
    println(message)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Lambda Expressions
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Java Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Java uses streams and lambda expressions to handle functions concisely. However, the syntax can still feel bulky:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;Integer&amp;gt; numbers = Arrays.asList(1, 2, 3, 4, 5);
List&amp;lt;Integer&amp;gt; evenNumbers = numbers.stream()
    .filter(n -&amp;gt; n % 2 == 0)
    .collect(Collectors.toList());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Kotlin Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kotlin simplifies lambda expressions by making them shorter and easier to read. The curly braces &lt;code&gt;{}&lt;/code&gt; define the lambda block, and &lt;code&gt;it&lt;/code&gt; is an implicit name used for the single parameter passed to the lambda:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;val numbers = listOf(1, 2, 3, 4, 5)
val evenNumbers = numbers.filter { it % 2 == 0 }
println(evenNumbers) // Output: [2, 4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, &lt;code&gt;filter { it % 2 == 0 }&lt;/code&gt; is a lambda expression that filters out the even numbers from the list. The &lt;code&gt;it&lt;/code&gt; keyword refers to each element number that we're iterating over.&lt;/p&gt;




&lt;h2&gt;
  
  
  Misc
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Collections
&lt;/h3&gt;

&lt;p&gt;Collections are used to store multiple items in one variable. A list is a common type of collection that holds an ordered set of items, like a shopping list or a list of names.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Java Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Java, you typically use &lt;code&gt;ArrayList&lt;/code&gt; to work with collections of items. You need to manually specify whether the list is mutable or immutable, and you also need the &lt;code&gt;new&lt;/code&gt; keyword to create the list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ArrayList&amp;lt;String&amp;gt; fruits = new ArrayList&amp;lt;&amp;gt;();
fruits.add("Apple");
fruits.add("Banana");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Kotlin Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Kotlin, you can create immutable and mutable lists more easily. The &lt;code&gt;listOf&lt;/code&gt; creates an immutable list by default, while &lt;code&gt;mutableListOf&lt;/code&gt; creates a mutable list. &lt;br&gt;
Also, you don't need the &lt;code&gt;new&lt;/code&gt; keyword, making list initialization simpler. Kotlin automatically initializes the list with the elements you provide with &lt;code&gt;listOf&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;val fruits = listOf("Apple", "Banana") // Immutable
val mutableFruits = mutableListOf("Apple")
mutableFruits.add("Banana")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Class Constructors &amp;amp; init
&lt;/h3&gt;

&lt;p&gt;A class is like a blueprint for creating objects. It defines what properties (variables) and actions (methods) the objects created from it will have. The constructor is a special function that runs when the class is used to create an object, and it initializes the object's properties.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Java Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Java, creating a class with properties involves more boilerplate code. Here, the &lt;code&gt;Person&lt;/code&gt; class has two properties: &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;age&lt;/code&gt;, which are set through a constructor. The constructor is a special method that takes the &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;age&lt;/code&gt; values when a new &lt;code&gt;Person&lt;/code&gt; object is created:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Person {
    private String name; // Property for name
    private int age; // Property for age

    // Constructor that sets the name and calculates age when the object is created
    public Person(String name, int birthYear) {
        this.name = name; // Initializes the name property
        int currentYear = 2024;
        this.age = currentYear - birthYear; // Calculates age based on birth year
        System.out.println("Age calculated: " + age);
    }

    // Main method to create a new Person object
    public static void main(String[] args) {
        Person person = new Person("John", 1990);  // Constructor is called to initialize the object
        // The age is automatically calculated in the constructor based on birthYear
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this Java example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The &lt;code&gt;Person&lt;/code&gt; class has a constructor that takes &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;birthYear&lt;/code&gt; as parameters.&lt;/li&gt;
&lt;li&gt;  The &lt;code&gt;age&lt;/code&gt; is calculated within the constructor, similar to the &lt;code&gt;init&lt;/code&gt; block in Kotlin, and is printed as part of the initialization process.&lt;/li&gt;
&lt;li&gt;  When a new &lt;code&gt;Person&lt;/code&gt; object is created, the constructor automatically runs to initialize the object's properties and calculate the &lt;code&gt;age&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Kotlin Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kotlin simplifies class constructors with its &lt;code&gt;primary constructor&lt;/code&gt; --- allowing the parameters to be directly included in the class definition. This reduces the need for a separate constructor method and makes the code more concise:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person(val name: String, val age: Int)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this Kotlin example, &lt;code&gt;Person&lt;/code&gt; is a class with two properties (&lt;code&gt;name&lt;/code&gt; and &lt;code&gt;age&lt;/code&gt;) declared directly in the class. These properties are automatically initialized when an object of &lt;code&gt;Person&lt;/code&gt; is created.&lt;/p&gt;

&lt;p&gt;Kotlin also offers a special feature called the &lt;code&gt;init&lt;/code&gt; block. The &lt;code&gt;init&lt;/code&gt; block runs automatically when an object is instantiated, and it allows for additional setup or property initialization. You don't need to call it explicitly---it just runs when the object is created.&lt;/p&gt;

&lt;p&gt;For example, the &lt;code&gt;Person&lt;/code&gt; class in Kotlin can also use an &lt;code&gt;init&lt;/code&gt; block for initialization:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person(val name: String, val birthYear: Int) {
    var age: Int = 0

    // The init block is used to initialize properties or perform setup tasks
    init {
        val currentYear = 2024
        age = currentYear - birthYear
        println("Age calculated: $age")
    }
}

fun main() {
    val person = Person("John", 1990)  // Init block runs automatically
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this Kotlin example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The &lt;code&gt;Person&lt;/code&gt; class has a primary constructor with &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;birthYear&lt;/code&gt; parameters.&lt;/li&gt;
&lt;li&gt;  The &lt;code&gt;init&lt;/code&gt; block calculates the &lt;code&gt;age&lt;/code&gt; based on the &lt;code&gt;birthYear&lt;/code&gt; and prints the result.&lt;/li&gt;
&lt;li&gt;  When the object is created, the &lt;code&gt;init&lt;/code&gt; block automatically runs to handle the initialization.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>beginners</category>
      <category>learning</category>
      <category>kotlin</category>
      <category>cheatsheet</category>
    </item>
    <item>
      <title>2024: retro.filter(experiences =&gt; share(experiences))</title>
      <dc:creator>Ashley D</dc:creator>
      <pubDate>Sun, 02 Feb 2025 05:14:50 +0000</pubDate>
      <link>https://dev.to/ashleyd480/2024-retrofilterexperiences-shareexperiences-2b2o</link>
      <guid>https://dev.to/ashleyd480/2024-retrofilterexperiences-shareexperiences-2b2o</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/newyear"&gt;2025 New Year Writing challenge&lt;/a&gt;: Retro’ing and Debugging 2024.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  await fetch("example.com/api/opportunity")
&lt;/h2&gt;

&lt;p&gt;For years, I faced rejection after rejection in my journey to enter tech. Like an &lt;strong&gt;&lt;code&gt;async&lt;/code&gt;&lt;/strong&gt; function, I kept running with no clear return value. But I kept going, not wanting to write my &lt;strong&gt;&lt;code&gt;return&lt;/code&gt;&lt;/strong&gt; statement prematurely and giving up. I found outlets to use and build upon my love of tech: training new hires on product and troubleshooting, contributing to tech projects like improving bug tracking and process enhancements, and more.&lt;/p&gt;

&lt;p&gt;Finally, after all that waiting and uncertainty, the call came through—my opportunity was returned. ⏳. In 2024, I was accepted to a one year technical program which included a 4 month bootcamp, project phase, followed by an internship 🚀. &lt;/p&gt;




&lt;h2&gt;
  
  
  public void StartBootcamp() {
&lt;/h2&gt;

&lt;p&gt;Joining the technical program was a dream come true after years of closed doors 🚪. However, as I’m not one to celebrate, - I was more-so my typical nervous self, fearful that I might not keep up with the program or fail to meet expectations. The first few weeks were filled with uncertainty 😟, but as time went on, I began to embrace the learning process. 📚&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Overcoming imposter syndrome&lt;/strong&gt;: &lt;br&gt;
Early on, I struggled with imposter syndrome, especially when I saw classmates &lt;strong&gt;&lt;code&gt;compiling&lt;/code&gt;&lt;/strong&gt; concepts more quickly. However, my curiosity and willingness to ask questions helped me push through. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Embracing the challenge&lt;/strong&gt;: &lt;br&gt;
Initially, I saw bugs as barriers 🐞 especially when it meant being stuck on homework in the morning with the deadline ticking closer each second  ⏰, but over time, I realized they were opportunities to learn and grow. I joked that I was a bug magnet 🧲. I found that a lot of my learning came from bugs and debugging 🔧.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After each project, I documented my retrospectives in &lt;a href="https://github.com/ashleyd480" rel="noopener noreferrer"&gt;GitHub READMEs&lt;/a&gt;, sharing bugs I encountered and how I resolved them. This process helped me reflect on my learnings and share insights with the community 🧑‍🤝‍🧑. I posted some of my retros on bugs encountered to dev.to too (&lt;a href="https://dev.to/ashleyd480/wk7-java-cli-app-retro-5ecj"&gt;example&lt;/a&gt;) as I wanted to normalize that failures and mistakes are just as much of a win when we approach them as a way to grow from. 🌱&lt;/p&gt;

&lt;p&gt;I also wrote about these &lt;a href="https://dev.to/ashleyd480/series/29770"&gt;experiences&lt;/a&gt; on dev.to to help future students navigating similar careers transitions and bootcamps to emotionally navigate &lt;/p&gt;




&lt;h2&gt;
  
  
  git diff: expectations vs reality
&lt;/h2&gt;

&lt;p&gt;As the program progressed, I worried it would become incrementally harder, like an &lt;strong&gt;&lt;code&gt;O(n) curve&lt;/code&gt;&lt;/strong&gt; on a &lt;strong&gt;&lt;code&gt;Big O graph&lt;/code&gt;&lt;/strong&gt; 📈. I discovered that while the daily challenges were daunting, my hunger to learn kept me engaged. I especially found it interesting to dive into  the “how” and “why” 🤔, and exploring the mechanics of programming fascinated me 🤖.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;let interest = “frontend”&lt;/strong&gt;: &lt;br&gt;
I started the program with a strong interest in front-end design 🎨, influenced by my creative outlets in dancing and singing.  One of the first bootcamp projects, I used my prior experience I face with barriers to get jobs to create a &lt;a href="https://github.com/ashleyd480/inclusive-jobseeker-referral-site" rel="noopener noreferrer"&gt;frontend mockup&lt;/a&gt; of a "refer-All" (referral) website. As I dived deeper into backend work, I found a passion for building APIs and understanding the logic behind the code ⚙️.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;interest = “fullstack”&lt;/strong&gt;: &lt;br&gt;
Reflecting on my &lt;a href="https://github.com/ashleyd480/access-map-app-capstone" rel="noopener noreferrer"&gt;capstone project&lt;/a&gt;, which focused on aggregating crowdsourced accessibility data 🗺️,, I found joy in creating meaningful insights through API and endpoint creation. 🌐 The program curriculum opened my eyes to the beauty of backend work, and I found myself falling in love with it. Towards the end, I found an interest in fullstack - especially enjoying building the endpoints to process and send data, and thinking through the logic of how to render that data on the frontend- akin to choreographing steps in a tango 🕺 💃.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  while (newKnowledge) {shareKnowledge++;}
&lt;/h2&gt;

&lt;p&gt;Throughout my journey, I made it a priority to share my knowledge and contribute to the community 🌍. Teaching and helping others is something that fills me, and writing things out helps me marinate and reinforce my own learnings 🧑‍🍳.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Writing Beginner-Friendly Articles&lt;/strong&gt;: &lt;br&gt;
I wanted to make learning code fun and accessible to beginners. 💕 This stemmed from my own struggles in bootcamp- noting a lack of beginner-friendly resources, and I am beyond grateful for the dev.to to allow me to share these articles publicly ✍️. &lt;br&gt;
For instance, I explained Big O notation through a &lt;a href="https://dev.to/ashleyd480/big-0-notation-laundry-day-1422"&gt;story of sorting laundry&lt;/a&gt;🗄️. I even created a &lt;a href="https://dev.to/ashleyd480/sql-joins-moving-in-together-1ol1"&gt;humorous article&lt;/a&gt; of SQL joins as a couple moving in 🏠. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Collaboration and Teamwork&lt;/strong&gt;: &lt;br&gt;
Whether helping with backend issues or discussing complex topics like Spring Boot, I worked with my classmates by sharing tips and tricks on Slack, and creating resources like cheat sheets to make learning easier for everyone. Some of these &lt;a href="https://dev.to/ashleyd480/series/27218"&gt;cheat sheets&lt;/a&gt; were also shared publicly of dev.to to help the wider community.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Teachbacks&lt;/strong&gt;: &lt;br&gt;
I recorded &lt;a href="https://www.youtube.com/watch?v=yA2RyRNSu7E&amp;amp;list=PL97VrtuAfZm_Cs85D8DYnlK7saz852a6y" rel="noopener noreferrer"&gt;teachbacks&lt;/a&gt; to better understand complex topics 🎥, talking through my thought process while having the code in front of me  👨‍💻.  Sharing these teachbacks with my cohorts helped others grasp difficult concepts, such as &lt;a href="https://youtu.be/xMZj8bgDpvU?feature=shared" rel="noopener noreferrer"&gt;connecting frontend and backend&lt;/a&gt;. Additionally, having a library of teachbacks allows me to reference them in the future, making the learning process more effective.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  refactoring my post-bootcamp learnings
&lt;/h2&gt;

&lt;p&gt;When bootcamp ended, instead of treating it as a breather after a marathon of a bootcamp- my first thought? Printing my 500+ pages of notes at Staples and reviewing them. I feared my brain would &lt;strong&gt;&lt;code&gt;stream API&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;.filter()&lt;/code&gt;&lt;/strong&gt; everything I’d learned if I didn’t immediately go back and study.&lt;/p&gt;

&lt;p&gt;Without the structure of office hours and classes, I proactively took it upon myself to work on some passion projects. Through this, I saw how I learn best hands-on, and doing these projects helped me &lt;strong&gt;&lt;code&gt;refactor&lt;/code&gt;&lt;/strong&gt; my understanding, retaining high-level concepts and improving my approach to learning.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Slack API project&lt;/strong&gt;: After overhearing another mentor’s painpoint for having to manually screenshot and share channels he belongs in to new hires, I built &lt;a href="https://github.com/ashleyd480/export-slack-channel-template" rel="noopener noreferrer"&gt;endpoints&lt;/a&gt; for the Slack API to allow users to fetch that list instead. While I initially impatiently tried to jump right into coding, a few unsuccessful attempts taught me the importance of reading the documentation 📄 first. I ended up sharing a more beginner-friendly version of it as a blog post 📝.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Portfolio Development&lt;/strong&gt;:  I continued my growth by building out my &lt;a href="https://github.com/ashleyd480/ashley-portfolio-frontend" rel="noopener noreferrer"&gt;portfolio&lt;/a&gt;, challenging myself to build it full-stack. Deploying it was daunting, but the discomfort allowed me to learn about using PSQL to populate my database 💾, integrating environmental variables, Dockerizing my app 🐳, and migrating Postgres to Heroku. As there was no beginner-friendly resource on deploying backend, I published my &lt;a href="https://dev.to/ashleyd480/how-to-deploy-backend-4b05"&gt;learnings&lt;/a&gt; on dev.to to help others who may be looking to do the same.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Google Maps Calculator&lt;/strong&gt;:  I helped the Google Maps volunteer community 🗺️ by creating a &lt;a href="https://github.com/ashleyd480/local-guide-points-calculator" rel="noopener noreferrer"&gt;tool&lt;/a&gt; that calculates customized plans to reach their points goal 📈. This project not only benefited the community but also helped me solidify my understanding of React, making concepts click in ways they hadn’t during bootcamp.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  &lt;strong&gt;where my linked list node .next points toward&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Looking back, 2024 has been a year of immense growth—both professionally and personally. I’ve learned that setbacks are part of the journey, and each challenge is an opportunity to grow stronger. I’ve embraced every bug 🦋, every failure 🚧, and every success 🏆 as part of a larger process of self-discovery.&lt;/p&gt;

&lt;p&gt;After navigating through the twists and turns of my journey, the &lt;strong&gt;&lt;code&gt;.next&lt;/code&gt;&lt;/strong&gt; pointer in my career path led me to an internship in software development. What started as a series of small, incremental steps now feels like a well-defined path. Just like a &lt;strong&gt;&lt;code&gt;linked list&lt;/code&gt;&lt;/strong&gt; that’s constantly evolving, I’m continually learning, growing, and adding new skills to my next phase as I dive deeper into the world of tech.&lt;/p&gt;

&lt;p&gt;Looking ahead, I know that the road ahead won’t be without its challenges, but with the skills I’ve gained and the mindset I’ve developed in 2024 —I’m ready to take on whatever comes my way. Just like a well-optimized &lt;strong&gt;&lt;code&gt;linked list&lt;/code&gt;,&lt;/strong&gt; each new &lt;strong&gt;&lt;code&gt;node&lt;/code&gt;&lt;/strong&gt; in my journey will connect me to even more opportunities to learn and grow. 💖 &lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>newyearchallenge</category>
      <category>career</category>
      <category>beginners</category>
    </item>
    <item>
      <title>surviving coding bootcamp: project planning</title>
      <dc:creator>Ashley D</dc:creator>
      <pubDate>Sun, 15 Dec 2024 05:43:11 +0000</pubDate>
      <link>https://dev.to/ashleyd480/surviving-coding-bootcamp-project-planning-3dg3</link>
      <guid>https://dev.to/ashleyd480/surviving-coding-bootcamp-project-planning-3dg3</guid>
      <description>&lt;p&gt;Coding projects are a central part of bootcamp life, but let’s be real—when you first get that project brief, the wave of panic can be real. You’ve just learned the concepts, and now you’re expected to apply them in a limited timeframe. It’s easy to feel overwhelmed, freeze up, or even procrastinate- and I’ve experienced all those feelings. 💕👨‍💻&lt;/p&gt;

&lt;p&gt;Here are some strategies that helped me get started and stay on track during my bootcamp projects:&lt;/p&gt;

&lt;p&gt;I’ll include examples too of how I applied them in bootcamp’s social media site backend &lt;a href="https://github.com/ashleyd480/referral-site-api-backend" rel="noopener noreferrer"&gt;project&lt;/a&gt; and in my capstone &lt;a href="https://github.com/ashleyd480/access-map-app-capstone/tree/main" rel="noopener noreferrer"&gt;project&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
Start Small: Beat Procrastination by Taking the First Step
&lt;/li&gt;
&lt;li&gt;
Plan with Diagrams
&lt;/li&gt;
&lt;li&gt;
Don’t Over-Plan
&lt;/li&gt;
&lt;li&gt;
Think About User Experience (Not Just CRUD)
&lt;/li&gt;
&lt;li&gt;Work on Frontend and Backend Together&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  1. Start Small: Beat Procrastination by Taking the First Step
&lt;/h2&gt;

&lt;p&gt;When a project feels like an insurmountable task, break it down. Start with something simple:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Read through the project requirements carefully.&lt;/strong&gt;&lt;br&gt;
Highlight key points, make notes, and write down any questions you might have for your instructor. Clearing up confusion early on saves you from headaches later.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create a checklist.&lt;/strong&gt;&lt;br&gt;
Write down the tasks you need to accomplish. A checklist transforms the project from a big, overwhelming blob into tangible, manageable steps. Plus, checking off items as you go gives a sense of accomplishment and momentum.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is an example of a checklist I made when working on my bootcamp’s social media site backend project:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvve4gvnoejid3z09bdky.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvve4gvnoejid3z09bdky.png" alt="Social Media Backend Checklist" width="800" height="901"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Plan with Diagrams
&lt;/h2&gt;

&lt;p&gt;Before diving into the code, spend some time planning your application’s structure.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use an ERD diagram for your backend.&lt;/strong&gt;
When building out the social media site, for example, I used an Entity-Relationship Diagram (ERD) to map out entities like &lt;code&gt;User&lt;/code&gt;, &lt;code&gt;Post&lt;/code&gt;, and &lt;code&gt;Tag.&lt;/code&gt; I defined their attributes (&lt;code&gt;content&lt;/code&gt;, &lt;code&gt;likes&lt;/code&gt;, etc.) and relationships (e.g., “one user can have many posts”). &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This visual roadmap made it much easier to understand how the pieces fit together:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F04kk9pvxrpaamql33exw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F04kk9pvxrpaamql33exw.png" alt="ERD Diagram for Social Media Backend" width="800" height="725"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Draw your frontend layout.&lt;/strong&gt;
For frontend planning, tools like &lt;a href="https://excalidraw.com/" rel="noopener noreferrer"&gt;Excalidraw&lt;/a&gt; or &lt;a href="https://www.autodraw.com/" rel="noopener noreferrer"&gt;AutoDraw&lt;/a&gt; are great for sketching your app’s UI. For example, before building out a login page, sketch out where the input fields, buttons, and error messages will go. Having this visual guide saves you from getting lost in your code later.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below is an example of a wireframe I made for my capstone to represent the search page:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F07cztoch1czfw4dl0ee1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F07cztoch1czfw4dl0ee1.png" alt="Capstone Wireframe" width="633" height="700"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Don’t Over-Plan
&lt;/h2&gt;

&lt;p&gt;Planning is critical, but bootcamp projects are short- typically a week— so limit your planning to a day. Also, aim to save at least half a day at the end for final touches, bug fixes, and polish.&lt;/p&gt;

&lt;p&gt;And while it might be tempting to tweak things the night before, resist the urge to make big changes at the last minute. It’s easy to accidentally introduce bugs, and you’ll want that time to focus on debugging, testing, and presentation prep.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Think About User Experience (Not Just CRUD)
&lt;/h2&gt;

&lt;p&gt;When designing your backend, don’t just focus on CRUD (Create, Read, Update, Delete) operations for each entity. Think about the user experience and build your endpoints accordingly.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In my social media project, users had associated addresses. It didn’t make sense to create a separate delete operation for an address since deleting a user should also delete their associated address.&lt;/li&gt;
&lt;li&gt;I also realized that users might want to search posts by keywords, so I added a &lt;code&gt;GET /search?keyword=...&lt;/code&gt; endpoint to fetch relevant posts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Designing with the frontend user in mind not only enhances your app’s functionality but also shows a deeper understanding of real-world application needs.&lt;/p&gt;

&lt;p&gt;You can use a Google Sheet to brainstorm those frontend user actions and endpoints. Below is  a snippet of what that looked like for my backend social media project:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpldroafyz6zdj2awpv1s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpldroafyz6zdj2awpv1s.png" alt="Brainstorming User Actions and Endpoints for Social Media Backend" width="800" height="503"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Work on Frontend and Backend Together
&lt;/h2&gt;

&lt;p&gt;The capstone project is your biggest challenge— and your biggest opportunity, and it is when you will typically get to do a full-stack project. &lt;/p&gt;

&lt;p&gt;I found it helpful to build the frontend and backend in tandem, focusing on one section at a time.&lt;/p&gt;

&lt;p&gt;Here’s how I approached my capstone project, an accessibility app where users could crowdsource and search for accessible locations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;“Break” your app into features- for mine, that was login, user profile, search, and contribute pages. &lt;/li&gt;
&lt;li&gt;Start with a single feature, like the login page.&lt;/li&gt;
&lt;li&gt;Build the backend for the feature first: create endpoints, test them with Postman, and confirm they work locally.&lt;/li&gt;
&lt;li&gt;Then, move to the frontend for that feature: integrate the endpoints and ensure the feature functions as intended.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By working one section at a time, you create “completed” parts of the app. Even if you run out of time, you’ll have fully functional features to showcase, reducing anxiety when it’s time to present your project.&lt;/p&gt;




&lt;p&gt;By taking small steps, visualizing your app, and working methodically, you can make coding projects more approachable—and even enjoyable. Whether you’re building a backend with ERD diagrams or sketching your UI, I hope these strategies help you stay organized, make progress, and finish strong.🤗💕&lt;/p&gt;

</description>
      <category>learning</category>
      <category>bootcamp</category>
      <category>beginners</category>
      <category>planning</category>
    </item>
    <item>
      <title>surviving coding bootcamp: lessons learned</title>
      <dc:creator>Ashley D</dc:creator>
      <pubDate>Mon, 28 Oct 2024 06:35:09 +0000</pubDate>
      <link>https://dev.to/ashleyd480/surviving-coding-bootcamp-lessons-learned-58am</link>
      <guid>https://dev.to/ashleyd480/surviving-coding-bootcamp-lessons-learned-58am</guid>
      <description>&lt;p&gt;This year, I turned a fresh new page in my book after 10 years of client-facing work, diving into the world of tech at General Assembly’s coding bootcamp. It’s been a rollercoaster—one with plenty of code, coffee, and moments of self-doubt. Yet, every bug and roadblock has turned into an opportunity for growth. Now, as I reflect on my bootcamp experience, I want to humbly share a few lessons I gained from my journey to anyone embarking on this wild ride.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Emotionally Navigating Bootcamp: Building Resilience and Community&lt;/li&gt;
&lt;li&gt;Mastering Homework: Strategic Approaches for Success&lt;/li&gt;
&lt;li&gt;Working with a Mentor: Maximizing Support and Growth&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Emotionally Navigating Bootcamp: Building Resilience and Community
&lt;/h2&gt;

&lt;p&gt;Bootcamp is intense. It’s fast-paced and packed with new concepts, and it can feel overwhelming, especially if you’re new to coding. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Anecdote:&lt;/strong&gt;&lt;br&gt;
I was really hard on myself at first. I’m a late bloomer in my career and life, and prior rejections built up a low self-image. I worried I would get kicked out of the bootcamp after a month. When I saw classmates rapidly mastering concepts, I felt behind— especially the day I struggled to get flexbox figured out. My project looked like a melted egg during show-and-tell.  &lt;/p&gt;

&lt;p&gt;I was beyond stressed and even cried at times, often unable to celebrate my own progress and only seeing my shortcomings. I wouldn’t take weekends or evenings off, which led to a mini episode of burnout in the first month. As time went on in the bootcamp, I became stronger and found ways to reframe my thinking. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tips:&lt;/strong&gt;&lt;br&gt;
Here’s what I learned about navigating the emotional ups and downs:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Embrace Vulnerability ❤️:&lt;/strong&gt; Don’t be afraid to speak up if you need more time with assignments or to ask questions during class. Communicating openly with instructors not only helps you but can also benefit others in your cohort. I found that sharing my struggles (rather than hiding them) allowed me to make the most of the support offered.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Celebrate Your Journey 🎉:&lt;/strong&gt;  When it feels tough, remember how far you’ve come. Think back to Day 1 and recognize your progress. It’s easy to get caught up in the challenges, but give yourself grace and take a moment to celebrate the wins, big or small. We all learn at different paces and have varied experience levels, so there’s no need to compare yourself to others.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Accommodations 💻:&lt;/strong&gt;  Have your instructor take advantage of tools like &lt;a href="https://visualstudio.microsoft.com/services/live-share/" rel="noopener noreferrer"&gt;Live Share&lt;/a&gt; during code-alongs. This collaborative feature allows you to see your instructor's screen in real-time, follow their code steps, and ask questions as they go.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Take Breaks 🌼:&lt;/strong&gt;  Sometimes, the best debugging tool is a break. Walk away, listen to music, or even grab a snack. A fresh mind often leads to breakthroughs and also prevents burnout.&lt;/p&gt;




&lt;h2&gt;
  
  
  Mastering Homework: Strategic Approaches for Success
&lt;/h2&gt;

&lt;p&gt;Homework is where bootcamp concepts really start to sink in, but it can feel daunting. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Anecdote:&lt;/strong&gt;&lt;br&gt;
I learned this the hard way during the first few weeks. I felt overwhelmed by all the information being thrown at me and often experienced anxiety trying to process it all. For our first major assignment— a website due over the weekend after the first week of onboarding and classes—I waited until Monday evening to start. I spent Monday organizing my notes and making sure I fully understood everything, but by that night, I was freaking out.&lt;/p&gt;

&lt;p&gt;I also remember how, in those first few weeks, when we had homework hour right after class, I often felt too overwhelmed to start. I wanted to understand everything and solve all the bonus questions too, which led me to go down rabbit holes. It would have been better to take small steps early on rather than waiting until the last minute and feeling anxious at night.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tips:&lt;/strong&gt;&lt;br&gt;
Here’s how I learned to tackle assignments efficiently:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Start Early 🕒:&lt;/strong&gt; If class ends early, dive into your homework. Starting promptly allows you to chip away at the assignment without last-minute stress, giving you the mental space to absorb what you’re learning.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build the Foundation 🔧:&lt;/strong&gt; Begin by setting up your development environment and creating any basic files or structures you’ll need. Laying out the skeleton files helps you get organized and ready to focus on the code itself.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ask for Clarification 👨‍🏫:&lt;/strong&gt; Use class time to ask questions about anything unclear. I found that understanding the core concepts before I left class made homework much more manageable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Master the Basics 📚:&lt;/strong&gt; Spend time solidifying foundational concepts. Focus on the underlying principles instead of memorizing syntax! Strengthening your basics will make advanced concepts easier as you move forward.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Leverage AI Tools 🤖:&lt;/strong&gt; Use AI-powered platforms or chatbots to help you debug your code or clarify concepts you're struggling with. These tools can provide instant feedback, or explain complex topics in a more digestible way, enhancing your learning experience and helping you become more independent in problem-solving.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Seek Help Strategically 🆘:&lt;/strong&gt; Work through problems on your own for 30-45 minutes before reaching out. This self-driven exploration is crucial for developing problem-solving skills. If you’re still stuck, ask classmates, instructors, or mentors for guidance, making it a collaborative learning experience.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Engage in Homework Review Sessions 🔄:&lt;/strong&gt; These sessions are not only for clarifying any confusing parts of the homework but also for gaining new insights from instructors’ feedback. Don’t hesitate to ask questions during these reviews— understanding the “why” behind an answer can be transformative.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Working with a Mentor: Maximizing Support and Growth
&lt;/h2&gt;

&lt;p&gt;Mentorship can be a lifeline in bootcamp. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Anecdote:&lt;/strong&gt;&lt;br&gt;
I remember feeling really nervous around my mentor at first, worried he’d think my questions were silly while I tried to impress him. However, midway through my apprenticeship, I realized that being more human and open improved our relationship. I started sharing consistent updates on what I was learning and working on, and during each meeting, I clearly communicated what I wanted to focus on and what I was having difficulties with. I approached our discussions with a collaborative mindset, saying, “let’s solve this together.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tips:&lt;/strong&gt;&lt;br&gt;
Here’s how I built a supportive relationship with my mentor and made the most of our sessions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Establish a Consistent Meeting Schedule 📅:&lt;/strong&gt; Regular meetings (weekly or bi-weekly) can be incredibly beneficial, especially if you’re juggling multiple projects or feel stuck. Don’t hesitate to reach out for additional meetings when needed, particularly during urgent project deadlines or if there is a week of complex concepts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prepare an Agenda 📋:&lt;/strong&gt; Coming to each session with a list of specific questions and topics ensures you make the most of your time together. If possible, send code snippets or key issues ahead of time to help your mentor prepare.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Be Open About Challenges 🤝:&lt;/strong&gt; Mentors aren’t just there to help with code. Share your struggles, celebrate your successes, and be honest about what’s tough. This transparency strengthens your connection and allows your mentor to provide tailored guidance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Share Your Understanding 💬:&lt;/strong&gt; During your meetings, take time to explain concepts or solutions you think you understand.  Your mentor can provide feedback, correct misunderstandings, and deepen your grasp of the material.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Document Solutions 📝:&lt;/strong&gt; Take notes on what you cover with your mentor, including any resources or solutions shared. These notes are invaluable for review and can help you navigate similar problems down the road.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build a Connection Beyond Code 🌟:&lt;/strong&gt; Get to know your mentor on a personal level. Whether it’s discussing their interests or sharing your own, this human connection fosters a supportive environment where learning feels collaborative, not just technical.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Final Thoughts: Embrace the Journey
&lt;/h2&gt;

&lt;p&gt;Bootcamp isn’t easy. You’ll encounter bugs, setbacks, and times when you doubt yourself, but each challenge is a stepping stone. So take it all in stride, ask for help when you need it, and remember to enjoy the process.&lt;/p&gt;

&lt;p&gt;In the end, bootcamp isn’t just about learning to code; it’s about discovering your resilience, embracing your curiosity, and finding joy in the journey. Happy coding! 💕&lt;/p&gt;

</description>
      <category>learning</category>
      <category>bootcamp</category>
      <category>beginners</category>
      <category>career</category>
    </item>
    <item>
      <title>seeing react through java lens</title>
      <dc:creator>Ashley D</dc:creator>
      <pubDate>Mon, 21 Oct 2024 07:05:07 +0000</pubDate>
      <link>https://dev.to/ashleyd480/seeing-react-through-java-lens-4k6i</link>
      <guid>https://dev.to/ashleyd480/seeing-react-through-java-lens-4k6i</guid>
      <description>&lt;p&gt;In our coding bootcamp, as we speedran through React and sweated through our labs, our instructor would say - "If you squint, React is a lot like Java." &lt;/p&gt;

&lt;p&gt;At first, it was just a catchy and funny phrase. 🤣 However, most recently, I revisited React while working on a personal Google Map calculator &lt;a href="https://github.com/ashleyd480/local-guide-points-calculator" rel="noopener noreferrer"&gt;project&lt;/a&gt;. Days deep into it, I could start to see some of those similarities come to light.&lt;/p&gt;

&lt;p&gt;Let’s dive into these connections and see how the foundational concepts of Java can illuminate our understanding of React. 💕&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frflzagw3ybghk01xsn93.jpg" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frflzagw3ybghk01xsn93.jpg" alt="Funny Bootcamp Teacher" width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;App.jsx as the Java main Class (psvm)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;State Management with Hooks as Java Getters and Setters&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Containers as Java Classes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Components as Java Methods&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;React’s Return in Components&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Props as Java Method Parameters&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Callback Functions as Java Methods that Return Values&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  1. App.jsx as the Java main Class (psvm)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Java:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Java, the &lt;code&gt;main&lt;/code&gt; class  serves as the entry point for the program, and it initiates the execution of the program.&lt;/p&gt;

&lt;p&gt;For instance, you might instantiate objects of different classes and invoke their respective methods:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Main {
    public static void main(String[] args) {
        Home home = new Home();
        home.render();
        About about = new About();
        about.show();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;React:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Similarly, in a React application, the &lt;code&gt;App.jsx&lt;/code&gt; file plays a comparable role by orchestrating the main application flow. &lt;/p&gt;

&lt;p&gt;Just as the &lt;code&gt;main&lt;/code&gt; method in Java can call multiple functions, &lt;code&gt;App.jsx&lt;/code&gt; is responsible for rendering all the components based on the application's routing and current state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Routes&amp;gt;
  &amp;lt;Route exact path="/" element={&amp;lt;Home /&amp;gt;} /&amp;gt;
  &amp;lt;Route path="/about" element={&amp;lt;About /&amp;gt;} /&amp;gt;
&amp;lt;/Routes&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above React example from &lt;code&gt;App.jsx&lt;/code&gt;,  the components rendered in the return statement mirror the process of calling methods or initializing objects in Java. &lt;/p&gt;

&lt;p&gt;In this case, the containers &lt;code&gt;&amp;lt;Welcome /&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;Home /&amp;gt;&lt;/code&gt; pages are rendered based on the web page URL path.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. State Management with Hooks as Java Getters and Setters
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Java:&lt;/strong&gt;&lt;br&gt;
In Java, you manage properties with variables and public getter/setter methods to get and set properties of attributes, such as a user's username.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private String username;

public String getUsername() {
    return this.username;
}

public void setUserData(String username) {
    this.username = username;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;React:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React’s &lt;code&gt;useState&lt;/code&gt; hooks handle application state similarly to how Java uses &lt;code&gt;getter&lt;/code&gt; and &lt;code&gt;setter&lt;/code&gt; methods to manage object properties. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;useState&lt;/code&gt; hook in React allows you to declare state variables that can change over time, much like Java's instance variables in a class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [username, setUsername] = useState("");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;setUserName&lt;/code&gt; serves as the setter method, allowing updates to the username. While &lt;code&gt;useState("")&lt;/code&gt; means &lt;code&gt;username&lt;/code&gt; is initialized as an empty string, the &lt;code&gt;setUserName&lt;/code&gt; updates the value.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below we have a function &lt;code&gt;handleInputChange&lt;/code&gt; that detects a change in a web form to update user info and updates the value of &lt;code&gt;username&lt;/code&gt; to what the user inputs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const handleInputChange = (event) =&amp;gt; { 
    setUserName(event.target.value);
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;You can think of accessing &lt;code&gt;username&lt;/code&gt; as a &lt;code&gt;getter&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whenever you reference &lt;code&gt;username&lt;/code&gt; in a component, you are effectively using a getter to access its value. For example, my webpage could render the username by:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;p&amp;gt;Welcome to our page {username}&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  3. Containers as Java Classes
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Java:&lt;/strong&gt;&lt;br&gt;
In Java, classes group related tasks and data together. They help manage how information flows in your application. &lt;/p&gt;

&lt;p&gt;In this example, the &lt;code&gt;Calculator&lt;/code&gt; class handles calculations and stores the result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Calculator {
    private int result;

    public void calculateSum(int a, int b) {
        result = a + b;
    }

    public int getResult() {
        return result;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;React:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Similarly, in React, containers play a key role by connecting the application's data to the components. They handle things like fetching data from API calls and managing the app's state. &lt;/p&gt;

&lt;p&gt;In this example, the Calculator container manages the state of the input value and the result,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Calculator = () =&amp;gt; {
  // State variables to hold input value and the calculation result
  const [inputValue, setInputValue] = useState(0);
  const [result, setResult] = useState(0);

  // Function to calculate the sum of two numbers
  const calculateSum = (a, b) =&amp;gt; {
    setResult(a + b); // Update result state with sum
  };

  return (
    &amp;lt;div&amp;gt;
      {/* Pass the calculateSum function to the ManualFilter component */}
      &amp;lt;ManualFilter onCalculate={calculateSum} /&amp;gt;
      &amp;lt;h2&amp;gt;Result: {result}&amp;lt;/h2&amp;gt; {/* Display result of the calculation */}
    &amp;lt;/div&amp;gt;
  );
};

export default Calculator;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  4. Components as Java Methods
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Java:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Methods in Java perform specific actions, such as handling user input. These methods can be invoked as needed to facilitate various functionalities in your application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public void handleCheckboxChange(String category) {
    // Logic to handle checkbox change
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;React:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Just like Java methods are small, focused tasks, React Components serve a similar purpose, acting as the fundamental building blocks of your user interface. &lt;/p&gt;

&lt;p&gt;Each component is crafted for a specific functionality and can be reused throughout the application. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;ManualFilter&lt;/code&gt; component below is solely focused on filtering options for users. It presents checkboxes that allow users to select specific categories. &lt;/p&gt;

&lt;p&gt;This component can then be called within a &lt;code&gt;UserForm&lt;/code&gt; container page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ManualFilter = ({ onCategoryChange }) =&amp;gt; {
  const [selectedCategories, setSelectedCategories] = useState([]);

  const handleCheckboxChange = (category) =&amp;gt; {
    setSelectedCategories((prev) =&amp;gt;
      prev.includes(category) ? prev.filter((cat) =&amp;gt; cat !== category) : [...prev, category]
    );
    onCategoryChange(category);
  };

  return (
    &amp;lt;div&amp;gt;
      {/* Render checklist */}
      {['Category1', 'Category2', ...].map((cat) =&amp;gt; (
        &amp;lt;label key={cat}&amp;gt;
          &amp;lt;input
            type="checkbox"
            checked={selectedCategories.includes(cat)}
            onChange={() =&amp;gt; handleCheckboxChange(cat)}
          /&amp;gt;
          {cat}
        &amp;lt;/label&amp;gt;
      ))}
    &amp;lt;/div&amp;gt;
  );
};

export default ManualFilter;

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

&lt;/div&gt;






&lt;h2&gt;
  
  
  5. React’s Return in Components
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Java:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Java, a method might return a value that another part of the program uses to generate output. &lt;/p&gt;

&lt;p&gt;For example, the &lt;code&gt;renderOutput&lt;/code&gt; method returns a string containing the user's goal, which can then be displayed elsewhere in the program.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public String renderOutput() {
    return "User Goal: " + userGoal;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;React:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The return statement in React components is crucial for rendering the user interface. In React, what you return from a component dictates what the user sees on the screen.&lt;/p&gt;

&lt;p&gt;This is similar to how as aforementioned, a method in Java that returns data intended for processing or display in another part of the program. &lt;/p&gt;

&lt;p&gt;In this example, the &lt;code&gt;UserGoal&lt;/code&gt; component returns a paragraph element that displays the user's goal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const UserGoal = ({ goal }) =&amp;gt; {
    return &amp;lt;p&amp;gt;User Goal: {goal}&amp;lt;/p&amp;gt;;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  6. Props as Java Method Parameters
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Java:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can passing arguments to a Java method, where the arguments can affect the state or behavior of the calling object. &lt;/p&gt;

&lt;p&gt;For example, consider a simple Java method that takes a message as a parameter. The message it receives will affect what the console will show.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public void displayMessage(String message) {
    System.out.println(message);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;React:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In React, components can receive props, which are similar to parameters in Java methods. React components use props to determine their content and functionality. &lt;/p&gt;

&lt;p&gt;Props control how components behave and what data they display. &lt;/p&gt;

&lt;p&gt;Let's say we have a parent component called &lt;code&gt;WelcomePage&lt;/code&gt; that will pass a message to the &lt;code&gt;MessageDisplay&lt;/code&gt; child component. &lt;/p&gt;

&lt;p&gt;In other words, imagine a &lt;code&gt;MessageDisplay&lt;/code&gt; as a section on the &lt;code&gt;WelcomePage&lt;/code&gt; landing page where a message shows.&lt;/p&gt;

&lt;p&gt;We can define a message in the parent component and pass it as a prop to the &lt;code&gt;MessageDisplay&lt;/code&gt; component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const WelcomePage = () =&amp;gt; {
    const greetingMessage = "Hello, welcome to my app!"; // Define a message to pass

    return (
        &amp;lt;div&amp;gt;
            &amp;lt;h1&amp;gt;Main Application&amp;lt;/h1&amp;gt;
            {/* Pass the greetingMessage as a prop to MessageDisplay */}
            &amp;lt;MessageDisplay message={greetingMessage} /&amp;gt;
        &amp;lt;/div&amp;gt;
    );
};
export default WelcomePage;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;MessageDisplay&lt;/code&gt; component will receive this prop and render it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const MessageDisplay = ({ message }) =&amp;gt; {
    return &amp;lt;h1&amp;gt;{message}&amp;lt;/h1&amp;gt;;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  7. Callback Functions as Java Methods that Return Values
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Java:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Java, you often have methods within classes that perform specific actions and return values to their caller. For example, you might have a class named &lt;code&gt;Calculator&lt;/code&gt; with a method that calculates the difference between two numbers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public int calculateDifference(int a, int b) {
    return a - b; // This method returns the result of the calculation to the caller
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;^In another class you create an instance of the &lt;code&gt;Calculator&lt;/code&gt; class and call that method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;React:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React follows a similar concept, but it focuses on the relationship between components. &lt;/p&gt;

&lt;p&gt;When you have a parent component that contains child components, callback functions help facilitate communication between them. (Remember: parent is a main container that holds the other components - similar to our earlier example of a parent "landing page" with a sub-component of a message box)&lt;/p&gt;

&lt;p&gt;For instance, let’s say you have a &lt;code&gt;ChildComponent&lt;/code&gt; that needs to send some calculated data back to its parent component.&lt;/p&gt;

&lt;p&gt;Below we pass the &lt;code&gt;handleCalculationResult&lt;/code&gt; function from the parent to the child as a prop. &lt;/p&gt;

&lt;p&gt;This function acts like a callback:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Parent component
const ResultsPage = () =&amp;gt; {
  const [calculationResult, setCalculationResult] = useState(null); // State to store the calculation result

  const handleCalculationResult = (result) =&amp;gt; {
    setCalculationResult(result); // Update state with the result from the child
  };

  return (
    &amp;lt;div&amp;gt;
       &amp;lt;ChildComponent onCalculate={handleCalculationResult} /&amp;gt;
       &amp;lt;h2&amp;gt;Calculation Result: {calculationResult}&amp;lt;/h2&amp;gt;
      )}
    &amp;lt;/div&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;p&gt;You can see below how &lt;code&gt;onCalculate&lt;/code&gt; is a callback function received in the ChildComponent from the parent component. &lt;/p&gt;

&lt;p&gt;When the button in &lt;code&gt;ChildComponent&lt;/code&gt; is clicked, it performs the calculation and uses &lt;code&gt;onCalculate&lt;/code&gt; to send the result back to the parent. This mimics how Java methods return values to their callers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ChildComponent = ({ onCalculate }) =&amp;gt; {
  const handleCalculate = () =&amp;gt; {
    const result = 5 - 3; // Example calculation
    onCalculate(result); // Calls the parent function, sending back the calculated result
  };

  return &amp;lt;button onClick={handleCalculate}&amp;gt;Calculate&amp;lt;/button&amp;gt;; // Button triggers the calculation
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this way, the parent manages the overall application state and behavior while the child focuses on a specific action (in this case, the calculation). &lt;/p&gt;

</description>
      <category>react</category>
      <category>beginners</category>
      <category>learning</category>
      <category>java</category>
    </item>
    <item>
      <title>sql joins: moving in together</title>
      <dc:creator>Ashley D</dc:creator>
      <pubDate>Tue, 01 Oct 2024 06:17:05 +0000</pubDate>
      <link>https://dev.to/ashleyd480/sql-joins-moving-in-together-1ol1</link>
      <guid>https://dev.to/ashleyd480/sql-joins-moving-in-together-1ol1</guid>
      <description>&lt;p&gt;In our coding bootcamp, as we breezed past SQL week, one of the topics that was harder to grasp was that of joins. When I looked at the fifth Venn diagram representation on a Google Image search in an attempt to better to visualize the concept then, it was then that I pictured a couple moving in and how that ties into SQL joins. 💖🏠💕 &lt;/p&gt;

&lt;p&gt;When a couple decides to move in together, the things they bring into their shared space represent how data from two tables (the guy and girl) merge through different types of SQL joins. The "love" they have for certain items (data) determines what ends up in the shared house.&lt;/p&gt;

&lt;p&gt;Let's start off with a visual of these two tables between John and Emily (a hypothetical couple), and what they each love.&lt;/p&gt;

&lt;h2&gt;
  
  
  Main Tables: The Guy and the Girl
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Guy Table (John's Interests)
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Guy&lt;/th&gt;
&lt;th&gt;GuyLove&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;Movies&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;Music&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;Sports&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Girl Table (Emily's Interests)
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Girl&lt;/th&gt;
&lt;th&gt;GirlLove&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Emily&lt;/td&gt;
&lt;td&gt;Movies&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Emily&lt;/td&gt;
&lt;td&gt;Music&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Emily&lt;/td&gt;
&lt;td&gt;Books&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Inner Join: The Love Match&lt;/li&gt;
&lt;li&gt;Left Join: The Bossy Guy&lt;/li&gt;
&lt;li&gt;Right Join: The Bossy Girl&lt;/li&gt;
&lt;li&gt;Full Join: The Cantankerous Couple&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Inner Join: The Love Match
&lt;/h2&gt;

&lt;p&gt;When a couple shares mutual love for the same things, only those items make it into the house. If either doesn't love something, it stays out. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Analogy:&lt;/strong&gt; They both only move in items they both love.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;SQL Code: *&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * 
FROM guy 
INNER JOIN girl 
ON guy.GuyLove = girl.GirlLove;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Result Table:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Guy&lt;/th&gt;
&lt;th&gt;GuyLove&lt;/th&gt;
&lt;th&gt;Girl&lt;/th&gt;
&lt;th&gt;GirlLove&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;Movies&lt;/td&gt;
&lt;td&gt;Emily&lt;/td&gt;
&lt;td&gt;Movies&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;Music&lt;/td&gt;
&lt;td&gt;Emily&lt;/td&gt;
&lt;td&gt;Music&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;br&gt;
An inner join finds the "love match" between the guy and girl, meaning it only brings in records where there’s a common interest between both. In our case, John and Emily both love movies and music, so only those shared loves end up in the house.&lt;/p&gt;


&lt;h2&gt;
  
  
  Left Join: The Bossy Guy
&lt;/h2&gt;

&lt;p&gt;In this case, the guy is bossy. He brings all of his stuff into the house, even if the girl doesn’t love it. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Analogy:&lt;/strong&gt; The guy brings all his stuff when they move in together, regardless of whether the girl loves it or not.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;SQL Code: *&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * 
FROM guy 
LEFT JOIN girl 
ON guy.GuyLove = girl.GirlLove;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Result Table:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Guy&lt;/th&gt;
&lt;th&gt;GuyLove&lt;/th&gt;
&lt;th&gt;Girl&lt;/th&gt;
&lt;th&gt;GirlLove&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;Movies&lt;/td&gt;
&lt;td&gt;Emily&lt;/td&gt;
&lt;td&gt;Movies&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;Music&lt;/td&gt;
&lt;td&gt;Emily&lt;/td&gt;
&lt;td&gt;Music&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;Sports&lt;/td&gt;
&lt;td&gt;NULL&lt;/td&gt;
&lt;td&gt;NULL&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;br&gt;
A left join returns all records from the guy’s table (left table aka first table specified in &lt;code&gt;FROM&lt;/code&gt;), regardless of whether there’s a match in the girl’s table (right table). So, even though John’s love for sports doesn’t match any of Emily’s interests, it still shows up in the final result.&lt;/p&gt;

&lt;p&gt;While John has an interest in "Sports," Emily does not share that interest, so there’s no matching value- hence we see a &lt;code&gt;NULL&lt;/code&gt; for her in that record.&lt;/p&gt;


&lt;h2&gt;
  
  
  Right Join: The Bossy Girl
&lt;/h2&gt;

&lt;p&gt;Here, the roles are reversed. The girl is the bossy one, and she brings all of her stuff into the house regardless of the guy's feelings.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Analogy:&lt;/strong&gt; The girl brings all her stuff into the house, whether or not the guy loves it.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;SQL Code: *&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * 
FROM guy 
RIGHT JOIN girl 
ON guy.GuyLove = girl.GirlLove;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Result Table:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Guy&lt;/th&gt;
&lt;th&gt;GuyLove&lt;/th&gt;
&lt;th&gt;Girl&lt;/th&gt;
&lt;th&gt;GirlLove&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;Movies&lt;/td&gt;
&lt;td&gt;Emily&lt;/td&gt;
&lt;td&gt;Movies&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;Music&lt;/td&gt;
&lt;td&gt;Emily&lt;/td&gt;
&lt;td&gt;Music&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;NULL&lt;/td&gt;
&lt;td&gt;NULL&lt;/td&gt;
&lt;td&gt;Emily&lt;/td&gt;
&lt;td&gt;Books&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;br&gt;
A right join prioritizes the girl’s table, meaning all of her interests get included, even if they don’t match with the guy’s interests. In this case, John and Emily share a love for movies and music so that record shows up in both. &lt;/p&gt;

&lt;p&gt;However, since John does not love shopping, it appears as a new record with &lt;code&gt;NULL&lt;/code&gt; values for John's columns, indicating he has no interest in it.&lt;/p&gt;


&lt;h2&gt;
  
  
  Full Join: The Cantankerous Couple
&lt;/h2&gt;

&lt;p&gt;In this scenario, both the guy and girl are very stubborn and bossy. They each bring everything they love into the house, whether or not the other person loves it. No compromise here!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Analogy:&lt;/strong&gt; They both bring all their stuff into the house, regardless of whether the other loves it or not.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;SQL Code: *&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * 
FROM guy 
FULL OUTER JOIN girl 
ON guy.GuyLove = girl.GirlLove;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Result Table:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Guy&lt;/th&gt;
&lt;th&gt;GuyLove&lt;/th&gt;
&lt;th&gt;Girl&lt;/th&gt;
&lt;th&gt;GirlLove&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;Movies&lt;/td&gt;
&lt;td&gt;Emily&lt;/td&gt;
&lt;td&gt;Movies&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;Music&lt;/td&gt;
&lt;td&gt;Emily&lt;/td&gt;
&lt;td&gt;Music&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;Sports&lt;/td&gt;
&lt;td&gt;NULL&lt;/td&gt;
&lt;td&gt;NULL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;NULL&lt;/td&gt;
&lt;td&gt;NULL&lt;/td&gt;
&lt;td&gt;Emily&lt;/td&gt;
&lt;td&gt;Books&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;br&gt;
In this full join example, we see that John brings in his love for sports, while Emily brings her love for books. The &lt;code&gt;NULL&lt;/code&gt; values in the &lt;code&gt;Girl&lt;/code&gt; and &lt;code&gt;GirlLove&lt;/code&gt; columns indicate that there were no corresponding entries in John’s interests for these loves, and vice versa.&lt;/p&gt;

&lt;p&gt;This full join captures all the items from both tables, showing how both John and Emily fill the house with their loves, whether shared or not.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>learning</category>
      <category>sql</category>
      <category>cheatsheet</category>
    </item>
    <item>
      <title>using slack api to retrieve data</title>
      <dc:creator>Ashley D</dc:creator>
      <pubDate>Thu, 22 Aug 2024 05:51:24 +0000</pubDate>
      <link>https://dev.to/ashleyd480/using-slack-api-to-retrieve-data-33ld</link>
      <guid>https://dev.to/ashleyd480/using-slack-api-to-retrieve-data-33ld</guid>
      <description>&lt;p&gt;&lt;strong&gt;Disclaimer:&lt;/strong&gt; This article provides a high-level overview of interacting with the Slack API from the perspective of a beginner who recently finished her 4-month bootcamp. The insights shared here are based on a mini-project and aim to guide those new to how to work with existing API- in this case Slack API integration. 🧡&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Recently, I overheard two of the mentors in my technical apprenticeship program  conversing about what Slack channels we should join once we transition into a formal technical role, and they mentioned how there is no easy way to export Slack channels you are in to share with others. &lt;/p&gt;

&lt;p&gt;As such, I embarked on a mini-project (&lt;a href="https://github.com/ashleyd480/export-slack-channel-template" rel="noopener noreferrer"&gt;repo&lt;/a&gt;) to build a Spring Boot application that could:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Retrieve both private and public Slack channels that a user is a member of, along with their details. This is super useful for onboarding new team members, giving them a comprehensive view of relevant channels.&lt;/li&gt;
&lt;li&gt;Create a Slack command that new hires can use to quickly join essential public channels. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This project marked my first foray into data retrieval with an existing API, and as a beginner, I initially felt quite overwhelmed by where to start. However, after gaining some high-level insights and a better understanding of how to approach API documentation, I wanted to humbly share my learnings with the community. 🤗&lt;/p&gt;




&lt;h2&gt;
  
  
  Topics I Learned:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Slack API Library in Java&lt;/li&gt;
&lt;li&gt;Token Management&lt;/li&gt;
&lt;li&gt;OAuth Scopes&lt;/li&gt;
&lt;li&gt;Jsoup Library&lt;/li&gt;
&lt;li&gt;limit Parameter&lt;/li&gt;
&lt;li&gt;.build() Builder Pattern&lt;/li&gt;
&lt;li&gt;Leveraging API Documentation&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  1. Slack API Library in Java
&lt;/h3&gt;

&lt;p&gt;The Slack API library for Java is a powerful tool that allows developers to interact with Slack's platform programmatically. This means you can write Java code to perform actions on Slack, such as sending messages, retrieving channel information, managing users, and much more. &lt;/p&gt;

&lt;p&gt;The Slack API library has several methods. In this project, I specifically used the conversations.list method provided by the Slack API. This method is designed to fetch a list of channels within a Slack workspace that a user is a part of. &lt;br&gt;
Here's a simple example of how you can import the Slack API library in Java to list channels:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import com.slack.api.Slack;
import com.slack.api.methods.SlackApiException;
import com.slack.api.methods.request.conversations.ConversationsListRequest;
import com.slack.api.methods.response.conversations.ConversationsListResponse;

import java.io.IOException;

public class SlackChannelLister {
// code here
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Token Management
&lt;/h3&gt;

&lt;p&gt;In the context of APIs, a token is a piece of information used to authenticate and authorize your requests. For Slack, this token allows your application to access and interact with Slack's data and functionalities, such as retrieving channel information.&lt;/p&gt;

&lt;p&gt;To get your Slack API token, follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create a Slack App:&lt;/strong&gt; Go to the Slack API Apps page and click "Create New App."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Install the App:&lt;/strong&gt; Install the app to your workspace to generate a token. This token is what you’ll use to authenticate API requests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Store the Token Securely:&lt;/strong&gt; For security reasons, avoid hardcoding your token directly into your code. Instead, use environment variables to manage sensitive information. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;^ In IntelliJ, you can access that setting from the Run menu and select Edit Configurations.&lt;br&gt;
Then in your Java code, you can use this line of code so that your application can read the environmental variable value at runtime.&lt;br&gt;
&lt;code&gt;String token = System.getenv("SLACK_TOKEN");&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  3. OAuth Scopes
&lt;/h3&gt;

&lt;p&gt;Now that you have your token, it needs the appropriate permissions, or "scopes," attached to it.&lt;/p&gt;

&lt;p&gt;Think of OAuth scopes as the permissions your app requests when it needs to interact with Slack API. These scopes specify exactly what your app is allowed to do within a Slack workspace:&lt;br&gt;
You'll need to specify these scopes in the app configuration:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Navigate to Your App's Settings:&lt;/strong&gt; Go to your app's dashboard on the Slack API website.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Select "OAuth &amp;amp; Permissions":&lt;/strong&gt; Here, you'll see a list of scopes you can add.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add Required Scopes:&lt;/strong&gt; It's a best practice to grant only the necessary permissions required for your app's functionality. As such, include the following scopes:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;channels:read:&lt;/code&gt; Allows your app to read information about public channels that you are in .&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;groups:read:&lt;/code&gt;Allows your app to read information about private channels that are in.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  4. Jsoup Library
&lt;/h3&gt;

&lt;p&gt;Jsoup is a versatile Java library designed for working with real-world HTML.  Using Jsoup ensures that any HTML content retrieved from APIs or user input is sanitized.&lt;br&gt;
In the context of this project, Jsoup was used to clean and parse the "purpose" field of Slack channels. Sometimes, the purpose or topic of a channel may contain HTML tags or entities, and we want to extract just the plain text for display or processing purposes.&lt;/p&gt;

&lt;p&gt;Here's  an example how Jsoup can be utilized to clean HTML content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import org.jsoup.Jsoup;
public class JsoupExample {
String htmlPurpose = "&amp;lt;p&amp;gt;Welcome to the &amp;lt;strong&amp;gt;development&amp;lt;/strong&amp;gt; channel!&amp;lt;/p&amp;gt;";`
    ….     
 // Parsing and cleaning the HTML content
String cleanedText = Jsoup.parse(htmlPurpose).text();

 System.out.println("Cleaned Up Purpose: " + cleanText);
 // Output: Cleaned Up Purpose: Welcome to the development channel!
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Jsoup.parse(htmlPurpose)&lt;/code&gt;: Parses the HTML string into a Jsoup Document object.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.text()&lt;/code&gt;: Extracts the plain text from the parsed HTML, stripping away all HTML tags.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  6. &lt;code&gt;limit&lt;/code&gt; Parameter
&lt;/h3&gt;

&lt;p&gt;When working with APIs that return lists of data, such as channels or messages, it's common to control how much data is retrieved in a single request.  This is because  fetching too much data in a single request can slow down your application and consume unnecessary resources. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;limit&lt;/code&gt; parameter serves this exact purpose by specifying the maximum number of items to return.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ConversationsListRequest request = ConversationsListRequest.builder()
        .limit(200)
        .build();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When dealing with larger datasets, you can also implement pagination by fetching data in chunks. You retrieve a set number of items per request and can request additional pages as needed. &lt;/p&gt;

&lt;p&gt;A &lt;code&gt;cursor&lt;/code&gt; is a  pointer provided by Slack to fetch the next set of results. If there's more data, Slack provides a &lt;code&gt;next_cursor&lt;/code&gt; value. You can use this &lt;code&gt;next_cursor&lt;/code&gt; to make subsequent requests and continue retrieving data until you have processed the entire dataset. This method ensures that you handle large volumes of data efficiently without overwhelming your application or the API, and this also addresses rate limit issues.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. &lt;code&gt;.build()&lt;/code&gt; Builder Pattern
&lt;/h3&gt;

&lt;p&gt;The .build() method is a fundamental part of the Builder Pattern in software design. This pattern provides a flexible and readable way to construct complex objects step by step.&lt;/p&gt;

&lt;p&gt;In the context of Slack API requests, the builder pattern simplifies the creation of request objects, as you can see in the example below. This way we don’t have to write several lines and calling &lt;code&gt;.set&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ConversationsListRequest request = ConversationsListRequest.builder()
        .token(System.getenv("SLACK_TOKEN")) 
        .types(Arrays.asList(ConversationType.PUBLIC_CHANNEL, ConversationType.PRIVATE_CHANNEL))
        .limit(100)
        .build();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ConversationsListRequest.builder()&lt;/code&gt;: Initializes a new builder instance for creating a &lt;code&gt;ConversationsListRequest&lt;/code&gt; object.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;token(...)&lt;/code&gt;: Sets the authentication token for the request.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;types(...)&lt;/code&gt;: Specifies the types of conversations to retrieve (public and private channels in this case).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;limit(...)&lt;/code&gt;: Sets the maximum number of channels to return.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.build()&lt;/code&gt;: Finalizes the construction and returns a fully configured &lt;code&gt;ConversationsListRequest&lt;/code&gt; object ready to be used.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  8. Leveraging API Documentation
&lt;/h3&gt;

&lt;p&gt;API documentation is your comprehensive guide to understanding and effectively using an API. At first I wanted to take a shortcut and just check chatGPT, however that resulted in many rabbit holes of doing things the wrong way.  Making sure you read the API documentation is key, as it offers the most up-to-date user guide, Here are a few highlights I found most helpful from Slack's API &lt;a href="https://api.slack.com/automation/quickstart" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sample Code:&lt;/strong&gt; The documentation provides starter code for interacting with their API endpoints in various languages such as Java, JavaScript, and Python. You can find this code on the sample code tab, which is a handy resource for getting started with your project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Detailed Method Descriptions:&lt;/strong&gt; Understand what each API method does, required parameters, and expected responses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sample Tester:&lt;/strong&gt; The Slack API &lt;a href="https://api.slack.com/methods/conversations.list/test" rel="noopener noreferrer"&gt;tester&lt;/a&gt; helps show how JSON responses from the API are formatted. You can see the exact structure of the data returned. This immediate feedback helps ensure your API requests are properly configured and your token is functioning as expected.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>beginners</category>
      <category>api</category>
      <category>springboot</category>
      <category>learning</category>
    </item>
    <item>
      <title>data structures analogies cheat sheet</title>
      <dc:creator>Ashley D</dc:creator>
      <pubDate>Fri, 09 Aug 2024 22:05:41 +0000</pubDate>
      <link>https://dev.to/ashleyd480/data-structures-analogies-cheat-sheet-591j</link>
      <guid>https://dev.to/ashleyd480/data-structures-analogies-cheat-sheet-591j</guid>
      <description>&lt;p&gt;Data structures are like eating utensils, each serving its purpose. Would you use a fork or a spoon to eat soup? Would you use a cup or a plate to drink a Long Island Iced Tea after a long day of debugging? Here’s a look at various data structures through the lens of familiar objects, focusing on their efficiency for lookup, insertion, and order maintenance.&lt;/p&gt;

&lt;p&gt;*Disclaimer&lt;br&gt;
This list is simply meant to be a high level overview of some of the data structures.&lt;br&gt;
Any images as well are also just high level visual representations as well. &lt;/p&gt;




&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;p&gt;Main Structures&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Arrays: The Shoe Shelf&lt;/li&gt;
&lt;li&gt;Linked List: The Rollercoaster&lt;/li&gt;
&lt;li&gt;Binary Search Tree (BST): The Gossip Chain&lt;/li&gt;
&lt;li&gt;HashMap: The Vending Machine&lt;/li&gt;
&lt;li&gt;HashSet: The Gym Check-In&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Additional Structures&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Queue: The Carnival Line&lt;/li&gt;
&lt;li&gt;Heap (Priority Queue): The Disney Fast-Pass&lt;/li&gt;
&lt;li&gt;Stack: The Pancake Stack&lt;/li&gt;
&lt;/ul&gt;







&lt;h2&gt;
  
  
  Main Structures
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Arrays: The Shoe Shelf
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Analogy:&lt;/strong&gt; Imagine a 5-shoe shelf that only fits 5 pairs of shoes. You can quickly access any shoe by its position. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1sagu8o6nyttjf8oig1r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1sagu8o6nyttjf8oig1r.png" alt="Array Shelf" width="800" height="218"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Order:&lt;/strong&gt; ✅ Yes - ordered when the array is initialized. The elements are in the order they were added.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Look Up:&lt;/strong&gt; 🆗 Time: O(n) (linear) if unsorted; ✅ Time: O(log n) If the array is sorted, you can use binary search for faster look-ups, where you quickly narrow down your search by repeatedly cutting the list in half. This makes finding an item much quicker than checking each one by one.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Insert:&lt;/strong&gt; 🆗 Space: O(n) (linear) - Resizing involves allocating memory for a new array and copying over elements. (We can’t insert to the original array as arrays are immutable in Java.)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fagtgr7htu82ohrerh5nm.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fagtgr7htu82ohrerh5nm.gif" alt="Array" width="300" height="142"&gt;&lt;/a&gt;&lt;br&gt;
Source: CoderMantra&lt;/p&gt;




&lt;h3&gt;
  
  
  Linked List: The Rollercoaster
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Analogy:&lt;/strong&gt; A rollercoaster with a head car pointing to the next car in line. The first car connects to the next car which connects to the next.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqnswqky5dyq74pcvcjc6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqnswqky5dyq74pcvcjc6.png" alt="Linked List Coaster" width="800" height="601"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Order:&lt;/strong&gt; ✅ Yes - ordered in the sequence nodes are added. Each node points to the next one in the list.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Look Up:&lt;/strong&gt; 🆗 Time: O(n) (linear) - You need to traverse all the nodes to find an element.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Insert:&lt;/strong&gt; ✅ Time: O(1) (constant) - It only takes two operations to insert: it requires initializing a new node and adjusting its pointer  ✅ Space: O(1) (constant) - Only one new node is created for insertion.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkjd8dnrq7inp0wtx7acv.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkjd8dnrq7inp0wtx7acv.gif" alt="Linked List" width="375" height="164"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Binary Search Tree (BST): The Gossip Chain
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Analogy:&lt;/strong&gt; The CEO (root node) starts a rumor, which spreads to department heads (child nodes) and then to their team leads (grandchild nodes), continuing until it reaches the interns (leaf nodes).  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy5i1jl1h71p1i4xhm6eh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy5i1jl1h71p1i4xhm6eh.png" alt="Binary Gossip" width="800" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Order:&lt;/strong&gt; ✅ (Binary Search Tree): Yes - ordered. Left child values are less than the parent; right child values are greater. ❌ (Binary tree): not ordered - each node has at most two children but no specific order  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Look Up:&lt;/strong&gt; ✅ Time: O(log n) (better than linear) - In a sorted BST, binary search is efficient because you only need to traverse half the tree. Root would be the middle; and if your number is bigger than the middle, you search the top half &amp;amp; vice versa (you wouldn’t have to search all nodes).  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Insert:&lt;/strong&gt; ✅ Time: O(log n) - Inserting into a BST is quick because you take advantage of the sorted order (as mentioned in the “look up” section above to find the correct spot).  &lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;em&gt;Note:&lt;/em&gt;&lt;/em&gt; For a regular binary tree (unsorted), look-up and insert times are O(n) (linear), as you may need to traverse all nodes.&lt;/p&gt;

&lt;p&gt;There are two ways to traverse a binary tree:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;BFS (Breadth First Search):&lt;/strong&gt; Explore all hallways on the current floor of the library before moving to the next floor (using a queue).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft0hswtb83euwncw08510.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft0hswtb83euwncw08510.png" alt="BFS" width="604" height="598"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;DFS (Depth First Search):&lt;/strong&gt; Explore a maze by going as deep as possible into one path before backtracking and exploring other paths (using a stack).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr3voq8kjo8ya5zqf0v7e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr3voq8kjo8ya5zqf0v7e.png" alt="DFS" width="519" height="432"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  HashMap: The Vending Machine
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Analogy:&lt;/strong&gt; Each slot in a vending machine has a unique code (key) like "A1." You input the code, and the machine retrieves the corresponding snack.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flw1nf7mcz0k84uorcux0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flw1nf7mcz0k84uorcux0.png" alt="Vending Machine" width="800" height="636"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Order:&lt;/strong&gt; ❌ Not ordered - The items are placed in slots based on hash codes, not insertion order. Think of rain falling into buckets.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Look Up:&lt;/strong&gt; ✅ Time: O(1) (constant) - Fast look-up using hash codes with .containsKey() and .hashCode().equals().  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Insert:&lt;/strong&gt; ✅ Time: O(1) (constant) - Adding a new key-value pair is quick, as it goes to the correct slot based on hash code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F44y823t8ms89ufxwvdws.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F44y823t8ms89ufxwvdws.gif" alt="HashMap" width="400" height="171"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  HashSet: The Gym Check-In
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Analogy:&lt;/strong&gt; The gym doesn’t care about the order in which members check in; they simply scan your ID barcode (hash code) to verify membership.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fedaofky4tllh086acyac.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fedaofky4tllh086acyac.png" alt="Gym" width="663" height="607"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;em&gt;Note:&lt;/em&gt;&lt;/em&gt; HashSet uses a HashMap internally, so its performance is similar to that of a HashMap but without the key-value pair structure. It's ideal for storing unique elements.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Order:&lt;/strong&gt; ❌ Not ordered - Elements are not kept in the order they are added.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Look Up:&lt;/strong&gt; ✅ Time: O(1) (constant) - Fast look-up using hash codes with .contains().  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Insert:&lt;/strong&gt; ✅ Time: O(1) (constant) - Adding an element is quick, with insertion based on hash code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6k0pm6u3wbwvvhjb0gro.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6k0pm6u3wbwvvhjb0gro.gif" alt="HashSet" width="376" height="158"&gt;&lt;/a&gt;&lt;/p&gt;







&lt;h2&gt;
  
  
  Additional Structures
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Queue: The Carnival Line
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Analogy:&lt;/strong&gt; In a carnival line, the first person (FIFO) gets on the ride first, and new people join at the end of the line.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnufix2u8ap055kcn8n3a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnufix2u8ap055kcn8n3a.png" alt="Carnival Line" width="608" height="627"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use:&lt;/strong&gt; for in-order processing; when you need to process items in the same order they are added (FIFO- first in first out)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Order:&lt;/strong&gt; ✅ Yes - Ordered. Items are processed in the same order they are added (First In, First Out).  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Look Up:&lt;/strong&gt; Need to traverse - To access any element other than the front, you need to go through the queue. (A queue is similar to a “linked list”, except with queues you add to one end of the list, and remove from the front.)  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Insert:&lt;/strong&gt; ✅ Time: O(1) (constant) - Adding an element to the end is quick.  &lt;/p&gt;




&lt;h3&gt;
  
  
  Heap (Priority Queue): The Disney Fast-Pass
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Analogy:&lt;/strong&gt; The fast-pass line allows people with priority tickets to get on the ride first, regardless of their arrival order.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk9kf89fhpqcqo9zl34yd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk9kf89fhpqcqo9zl34yd.png" alt="Fast Pass" width="800" height="776"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use:&lt;/strong&gt; When you want to reach into a “bucket” and always grab the highest (max heap) or lowest (min heap).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Order:&lt;/strong&gt; ❌ Not ordered - Elements are organized based on priority, not insertion order. For example, when the top element (highest or lowest priority) is removed, the heap reorders itself by moving the last element to the top and adjusting its position to maintain the heap property.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc9b7zy0393iqaaelctk4.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc9b7zy0393iqaaelctk4.gif" alt="Image description" width="500" height="300"&gt;&lt;/a&gt;&lt;br&gt;
Source: Tutorials Point&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Look Up:&lt;/strong&gt; ✅ Time: O(1) (constant) - Accessing the top element (highest or lowest priority) is fast. However, you need to traverse or use heap operations to access elements other than the top element (highest or lowest priority one in max/min heap respectively).  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Insert:&lt;/strong&gt; ✅ Time: O(log n) (better than linear) - Insertion involves adjusting the heap to maintain priority order.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F954phiiosi3wdrh2tutt.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F954phiiosi3wdrh2tutt.gif" alt="Image description" width="400" height="171"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Stack: The Pancake Stack
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Analogy:&lt;/strong&gt; Stacking pancakes one on top of another, you eat the last one added first (LIFO- last in first out).  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6hnm2949rqd0vr4lf7il.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6hnm2949rqd0vr4lf7il.png" alt="Pancake" width="611" height="578"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use:&lt;/strong&gt; for reverse order processing (LIFO); typically used with recursion and function call as code calls itself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Order:&lt;/strong&gt; ✅ Yes - Ordered. Items are added and removed from the top (LIFO).  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Look Up:&lt;/strong&gt; ❌ Need to traverse - To access any element other than the top, you need to go through the stack.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Insert:&lt;/strong&gt; ✅ Time: O(1) (constant) - Adding an element to the top is quick.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuwa5f5roob6cgbbwt0lm.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuwa5f5roob6cgbbwt0lm.gif" alt="Stack" width="640" height="400"&gt;&lt;/a&gt;&lt;br&gt;
Source: Medium (Practicetrackever)&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>algorithms</category>
      <category>codenewbie</category>
      <category>learning</category>
    </item>
    <item>
      <title>big 0 notation: laundry day</title>
      <dc:creator>Ashley D</dc:creator>
      <pubDate>Thu, 18 Jul 2024 05:02:08 +0000</pubDate>
      <link>https://dev.to/ashleyd480/big-0-notation-laundry-day-1422</link>
      <guid>https://dev.to/ashleyd480/big-0-notation-laundry-day-1422</guid>
      <description>&lt;p&gt;After our bootcamp, we were challenged to learn data structures, and I noticed a gap: a lot of online resources dive deep right into the math behind calculating  Big O Notation through data, which can be intimidating for beginners. Instead, I want to make a beginner-friendly approach using something we all can relate to:  laundry day.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/ashleyd480/big-0-notation-laundry-day-1422#the-big-o-graph"&gt;The Big O Graph 📉&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.to/ashleyd480/big-0-notation-laundry-day-1422#what-do-those-lines-mean"&gt;What Do Those Lines Mean? 📊&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://dev.to/ashleyd480/big-0-notation-laundry-day-1422#not-good"&gt;Not Good&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/ashleyd480/big-0-notation-laundry-day-1422#quadratic-time-on2"&gt;Quadratic Time - O(n^2)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/ashleyd480/big-0-notation-laundry-day-1422#linearithmic-time-on-log-n"&gt;Linearithmic Time - O(n-log-n&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.to/ashleyd480/big-0-notation-laundry-day-1422#okay"&gt;Okay&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/ashleyd480/big-0-notation-laundry-day-1422#linear-time-on"&gt;Linear Time - O(n)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.to/ashleyd480/big-0-notation-laundry-day-1422#good"&gt;Good&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/ashleyd480/big-0-notation-laundry-day-1422#logarithmic-time-olog-n"&gt;Logarithmic Time - O(log n)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/ashleyd480/big-0-notation-laundry-day-1422#constant-time-o1"&gt;Constant Time - O(1)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The Big O Graph 📉
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmcgzjoln150ak8s2dae8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmcgzjoln150ak8s2dae8.png" alt="Big O Graph" width="800" height="587"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Image Credit: &lt;a href="https://www.bigocheatsheet.com/" rel="noopener noreferrer"&gt;Big O Cheat Sheet&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here’s the typical Big O graph you see in many articles and videos. Let's break it down real quick:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Algorithm:&lt;/strong&gt; A set of systematic instructions for solving a problem, like directions from your home to the grocery store for chips or the movie theater.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Operations:&lt;/strong&gt; How many steps your algorithm will perform relative to the number of elements.&lt;/li&gt;
&lt;li&gt;The graph's &lt;strong&gt;x-axis&lt;/strong&gt; shows the number of elements to process, and the &lt;strong&gt;y-axis&lt;/strong&gt; shows the number of operations necessary to process each element. 
If time increases too much with more elements, that's not optimal. Imagine customers having to wait longer, or an app crashing because it's taking too long to load something. But if more elements take proportionally less time (i.e. less operations) to process as the data size grows, that's good—it means we're being efficient!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What Do Those Lines Mean? 📊
&lt;/h2&gt;

&lt;p&gt;Let's make this relatable. Imagine it's laundry day.... We've all been there, right? &lt;br&gt;
Below you will see laundry day analogies for the various big 0 notations, in regards to time complexity.&lt;br&gt;
(I’ve also grouped them by okay, good and not good for their efficiency) &lt;/p&gt;
&lt;h3&gt;
  
  
  Not Good 🙁
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Quadratic Time - O(n^2) 😓
&lt;/h4&gt;

&lt;p&gt;Imagine you are done with laundry day. You need to find the sock pairs, however the  socks aren't paired up yet. To do your laundry quadratic style- you need to iterate over all laundry items, making every combination of 'two-item pairs'.  Some of these will be a pair of a shirt and pants, some will be a shirt with one sock, and some will be two socks. Clearly lots of 'pairs' are needless, but this would succeed in finding the perfect pair of socks eventually.&lt;/p&gt;

&lt;p&gt;This is similar to the idea of a nested loop in code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (int i = 0; i &amp;lt; socks.length; i++) {
    for (int j = i + 1; j &amp;lt; socks.length; j++) {
        if (socks[i] == socks [j]) {
            // Found a pair of socks


        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffp3hjiju4ovx1hlljibg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffp3hjiju4ovx1hlljibg.png" alt="Quadratic Drawing" width="800" height="469"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Linearithmic Time - O(n log n) 🪵
&lt;/h4&gt;

&lt;p&gt;This is like “fancy” sorting—dividing or grouping the problem to avoid repeated steps. Imagine you need to organize all your clothes after laundry day. &lt;/p&gt;

&lt;p&gt;First, you separate your clothes into different categories: socks, shirts, pants, etc. This initial division helps reduce the problem size (or how many clothes you have to sort through). Next, within each category, you sort the items by color. For example, for socks, you put all the purple socks together, then the green socks, and so on. Finally, within each color group, you sort by size It avoids touching each clothing repeatedly as we saw in the quadratic example above. &lt;/p&gt;

&lt;p&gt;As you can see in the example below, once the clothes are divided into smaller groups, sorting within each category is much faster.  Since each category has fewer items, you avoid repeatedly handling the entire pile- meaning operations (sorts) to go through the smaller pile. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9odtsp5c3nh6j4fe5ytn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9odtsp5c3nh6j4fe5ytn.png" alt="Sorting Drawing" width="658" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Okay 🤔
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Linear Time - O(n) 🔍
&lt;/h4&gt;

&lt;p&gt;This is like opening each drawer to find your socks. The number of operations it takes grows in proportion to the number of drawers.In this case, one operation is opening each drawer to check inside. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you have 2 drawers, it will take 2 operations. Let's pretend it takes you 5 seconds to open each drawer and look, so that's 10 seconds.&lt;/li&gt;
&lt;li&gt;If you have 10 drawers, it will take you 50 seconds (10*5).&lt;/li&gt;
&lt;li&gt;Now, imagine if you had 10,000 drawers—it would take you 50,000 seconds or roughly 13.9 hours! Would you want to open each of those 10,000 drawers?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In code, this is like a for loop iterating through each element (drawer) to perform an operation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (int i = 0; i &amp;lt; drawers.length; i++) {
    // Check each drawer
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fppq33qtmcrdrpeci33yb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fppq33qtmcrdrpeci33yb.png" alt="Linear Drawing" width="772" height="890"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Good 🌟
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Logarithmic Time - O(log n) 🔍🕵️‍♂️
&lt;/h4&gt;

&lt;p&gt;Imagine you know your drawers are alphabetically sorted by clothing type. When searching for socks, you start in the middle... If you find pants, you realize you've opened too high, so you continue searching in the lower drawers. This means you don’t have to open all the drawers above the pants. &lt;/p&gt;

&lt;p&gt;This method allows you to skip entire sections of drawers with each search, reducing the number of drawers you need to open to find your sock. Thus, it's more efficient and takes less time to locate your item compared to searching through every drawer linearly.&lt;/p&gt;

&lt;p&gt;This is similar to a binary search.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int binarySearch(int[] drawers, int targetSock) {
    int left = 0;
    int right = drawers.length - 1;

    while (left &amp;lt;= right) {
        int mid = left + (right - left) / 2;

        if (drawers[mid] == targetSock) {
            return mid; // Found the target at index mid
        } else if (drawers[mid] &amp;lt; targetSock) {
            left = mid + 1; // Continue searching  right (upper) half
        } else {
            right = mid - 1; // Continue searching left (lower) half
        }
    }

    return -1; // targetSock not found
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F945bl4bmnzgmli3ttwcz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F945bl4bmnzgmli3ttwcz.png" alt="Logarithmic Drawing" width="800" height="768"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Constant Time - O(1) 🚀
&lt;/h4&gt;

&lt;p&gt;This is like having your drawers labeled on the outside so know exactly where your socks are. It doesn’t matter how many drawers you have; you only need one operation where you open one drawer because you  “know” where the socks are so you only have to open one drawer. &lt;/p&gt;

&lt;p&gt;Think of a HashMap where you can quickly find an item by key. The key would be the label on the outside of the drawer (which would say socks), so you know to open up drawer 3. Regardless of how many drawers you have- you know it’s always going to be drawer 3.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HashMap&amp;lt;String, String&amp;gt; drawerMap = new HashMap&amp;lt;&amp;gt;();
drawerMap.put("favoriteSocks", "Drawer 3");
String socks = drawerMap.get("favoriteSocks"); // Instant lookup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqwxjruuhmnu9t9tnnz5v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqwxjruuhmnu9t9tnnz5v.png" alt="Constant Drawing" width="800" height="695"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>algorithms</category>
      <category>coding</category>
      <category>learning</category>
    </item>
    <item>
      <title>how to deploy backend</title>
      <dc:creator>Ashley D</dc:creator>
      <pubDate>Mon, 08 Jul 2024 15:50:19 +0000</pubDate>
      <link>https://dev.to/ashleyd480/how-to-deploy-backend-4b05</link>
      <guid>https://dev.to/ashleyd480/how-to-deploy-backend-4b05</guid>
      <description>&lt;p&gt;After our bootcamp was done, we were instructed to create a portfolio &lt;a href="https://ashley-boost-portfolio.netlify.app/" rel="noopener noreferrer"&gt;website&lt;/a&gt; and given my interests in both frontend (my creative side) and backend (my curiosity for more of the technical engine that drives a site)- I decided to make my site fullstack.  For example, I wanted to host my data tables for my bootcamp scores and feedback and projects on the backend.&lt;/p&gt;

&lt;p&gt;When researching the how-to, I noticed a lack of resources for deploying a fullstack site and specifically for how to deploy the backend. &lt;/p&gt;

&lt;p&gt;I wanted to create a resource to share my learnings on how to deploy the backend with the hope that this can help others. To preface, yes- there can be multiple approaches, but this here is specifically the approach my mentor and I took to deploy the backend.  Please also note- that yes Heroku does require a card (~ $5, $9/ month), so if you want to avoid the billing - you can also just hardcode your backend data on the frontend. :) &lt;/p&gt;

&lt;p&gt;To start off - we used Heroku to deploy and locally- we used Postgres to store the data. It is a very beginner-friendly site compared to some of the other more complex sites like AWS. In the steps below, we will go over:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Account Set Up&lt;/li&gt;
&lt;li&gt;Postgres Set Up&lt;/li&gt;
&lt;li&gt;Migrating Data&lt;/li&gt;
&lt;li&gt;Connecting to Frontend&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Before reading these steps, please note that the terminal commands are specific to Mac. As deployment strategies can vary based on your versions, below are the specific versions of systems I had:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React: 18.2.0&lt;/li&gt;
&lt;li&gt;Spring: 3.3.0&lt;/li&gt;
&lt;li&gt;Postgres: 14.12&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Another optional  thing to note if it makes it easier for you to organize the work, you will want to have a separate repo on Github respectively for both the frontend and backend. &lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Account Set Up
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. To start, you can go to heroku.com to sign up.
&lt;/h3&gt;
&lt;h3&gt;
  
  
  2. Click &lt;code&gt;Create New App&lt;/code&gt; or navigate to:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://dashboard.heroku.com/apps" rel="noopener noreferrer"&gt;https://dashboard.heroku.com/apps&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgog3k9q44tghlk76hdi7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgog3k9q44tghlk76hdi7.png" alt="Create App" width="784" height="572"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Give your app a name.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa88rrhs6gtc1c0cgy09x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa88rrhs6gtc1c0cgy09x.png" alt="Name Your App" width="782" height="228"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  4. From your Dashboard (&lt;a href="https://dashboard.heroku.com/apps" rel="noopener noreferrer"&gt;https://dashboard.heroku.com/apps&lt;/a&gt;), click on the app name.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj07wtyc514v1z2oe81bq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj07wtyc514v1z2oe81bq.png" alt="Click on App" width="771" height="466"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  5. Add a system.properties file to your backend Java project.
&lt;/h3&gt;

&lt;p&gt;Note: please keep the page open from step 4. This step 5 is done on your IDE to ensure proper deployment.&lt;br&gt;
You will add this &lt;code&gt;system.properties&lt;/code&gt; file to the root of your backend Java project directory. In this file, add the following:&lt;br&gt;
Make sure you replace the &lt;code&gt;21&lt;/code&gt; with your actual version number of Java.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;java.runtime.version=21
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This file helps Heroku understand which version of Java to use when running your application. Without it, Heroku might default to a version that is not compatible with your application, leading to potential runtime issues.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Click on deploy and click &lt;code&gt;Connect to Github&lt;/code&gt;.
&lt;/h3&gt;

&lt;p&gt;After connecting your GitHub repository, you'll see options to set up automatic deployments. Choose the GitHub branch you want Heroku to deploy automatically from (usually main or master). Optionally, enable automatic deploys so that every time you push to the chosen branch on GitHub, Heroku will automatically deploy those changes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F76sgd69i9rqz14msjnw9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F76sgd69i9rqz14msjnw9.png" alt="Deploy to Github" width="791" height="606"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are having issues with automatic deployment, you may manually deploy. You will see that option at the bottom of the Deploy page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fii17i7pxq30fwe2co14d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fii17i7pxq30fwe2co14d.png" alt="Manual Deploy" width="763" height="338"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After successful deployment, Heroku assigns a URL to your application. You can find this URL either in the output of the deployment process or by logging into your Heroku account and navigating to your app's dashboard. Make sure you write that URL down in a secure spot, as this will be the updated endpoint for your API calls. &lt;/p&gt;

&lt;p&gt;Once you have obtained the URL (i.e. &lt;code&gt;https://your-app-name.herokuapp.com&lt;/code&gt;), you can use it to make HTTP requests to your backend API endpoints deployed on Heroku. Replace &lt;code&gt;your-app-name&lt;/code&gt; with the actual name of your Heroku app.&lt;/p&gt;

&lt;p&gt;For example, if your backend API endpoint is &lt;code&gt;/api/data&lt;/code&gt;, your complete URL for making requests would be &lt;code&gt;https://your-app-name.herokuapp.com/api/data&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Check the logs to verify the correct Java version is being used.
&lt;/h3&gt;

&lt;p&gt;Logs for both successful and unsuccessful builds are available from your app’s Activity tab in the Heroku Dashboard. You may read more steps for this under Heroku Logs documentation &lt;a href="https://devcenter.heroku.com/articles/logging" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After deploying, you should also double check the Heroku deployment logs to ensure the correct Java version is being used:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to the Heroku dashboard, select your app, and navigate to the "More" dropdown in the top-right corner. Choose "View Logs."&lt;/li&gt;
&lt;li&gt;In the logs, look for lines that mention the Java runtime version. This will help you confirm that the correct version is being used.&lt;/li&gt;
&lt;li&gt;If the version is incorrect, update the &lt;code&gt;system.properties&lt;/code&gt; file with the correct version number and redeploy.&lt;/li&gt;
&lt;/ul&gt;



&lt;h2&gt;
  
  
  Postgres Set Up
&lt;/h2&gt;

&lt;p&gt;Now let’s say you want to connect your existing Postgres database, i.e. say you are using Spring Boot and in the front end, you make the API call to the endpoints to &lt;code&gt;get&lt;/code&gt; your data to display.&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Click on the  dots at top right next to your profile picture, and select &lt;code&gt;Data&lt;/code&gt;.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn4gj123m2v0mv8b2f3m3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn4gj123m2v0mv8b2f3m3.png" alt="Data from Dashboard" width="616" height="293"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Click &lt;code&gt;Create one&lt;/code&gt; under &lt;code&gt;Heroku Postgres&lt;/code&gt; and click on &lt;code&gt;install&lt;/code&gt;.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftijsbkklowa9zyxv0nwl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftijsbkklowa9zyxv0nwl.png" alt="Heroku Postgres" width="689" height="427"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Select the plan so you can host your database on Heroku.
&lt;/h3&gt;

&lt;p&gt;The ones recommended for small-scale projects like a portfolio are &lt;code&gt;Essential 0&lt;/code&gt; ($5/month) or &lt;code&gt;Essential 1&lt;/code&gt; ($9/month). I got the latter. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0wnnesbluo7510mtfu7s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0wnnesbluo7510mtfu7s.png" alt="Heroku Plan" width="732" height="508"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;h2&gt;
  
  
  Migrating Data
&lt;/h2&gt;

&lt;p&gt;Now that the postgres instance is set up, now we can migrate our data from our local postgres to Heroku remote. An analogy is when we push code from local to your remote github repo, except in this case we are “pushing” our data. &lt;/p&gt;
&lt;h3&gt;
  
  
  1. First, you will want to install Docker.
&lt;/h3&gt;

&lt;p&gt;Docker allows you to package an application along with its dependencies and configuration settings into a single, portable unit called a container. This makes it easier to develop and deploy applications. For example, when you use Docker to run PostgreSQL commands like &lt;code&gt;pg_dump&lt;/code&gt; (to back up a database) or &lt;code&gt;pg_restore&lt;/code&gt; (to restore a database), these commands execute within this isolated environment.&lt;/p&gt;

&lt;p&gt;In our case, using Docker resolved a version conflict issue where Heroku server version of Postgres was 16.2 (and you can see that version &lt;a href="https://devcenter.heroku.com/articles/heroku-postgres-version-support#:~:text=Heroku%20deprecates%20these%20versions%20to,version%2016%20as%20the%20default." rel="noopener noreferrer"&gt;here&lt;/a&gt;), but the &lt;code&gt;pg_dump&lt;/code&gt; version was 14.12 &lt;/p&gt;

&lt;p&gt;You may type the command below on your terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew install docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;… or if your terminal is being cranky and doesn’t want to work, then you can go to the Docker &lt;a href="https://www.docker.com/get-started/" rel="noopener noreferrer"&gt;website&lt;/a&gt; and download Docker Desktop for Mac. Once installed, open the “Docker Desktop” application, skip through the various prompts until the docker daemon is running. Then you can close the docker desktop window and proceed to run docker commands in your shell session.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Then, you have to use &lt;code&gt;pg_dump&lt;/code&gt; to create a create a backup file (*.dump) of your database for  migration.  You can run this command within Docker.
&lt;/h3&gt;

&lt;p&gt;Type in your terminal the following: &lt;br&gt;
You may see some abbreviated letters like &lt;code&gt;-h&lt;/code&gt; and &lt;code&gt;-U&lt;/code&gt;, etc. Here’s what they stand for and make sure to replace the word following the abbreviated letter for the following: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;-h&lt;/strong&gt; is the host name, so if you are not locally using &lt;code&gt;localhost&lt;/code&gt;, replace it with your host.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;-U&lt;/strong&gt; is your local postgres username.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;-d&lt;/strong&gt; is the name of your local postgres database.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;-f&lt;/strong&gt;  ashley-portfolio.dump: Specifies the filename (ashley-portfolio.dump) to save the dump.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run postgres:16 pg_dump -Fc --no-acl --no-owner -h localhost -U postgres -d ashley-portfolio-database -f ashley-portfolio.dump

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

&lt;/div&gt;


&lt;p&gt;Notice above we put &lt;code&gt;postgres:16&lt;/code&gt; so that it will match the server version of Heroku. &lt;br&gt;
Note also: If you do not change directories (cd) before running &lt;code&gt;pg_dump&lt;/code&gt;, the dump file will typically be saved in your home directory (~/) or wherever your terminal session is currently located.&lt;/p&gt;

&lt;p&gt;Some more details if you are curious on the how and why behind this: &lt;code&gt;pg_dump&lt;/code&gt; allows you to create a snapshot (backup) of your local PostgreSQL database (ashley-portfolio-database). This backup is crucial for preserving your data before transferring it to Heroku.&lt;/p&gt;

&lt;p&gt;The backup file created by &lt;code&gt;pg_dump&lt;/code&gt; (ashley-portfolio.dump) contains a consistent snapshot of your database, including the SQL commands necessary to remake the table structure. This file can then be transferred and restored into a different PostgreSQL database environment, such as one hosted on Heroku.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Upload your database &lt;code&gt;pg_dump&lt;/code&gt; backup file to Heroku:
&lt;/h3&gt;

&lt;p&gt;Now that you have created a backup of your local PostgreSQL database using &lt;code&gt;pg_dump&lt;/code&gt;, the next step is to migrate this data to your PostgreSQL database hosted on Heroku. &lt;/p&gt;

&lt;p&gt;Use &lt;code&gt;pg_restore&lt;/code&gt; to upload your local database backup (ashley-portfolio.dump) to your Heroku PostgreSQL database:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -e PGPASSWORD=yourHerokuDatabasePassword -v /path/to/your/backup:/my-portfolio-backup postgres:16 pg_restore -h herokuHostName -p 5432 -U yourHerokuUsername -d yourHerokuDatabaseName /my-portfolio-backup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;/path/to/your/backup&lt;/code&gt;, &lt;code&gt;yourHerokuDatabasePassword&lt;/code&gt;, &lt;code&gt;herokuHostName&lt;/code&gt;, &lt;code&gt;5432&lt;/code&gt;, the postgres version:16, &lt;code&gt;yourHerokuUsername&lt;/code&gt;, &lt;code&gt;yourHerokuDatabaseName&lt;/code&gt; with your actual paths and database details.&lt;/p&gt;

&lt;p&gt;You can find this information by clicking the 9 dots at the top right of your Heroku page next to your profile picture. Click on &lt;code&gt;Data&lt;/code&gt;. From there, it will open a page and you will see &lt;code&gt;Datastores&lt;/code&gt;. Click on your datastore. Then you will see another page open, and at the top bar, it will say &lt;code&gt;Overview&lt;/code&gt;, &lt;code&gt;Durability&lt;/code&gt;, &lt;code&gt;Settings&lt;/code&gt;. Make sure you select &lt;code&gt;Settings&lt;/code&gt;. From there, click on &lt;code&gt;View Database Credentials&lt;/code&gt;. Make sure that you don’t write this information down in an insecure environment. &lt;/p&gt;

&lt;p&gt;Here is an explanation of what that Docker command means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;docker run:&lt;/strong&gt; This command starts a new Docker container.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;-e PGPASSWORD=yourHerokuDatabasePassword:&lt;/strong&gt; This sets an environment variable inside the container. Here, PGPASSWORD is being set to your Heroku database password. Environment variables are a way to pass configuration settings to your application.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;-v /path/to/your/backup:/my-portfolio-backup:&lt;/strong&gt; This option links a directory on your host machine (your computer) to a directory inside the container. The part before the colon (/path/to/your/backup) is the path on your host machine where your backup file is stored. The part after the colon (/my-portfolio-backup) is the path inside the container where the backup file will be accessible.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;postgres:16:&lt;/strong&gt; This specifies the Docker image to use, in this case, version 16 of the PostgreSQL image. This ensures compatibility and forces the container to run with PostgreSQL version 16.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;pg_restore:&lt;/strong&gt; This is the command that will run inside the container. It restores a PostgreSQL database from a backup file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;-h herokuHostName:&lt;/strong&gt; This specifies the host name of your Heroku PostgreSQL database.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;-p 5432:&lt;/strong&gt;This specifies the port number to connect to. The default port for PostgreSQL is 5432.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;-U yourHerokuUsername:&lt;/strong&gt; This specifies the username to connect to the PostgreSQL database on Heroku.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;-d yourHerokuDatabaseName:&lt;/strong&gt; This specifies the name of the PostgreSQL database to restore the backup into.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;/my-portfolio-backup:&lt;/strong&gt; This is the path to the backup file inside the container. It should match the directory we mounted earlier.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. The last step is to have the migrated database appear on your local Postgres (this way if you need to view the data, or make updates- you can do so).
&lt;/h3&gt;

&lt;p&gt;Using the aforementioned steps from step 3 on how to view your database Heroku credentials, make sure you keep that page open. &lt;br&gt;
Open Postgres from your desktop. Right click on &lt;code&gt;Servers&lt;/code&gt; in Postgres and then  click &lt;code&gt;Register&lt;/code&gt; and select &lt;code&gt;Server.&lt;/code&gt;&lt;br&gt;
From there, in the popup, select &lt;code&gt;Connections&lt;/code&gt; and type in the info from your Heroku database credentials. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwwfwgxwv4hgamylczvtm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwwfwgxwv4hgamylczvtm.png" alt="Postgres Server" width="782" height="362"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, when you open up Postgres, you should see a server called heroku. When you expand it, you will see &lt;code&gt;databases&lt;/code&gt;. You can search for the one that matches the &lt;code&gt;database&lt;/code&gt; name in your Heroku database credentials. Once you expand the database, click on &lt;code&gt;Schemas&lt;/code&gt; to expand. Then, click on &lt;code&gt;public&lt;/code&gt; to expand and then from there click on &lt;code&gt;Tables&lt;/code&gt; to expand. Now, you can go to each table and run queries. &lt;/p&gt;



 

&lt;h2&gt;
  
  
  Connecting to Frontend
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;To set up the frontend you can deploy your frontend repo on Github on Netlify via these steps found in Netlify documentation.&lt;/li&gt;
&lt;li&gt;You will want to make sure that for any API calls you make on the frontend code, that the API URL is updated from localhost to the new URL (i.e. &lt;code&gt;https://your-app-name.herokuapp.com&lt;/code&gt;) and you may refer Account Setup Step 5 for a refresher on that. :) &lt;/li&gt;
&lt;li&gt;After you finish deploying on Netlify, then you will get a link to your website which you can visit to visually see your fullstack site.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>beginners</category>
      <category>backend</category>
      <category>heroku</category>
      <category>webdev</category>
    </item>
    <item>
      <title>capstone debugging: learnings</title>
      <dc:creator>Ashley D</dc:creator>
      <pubDate>Fri, 07 Jun 2024 21:34:46 +0000</pubDate>
      <link>https://dev.to/ashleyd480/capstone-debugging-learnings-3495</link>
      <guid>https://dev.to/ashleyd480/capstone-debugging-learnings-3495</guid>
      <description>&lt;p&gt;The clock on my monitor silently ticked, while I cried in JSX fragments and Spring beans. It was Week 15 and 16- the final stretch of my coding bootcamp and we were tasked with creating a full-stack app. Time was tight from having to research and execute new concepts, and the bugs- oh someone call pest control! 😅&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fww86p57740jx0jsku28t.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fww86p57740jx0jsku28t.jpg" alt="Cartoon of Emotional Gal" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Though it was tough, I did end up finishing and learned a bunch in the process. My project was a volunteer-driven maps application that allows users to crowdsource accessibility information as well as explore and search accessible places near them. &lt;/p&gt;

&lt;p&gt;While my Github &lt;a href="https://github.com/ashleyd480/access-map-app-capstone"&gt;readme&lt;/a&gt; shares more in-depth details of my learnings, I wanted to also share a behind the scenes view of 4 bugs I faced and how I debugged them:&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Duplicate Data Seeding&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rating Button Not Showing as Checked&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Uncontrolled Component Warning&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Conditional API Calls&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  1. Duplicate Data Seeding
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Issue:&lt;/strong&gt; When seeding data without using a list, duplicate entries were created.&lt;br&gt;
&lt;strong&gt;Solution:&lt;/strong&gt; Created a variable to store the data seeder return and referenced this variable in other functions. This prevented duplication when checked in Postman.&lt;/p&gt;

&lt;p&gt;To ensure the app had places loaded along with user reviews (to simulate a database of Maps places) and feature tags, a data seeding mechanism was used. 🌱. My approach at the beginning was to call the return of the entity seeder class. For example, in my &lt;code&gt;reviewSeeder&lt;/code&gt;, I called &lt;code&gt;userSeeder.seedUsers()&lt;/code&gt;, thinking that would just get me the return value of the initial list of 10 seeded users. Instead, I ended up with duplicates—Postman showed 20 users instead of 10 😬. When checking that list, I noticed that the usernames repeated twice, i.e. &lt;code&gt;user1&lt;/code&gt; appeared twice with &lt;code&gt;id&lt;/code&gt; of 1 and 11. &lt;/p&gt;

&lt;p&gt;After an hours-long trip down a rabbit hole, I realized that &lt;code&gt;userSeeder.seedUsers()&lt;/code&gt; appeared to invoke the seeder function again instead of just returning the initial seeded list. &lt;br&gt;
To fix this, I created a variable to hold the data seeder's return value and referenced this variable in subsequent functions. This change effectively prevented duplication, confirmed by rechecking in Postman.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     public void run(String... args) throws Exception {
            List&amp;lt;User&amp;gt; seededUsers= userSeeder.seedUsers();
            // Seed users first
            List&amp;lt;FeatureTag&amp;gt; seededTags = tagSeeder.seedTags(); // Then, seed tags first
            List&amp;lt;Place&amp;gt; seededPlaces = placeSeeder.seedPlaces(seededTags); // Pass seeded tags to places
            reviewSeeder.seedReviews(seededPlaces, seededUsers); // Pass seeded places and tags to reviews (because reviews can only exist with a place and places have tags)
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Rating Button Not Showing as Checked
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Issue: **The rating button wasn’t properly working or showing as checked upon user selection. &lt;br&gt;
**Solution:&lt;/strong&gt; Used the checked attribute to control the selected radio button based on the component's state, as well as corrected mapping logic.&lt;/p&gt;

&lt;p&gt;When adding a review, users are also prompted to rate the accessibility of the place from 1-5. Getting the rating buttons to display as checked was another challenge ⭐. &lt;/p&gt;

&lt;p&gt;Kudos to my instructor who worked through with me during office hours.&lt;br&gt;
Firstly, we fixed the mapping logic. The way rating radio buttons are generated is to take the array of ratings [1, 2, 3,4,5] and then map through them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{[1, 2, 3, 4, 5].map((value) =&amp;gt; { ... })}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A &lt;code&gt;map&lt;/code&gt; typically takes 2 parameters: the value (current element of the array being processed and the index of the current element in the array. In this case, &lt;code&gt;(value) =&amp;gt; { ... }&lt;/code&gt; is an anonymous function that takes value as its parameter. and it is saying for each rating number, we want to have it be a radio button.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{[1, 2, 3, 4, 5].map((value) =&amp;gt; {

    return ( // return a radio button for each number in the array 
       &amp;lt;Form.Check
             key={value}                  
 type="radio"
             label={value} // set label text for radio button 
             name="rating"
             value={value} // set value attribute to the current value we are mapping over 
             checked={formData.rating === value.toString()}
             onChange={handleChange}
           /&amp;gt;
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, I was able to confirm that yes, the value of the user’s selection was read by using a &lt;code&gt;console.log&lt;/code&gt; and confirming the value was read on click. However, the button still appeared as unchecked, and that can be confusing to the end user.&lt;/p&gt;

&lt;p&gt;We researched and learned that the &lt;code&gt;checked&lt;/code&gt; attribute is what helps  React determine which button to select when the form renders. This meant that there was an issue with how we were defining the statement in &lt;code&gt;checked.&lt;/code&gt; The values in the bracket had to evaluate to true and we were comparing &lt;code&gt;formData.rating&lt;/code&gt; to &lt;code&gt;value&lt;/code&gt; (which was the value of the radio button generated from our mapping). &lt;/p&gt;

&lt;p&gt;We confirmed that this comparison had to evaluate to true as we wrote &lt;code&gt;checked = {false}&lt;/code&gt;; the formData.rating value was read on the console, but the button was not checked - which proves that when the comparison is &lt;code&gt;false&lt;/code&gt;, a check will not appear visually in our UI. &lt;/p&gt;

&lt;p&gt;Therefore, we dug a bit further into how we were getting those values and comparing them.&lt;/p&gt;

&lt;p&gt;formData.rating is set using the &lt;code&gt;handleChange&lt;/code&gt; which sets the rating value when the user clicks on a radio button. (Essentially, the function  looks at &lt;code&gt;event.target.name&lt;/code&gt; aka fields that triggered the change, and gets its value and sets it to form data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const handleChange = (event) =&amp;gt; {
    const { name, value } = event.target; // destructures the event.target with the keys in brackets 
// this way, we can use `name` and `value` variables vs `event.target.name, event.target.value
    setFormData((prevFormData) =&amp;gt; ({
        ...prevFormData, //takes the form data and makes copy of it 
        [name]: value, //gets value for fields that triggered the change and sets it to form data.
    }));
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We ran a &lt;code&gt;console.log&lt;/code&gt; to compare &lt;code&gt;formData.rating&lt;/code&gt; and &lt;code&gt;value.&lt;/code&gt; In the end, we saw the issue was a type mismatch. After researching and seeing a suggested &lt;code&gt;toString&lt;/code&gt; method online, we used that with our own code. &lt;code&gt;formData.rating === value.toString()&lt;/code&gt; generated &lt;code&gt;true&lt;/code&gt; and the check was now appearing on the UI. ✅&lt;/p&gt;

&lt;p&gt;We could also verify this with the &lt;code&gt;console.log&lt;/code&gt;. You can see when the user clicks 2. &lt;br&gt;
Line 88 is &lt;code&gt;formData.rating&lt;/code&gt; and Line 89 is    &lt;code&gt;value.toString()&lt;/code&gt;. You can see 5 lines appear - which is from our mapping of the 5 ratings, and for each it checks to see if the &lt;code&gt;value&lt;/code&gt; we are mapping over from the array is equal to the user’s selection. When it is mapped over 2, that matches what the user selected, so the check appears visually in the UI. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5f40r2orcks30qagqauw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5f40r2orcks30qagqauw.png" alt="Rating Console Log" width="709" height="281"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  3. Uncontrolled Component Warning
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Issue:&lt;/strong&gt; Input fields were locked because they were directly bound to &lt;code&gt;userData&lt;/code&gt;.&lt;br&gt;
&lt;strong&gt;Solution:&lt;/strong&gt; Made a copy of &lt;code&gt;userData&lt;/code&gt; to allow edits and saved changes on submit. This prevented the form from locking while enabling updates.&lt;/p&gt;

&lt;p&gt;When designing the &lt;code&gt;Edit Account&lt;/code&gt; page, I wanted data from &lt;code&gt;My Account&lt;/code&gt; (which was retrieved from a &lt;code&gt;GET&lt;/code&gt; mapping call to also populate on &lt;code&gt;Edit Account&lt;/code&gt;).  I used the &lt;code&gt;UserData&lt;/code&gt; context provider in React to carry over those values. While the information did port over correctly to &lt;code&gt;Edit Account&lt;/code&gt;, the input fields were locked 🔒, preventing edits. &lt;/p&gt;

&lt;p&gt;Shoutout to my mentor who helped me to battle this bug. The console showed an error of “uncontrolled component warning.” We learned this error is when the state of a component is not being controlled by React itself, aka React doesn’t have complete control over the &lt;code&gt;Edit Account&lt;/code&gt; form’s input fields. Yes, React is a control freak. 😉&lt;/p&gt;

&lt;p&gt;Fields were directly bound to &lt;code&gt;userData&lt;/code&gt; (which was set from that aforementioned API call on &lt;code&gt;My Account&lt;/code&gt;). This resulted in the fields being "locked" and preventing any edits. This also means that when I was  trying to edit the input fields, I was essentially trying to edit the original userData. React doesn't allow direct changes to props because they are supposed to be immutable. So, trying to edit the input fields directly would essentially be trying to modify immutable data, which React won't allow.&lt;/p&gt;

&lt;p&gt;Also, when an input field is directly bound to a piece of data- in this case &lt;code&gt;userData&lt;/code&gt;, React cannot fully control the state of that input field. &lt;/p&gt;

&lt;p&gt;We resolved it by creating a copy of &lt;code&gt;userData&lt;/code&gt;, allowing modifications without altering the original until submission.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const [formData, setFormData] = useState({ ...userData });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;formData&lt;/code&gt; is a variable that refers to that copy of &lt;code&gt;userData&lt;/code&gt; (with its key-value pairs of data details), so in our form fields, we can use the dot notation of &lt;code&gt;value={formData.email}&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;This also fixed the uncontrolled component warning, ensuring form fields were populated with the initial &lt;code&gt;userData&lt;/code&gt; values but remained editable. Upon submitting, changes were saved back to the original user data with a &lt;code&gt;PUT&lt;/code&gt; request,  ensuring a smooth and functional user experience.&lt;/p&gt;

&lt;p&gt;Finally, the user is redirected back to &lt;code&gt;My Account&lt;/code&gt; after a successful &lt;code&gt;PUT&lt;/code&gt; call, and that is where &lt;code&gt;GET&lt;/code&gt; mapping happens to retrieve the user info and set it to the &lt;code&gt;userData&lt;/code&gt; context provider- ensuring both the backend and the frontend context providers’ values are updated 💾. &lt;/p&gt;

&lt;h2&gt;
  
  
  4. Conditional API Calls
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Issue:&lt;/strong&gt; Fetch API calls wouldn’t populate with data on the frontend &lt;br&gt;
&lt;strong&gt;Solution:&lt;/strong&gt; Ensured API call was made only if the &lt;code&gt;username&lt;/code&gt; was truthy, triggering the call once the username was available.&lt;/p&gt;

&lt;p&gt;A peculiar issue with populating data from fetch API arose 🚧. The first time I noticed this was when trying to get &lt;code&gt;My Account&lt;/code&gt; details to populate by username. My API call required the &lt;code&gt;username&lt;/code&gt; value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const responseData = await fetchData(`users?username=${username}`);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I started with using local storage to store the username upon a successful sign in, but the API call to get account details would not return anything. I even did a &lt;code&gt;console.log&lt;/code&gt; to ensure the username was being correctly read. The instructor gave a hint on how local storage can be slow to load. Thus, I then tested using a &lt;code&gt;username&lt;/code&gt; context provider to pass the value - thinking this would resolve it. Still, there was no luck in rendering the API call’s return.&lt;/p&gt;

&lt;p&gt;To prove that it was not an issue with the system reading the &lt;code&gt;username&lt;/code&gt; value, I even tried to hardcode a &lt;code&gt;username&lt;/code&gt; value of const username = &lt;code&gt;user1&lt;/code&gt; before the API call, and that worked. Something else was brewing. &lt;/p&gt;

&lt;p&gt;As I initially had an &lt;code&gt;address&lt;/code&gt; entity linking to &lt;code&gt;user&lt;/code&gt;, I tried to change the dot notation format to &lt;code&gt;users.address&lt;/code&gt;, &lt;code&gt;users.&lt;/code&gt; , &lt;code&gt;address&lt;/code&gt;, etc- all to no avail either. I then thought perhaps the &lt;code&gt;address&lt;/code&gt; entity was giving me issues due to how it was set up on Spring Boot with the one-to-one cascade, so I commented it out to see if I could at least get the &lt;code&gt;user&lt;/code&gt; information to populate. It did! &lt;br&gt;
When I uncommented out &lt;code&gt;address&lt;/code&gt;, then the &lt;code&gt;address&lt;/code&gt; would populate. I tested this a few times with mixed results, and noticed I had to wait a bit to uncomment out &lt;code&gt;address&lt;/code&gt; for both the user and address to display. This gave me another hint, that perhaps we had to wait for the user information to populate. &lt;/p&gt;

&lt;p&gt;A few hours later, what I learned is that given that API calls are asynchronous, there was a possibility that the data might not be available at the time of the call. Also, local storage and context providers are asynchronous too. That means JavaScript won't wait for the local storage or context operation to finish before continuing to execute the API calls. &lt;/p&gt;

&lt;p&gt;That  means that when we attempted to fetch "My Account" details based on the &lt;code&gt;username&lt;/code&gt;, there was no guarantee that the username would be available immediately. It could take some time for the local storage to be accessed and the username to be retrieved. &lt;/p&gt;

&lt;p&gt;By implementing a conditional API call that triggered only if the username was truthy, I ensured the address field was populated correctly. This method checked if the username was available before making the API call, allowing the address data to load appropriately. This method highlighted the importance of conditional logic in ensuring seamless data fetching and rendering in the UI 🎉&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(() =&amp;gt; {
  if (username) {
    fetchUserData(username);
  }
}, [username]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>learning</category>
      <category>bootcamp</category>
      <category>fullstack</category>
    </item>
    <item>
      <title>spring JPA entities: cheat sheet</title>
      <dc:creator>Ashley D</dc:creator>
      <pubDate>Sun, 28 Apr 2024 20:58:11 +0000</pubDate>
      <link>https://dev.to/ashleyd480/spring-jpa-entities-cheat-sheet-bbe</link>
      <guid>https://dev.to/ashleyd480/spring-jpa-entities-cheat-sheet-bbe</guid>
      <description>&lt;p&gt;Week 10 of coding bootcamp was marked by lots of junk food, a sleepless Sunday night from drinking my coffee too late, and oh yeah learning about Spring JPA entities. Learning them felt like mental gymnastics for me. Now that my brain has shakily landed from its endless flips and rumination, I wanted to share my basic understanding of the how behind each. 😅&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcue98d923cll2btmhgrm.jpg" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcue98d923cll2btmhgrm.jpg" alt="Flipping For Code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;🌸 &lt;a href="https://dev.to/ashleyd480/spring-jpa-entities-cheat-sheet-bbe#one-to-many"&gt;One to Many&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🌷 &lt;a href="https://dev.to/ashleyd480/spring-jpa-entities-cheat-sheet-bbe#one-to-one"&gt;One to One&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🌼 &lt;a href="https://dev.to/ashleyd480/spring-jpa-entities-cheat-sheet-bbe#many-to-many"&gt;Many to Many&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;a id="One To Many"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  One to Many
&lt;/h2&gt;

&lt;p&gt;Below we have two entities from the basic backend framework of an ecommerce’s app’s backend. A customer has a one to many relationship with orders.  In other words, a customer can buy multiple orders.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F54625k3a3stxilcz8tru.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F54625k3a3stxilcz8tru.png" alt="One to Many Code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Order&lt;/th&gt;
&lt;th&gt;Customer&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;@ManyToOne&lt;/code&gt; annotation above &lt;code&gt;private Customer customer&lt;/code&gt; indicates many &lt;code&gt;Order&lt;/code&gt; instances can belong to one &lt;code&gt;Customer&lt;/code&gt; instance.&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;@OneToMany&lt;/code&gt; annotation above &lt;code&gt;private List&amp;lt;Order&amp;gt;  orders&lt;/code&gt; means that one &lt;code&gt;Customer&lt;/code&gt; instance can have multiple &lt;code&gt;Order&lt;/code&gt; instances.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;@JoinColumn&lt;/code&gt; indicates the foreign key of &lt;code&gt;customer_id&lt;/code&gt; references the one in Customer table. &lt;code&gt;nullable=false&lt;/code&gt; means that each order must have a customer instance (when being created/updated), or in other words belong to a customer.&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;mappedBy= "customer"&lt;/code&gt; (written above &lt;code&gt;List&amp;lt;Order&amp;gt; orders&lt;/code&gt;) means that the list of orders is mapped to each customer via the &lt;code&gt;Customer customer&lt;/code&gt; field on the Orders table (aka… the Orders table owns the relationship).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hibernate then fetches the associated &lt;code&gt;Customer&lt;/code&gt; instance based on that foreign key. This is how the order(s) are associated with the respective customer.&lt;/td&gt;
&lt;td&gt;Remember how in the Order table, Hibernate gets the &lt;code&gt;Customer&lt;/code&gt; instance via the foreign key and that is how it’s associated with those orders?&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;*Note:  Even though we don’t see a list of orders or the  customer object - we can access that relationship programmatically via JPA, as discussed above.&lt;/p&gt;

&lt;p&gt;Here are how the Order and Customer Table look respectively on Postgres.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmmemtdnk9e7tnu6bs7ra.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmmemtdnk9e7tnu6bs7ra.png" alt="One to Many Tables"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  @JsonIgnore
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;@JsonIgnore&lt;/code&gt; is to prevent “looping” (aka circular dependency)  when we display the data. For example, when we made a request to get orders tied to a customer, without JSON, it would show the order, then the customer, which then shows the customer field info and then calls the order field which then calls the customer, ad infinitum. &lt;/p&gt;

&lt;p&gt;With &lt;code&gt;@JsonIgnore&lt;/code&gt;- only the Order information would show when making that &lt;code&gt;get&lt;/code&gt; request. &lt;br&gt;
When deciding where to place &lt;code&gt;@JsonIgnore&lt;/code&gt;- you can think of it as we don’t need to show the customer when querying orders, but it would be more helpful to show the orders when querying a customer. An alternative way of approaching that thought process is: we put &lt;code&gt;@JsonIgnore&lt;/code&gt; over the &lt;code&gt;customer&lt;/code&gt; field, because a customer can exist without orders but not vice versa. &lt;/p&gt;

&lt;h3&gt;
  
  
  Owning Table
&lt;/h3&gt;

&lt;p&gt;Orders is the owning table, which means any changes to the relationship,  such as adding or removing orders for a customer, should be made through the customer field in the Order entity.)  The owning side is also where the relationship is persisted in the database; that is the owning side is the one that owns the foreign key in the relationship.  &lt;/p&gt;

&lt;p&gt;We chose orders as the owning side, because of operational logic. You typically create orders and associate with customers, not the other way around. &lt;/p&gt;

&lt;p&gt;The example code block shows how we add an order to a customer. &lt;code&gt;order&lt;/code&gt; represents the new order we are adding (sent via the request body in the API call &lt;code&gt;@PostMapping("/customers/{id}/orders")&lt;/code&gt;). &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

 public Customer addOrderToCustomer(Integer id, Order order) throws Exception {
        Customer customer = customerRepository.findById(id).orElseThrow(() -&amp;gt; new Exception("Customer not found"));
        order.setCustomer(customer);
        orderRepository.save(order);
        return customer;
    }


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

&lt;/div&gt;

&lt;p&gt;Notice how the updates in the code are done via the order’s side.  The customer that has made the order is set to the customer field in the Order entity. This &lt;code&gt;Order&lt;/code&gt; instance that now has the respective customer tied to it is then saved (persisted) to the &lt;code&gt;Order&lt;/code&gt; database. &lt;/p&gt;

&lt;h3&gt;
  
  
  Bidirectional
&lt;/h3&gt;

&lt;p&gt;As a side note, as cascade persist is not used above, you can set the order on the customer side as well to allow for bidirectional navigation. Cascade persist means that operations on say a customer entity would persist to the associated order entities (i.e. if you deleted a customer, then the associated customer would aso delete) …however, in our case- as we are primarily accessing orders from the orders side (i.e. we typically retrieve orders and associate them with customers), then we don’t need that bidirectional code added. &lt;/p&gt;

&lt;h4&gt;
  
  
  Note:
&lt;/h4&gt;

&lt;p&gt;Keep in mind, for unidirectional one-to-many relationships, in most cases- you have to set both entities "to each other", in other words for example set a team to a player, and player to a team. On the other hand, many-to-many relationships are bidirectional and that means if you set a post to have a tag, you don't need to set the post to the tag- since JPA handles that on the backend (made possible by the associations between both entities via the join table). &lt;/p&gt;




&lt;p&gt;&lt;a id="One To One"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  One to One
&lt;/h2&gt;

&lt;p&gt;Below we see how each record in our Address entity is associated with one record in the Customer entity., and vice versa. That is, in our hypothetical scenario: each customer can have one address, and one address can belong to one customer. &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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj9yapk7pm6l38l0wdzct.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj9yapk7pm6l38l0wdzct.png" alt="One to One Code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All the annotations are handled on the Customer entity side: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@OneToOne&lt;/code&gt; annotation in our Customer entity above &lt;code&gt;private Address address&lt;/code&gt; means that one customer instance has one address&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;CascadeType.ALL&lt;/code&gt; in our Customer entity means that for any actions taken on a &lt;code&gt;Customer&lt;/code&gt; instance, should also be applied to the &lt;code&gt;Address&lt;/code&gt;. For example, if a customer is deleted, then its respective address will also be deleted. Likewise, if a customer is created, then it will be expected to have an address added. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@JoinColumn&lt;/code&gt; annotation indicates the &lt;code&gt;address_id&lt;/code&gt; is the foreign key. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;nullable=false&lt;/code&gt; means the &lt;code&gt;address_id&lt;/code&gt; can’t be null, or in other words each customer needs to have an address associated with it. When creating or updating a user, it must have an address.
-&lt;code&gt;unique=true&lt;/code&gt; means that for each customer, they must have a unique address. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This screenshot below shows the Customer table in Postgres, and you can see the foreign key address_id as the first column- essentially allowing this table to “link” to the Address table. &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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9krj46g0x81xqc4gz133.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9krj46g0x81xqc4gz133.png" alt="One to One Table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a id="Many to Many"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Many to Many
&lt;/h2&gt;

&lt;p&gt;Below we see a relationship where one order can have multiple products (i.e. TV, sofa, etc), and one product can have many orders. In other words, orders and products have a many to many relationship. &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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhoowjqdd9lsxgav65ahs.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhoowjqdd9lsxgav65ahs.png" alt="Many to Many Code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Order&lt;/th&gt;
&lt;th&gt;Product&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;@ManyToMany&lt;/code&gt; above &lt;code&gt;List&amp;lt;Product&amp;gt;&lt;/code&gt; means one order can have multiple products.&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;@ManyToMany&lt;/code&gt; above &lt;code&gt;List&amp;lt;Order&amp;gt;&lt;/code&gt; means one product can have multiple orders.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;@JoinTable&lt;/code&gt;is on the Order side. We query most from Orders and when we query, it allows the related products to properly display.&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;@JsonIgnore&lt;/code&gt; is placed over &lt;code&gt;List&amp;lt;Order&amp;gt;&lt;/code&gt; to prevent that circular reference data loop. Also, we don't need a product result to show affiliated orders, whereas we want to show orders with their affiliated products.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;inverseJoinColumn&lt;/code&gt; means the foreign key of &lt;code&gt;product_id&lt;/code&gt; references the one in the Product table (opposite side table). Hibernate then fetches the associated &lt;code&gt;Product&lt;/code&gt; instance based on that foreign key. This is how the orders(s) are associated with the respective products.&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;mappedBy = “products”&lt;/code&gt; means Orders is the owning side; you create Orders and associate products to orders. The list of orders is mapped to products via the Order table (through its join table). Remember how in the Order table, Hibernate gets the &lt;code&gt;Product&lt;/code&gt; instance via the foreign key and that is how it’s associated with those orders?&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;*This below screenshot shows the Join Table that is actually created in Postgres from that &lt;code&gt;@JoinTable&lt;/code&gt; annotation. &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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnenvhngr614558yunidg.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnenvhngr614558yunidg.png" alt="Many to Many Diagram Table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Side note: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On the Order table: &lt;code&gt;=new ArrayList&amp;lt;&amp;gt;&lt;/code&gt; initializes the list of products with an empty array list, so that as products are added to an order, that array list is updated. This ensures that the &lt;code&gt;products&lt;/code&gt; field is not null even if no products are associated with that order at initialization time. &lt;/li&gt;
&lt;li&gt;On the Product table: &lt;code&gt;=new ArrayList&amp;lt;&amp;gt;&lt;/code&gt; initializes the list of orders with an empty array list, so that as new orders are made with that product, then those orders can be added in. This ensures that the &lt;code&gt;orders&lt;/code&gt; field is not null even if no orders are associated with that product at initialization time. &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>springboot</category>
      <category>jpa</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
