<?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>Forem: Sadisha Nimsara</title>
    <description>The latest articles on Forem by Sadisha Nimsara (@nsadisha).</description>
    <link>https://forem.com/nsadisha</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%2F467782%2F08ce6e2b-c852-4f62-bb5c-ad543d655187.png</url>
      <title>Forem: Sadisha Nimsara</title>
      <link>https://forem.com/nsadisha</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/nsadisha"/>
    <language>en</language>
    <item>
      <title>SOLID Principles</title>
      <dc:creator>Sadisha Nimsara</dc:creator>
      <pubDate>Sun, 20 Oct 2024 16:02:43 +0000</pubDate>
      <link>https://forem.com/nsadisha/solid-principles-4j92</link>
      <guid>https://forem.com/nsadisha/solid-principles-4j92</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff7ycj6f4xp7qpznmmwdv.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%2Ff7ycj6f4xp7qpznmmwdv.png" alt="Cover image for SOLID Principles" width="800" height="565"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SOLID&lt;/strong&gt; is a collection of fundamental principles designed to enhance the manageability and scalability of code in Object-Oriented Programming (OOP). It consists of five key principles:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;S&lt;/strong&gt; ingle Responsibility Principle — SRP&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;O&lt;/strong&gt; pen-Closed Principle — OCP&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;L&lt;/strong&gt; iskov’s Substitution Principle — LSP&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;I&lt;/strong&gt; nterface Segregation Principle — ISP&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;D&lt;/strong&gt; ependency Inversion Principle — DIP&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These principles were introduced by &lt;strong&gt;Robert C. Martin&lt;/strong&gt; (also known as Uncle Bob) in the early 2000s and have since become widely adopted in the software development community. By following SOLID principles, developers can create code that is easier to understand, modify, and extend, leading to more robust and maintainable software systems.&lt;/p&gt;

&lt;h3&gt;
  
  
  Single Responsibility Principle (SRP)
&lt;/h3&gt;

&lt;p&gt;Single Responsibility Principle is the first and most fundamental principle in OOP and SOLID. As the name sounds, this principle means “One class should have only one specific responsibility to take care of”.&lt;/p&gt;

&lt;p&gt;Suppose we have a class called Invoice , which contains 2 methods generateInvoice() and saveToFiles() .&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 Invoice {
  private Long InvoiceNo;

  public void generateInvoice() {
    // code to generate Invoice.
  }

  public void saveToFiles() {
    // code to save invoice as a file.
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This is not a good practice because the Invoice class has two responsibilities. A better approach would be to separate these functionalities into dedicated classes.&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 Invoice {
  private Long InvoiceNo;

  public void generateInvoice() {
    // code to generate Invoice.
  }
}

public class FileManager {
  public void saveToFiles(Invoice invoice) {
    // code to save invoice as a file.
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here, we can see we have 2 classes for the use case:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generating the invoice&lt;/li&gt;
&lt;li&gt;Save it to files&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Benefits of following SRP
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Improved Code Organization&lt;/strong&gt; : By separating concerns into different classes, the codebase becomes more organized and easier to navigate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Better Maintainability&lt;/strong&gt; : When a class has a single responsibility, it is easier to understand its purpose and make changes without unintended side effects.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Increased Reusability&lt;/strong&gt; : Classes with a single responsibility are more likely to be reusable in different parts of the application or even in other projects.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Easier Testing&lt;/strong&gt; : Classes with a single responsibility are typically smaller and more focused, making them easier to test in isolation.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Open-Closed Principle (OCP)
&lt;/h3&gt;

&lt;p&gt;Open-Closed principle is another core principle in SOLID. This principle was introduced by &lt;strong&gt;Bertrand Meyer&lt;/strong&gt; in 1997. The idea behind this principle is “Software artifacts (classes, modules, and functions) should open for extensions, but closed for modifications.”&lt;/p&gt;

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

&lt;p&gt;Let’s say, we have a class called Shape , we can use this class to calculate the area of the shape.&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 Shape {
    private String shapeType;
    private double radius;
    private double length;
    private double width;

    public Shape(String shapeType, double radius, double length, double width) {
        this.shapeType = shapeType;
        this.radius = radius;
        this.length = length;
        this.width = width;
    }

    public double area() {
        if (shapeType.equals("circle")) {
            return Math.PI * (radius * radius);
        } else if (shapeType.equals("rectangle")) {
            return length * width;
        } else {
            throw new IllegalArgumentException("Unknown shape type");
        }
    }
}

// Usage
public class Main {
    public static void main(String[] args) {
        Shape circle = new Shape("circle", 5, 0, 0);
        Shape rectangle = new Shape("rectangle", 0, 4, 6);

        System.out.println(circle.area());
        System.out.println(rectangle.area());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In the code above, adding a new shape requires modifying the existing Shape class, which is not considered a good practice.&lt;/p&gt;

&lt;p&gt;Below is a code example that demonstrates how to apply the Open-Closed Principle to this scenario.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface Shape {
  public double area();
}

class Circle implements Shape {
    private double radius;

    public Circle(double radius) {
        this.radius = radius;
    }

    @Override
    public double area() {
        return Math.PI * (radius * radius);
    }
}

class Rectangle implements Shape {
    private double length;
    private double width;

    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }

    @Override
    public double area() {
        return length * width;
    }
}

// Usage
public class Main {
    public static void main(String[] args) {
        Shape circle = new Circle(5);
        Shape rectangle = new Rectangle(4, 6);

        System.out.println(circle.area());
        System.out.println(rectangle.area());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;With the application of OCP, we can add many shapes as we want without modifying the current implementation.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;NOTE: Using interfaces is not the only way to achieve OCP.&lt;/em&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Benefits of following OCP
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reduced Risk of Bugs&lt;/strong&gt; : By not modifying existing code, the risk of introducing new bugs or breaking existing functionality is minimized.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improved Maintainability&lt;/strong&gt; : Code that follows the OCP is easier to maintain and extend, as new features can be added without altering the existing codebase.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enhanced Flexibility&lt;/strong&gt; : The use of abstractions and polymorphism allows for more flexible and adaptable designs, making it easier to accommodate changing requirements.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Liskov’s Substitution Principle (LSP)
&lt;/h3&gt;

&lt;p&gt;Liskov’s Substitution Principle is another important principle in OOP. It was introduced by &lt;strong&gt;Barbara Liskov&lt;/strong&gt; in 1987 during a conference talk on data abstraction.&lt;/p&gt;

&lt;p&gt;The principle states, “Objects of a superclass should be replaceable with objects of its subclasses without altering the correctness of the program”.&lt;/p&gt;

&lt;p&gt;For example, if Circle and Rectangle are sub types of Shape, then we should be able to replace Shape object with a Circle or Rectangle object without any issues.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface Shape {
  public double area();
}

class Circle implements Shape {
    private double radius;

    public Circle(double radius) {
        this.radius = radius;
    }

    @Override
    public double area() {
        return Math.PI * (radius * radius);
    }
}

class Rectangle implements Shape {
    private double length;
    private double width;

    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }

    @Override
    public double area() {
        return length * width;
    }
}

public class Main {
    public static void main(String[] args) {
        Shape circle = new Circle(5); // Replace Shape object with Circle
        Shape rectangle = new Rectangle(4, 6); // Replace Shape object with Rectangle

        System.out.println(circle.area());
        System.out.println(rectangle.area());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;As demonstrated in this example, adhering to the Liskov Substitution Principle means we should be able to substitute a superclass instance with a subclass instance seamlessly.&lt;/p&gt;
&lt;h4&gt;
  
  
  Benefits of following LSP
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Improved Code Reusability&lt;/strong&gt; : By ensuring that subtypes can be substituted for their base types, code that uses the base type can also work with any of its subtypes, promoting code reuse.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enhanced Maintainability&lt;/strong&gt; : Code that follows LSP is easier to maintain because it reduces the risk of introducing bugs when modifying or extending the codebase.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Better Testability&lt;/strong&gt; : LSP makes it easier to write unit tests for classes and their subtypes, as the tests can be written against the base type and should work for all subtypes.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Interface Segregation Principle (ISP)
&lt;/h3&gt;

&lt;p&gt;The Interface Segregation Principle is one of the five SOLID principles introduced by &lt;strong&gt;Robert C. Martin&lt;/strong&gt;. It states: “Clients should not be forced to depend on interfaces they do not use”.&lt;/p&gt;

&lt;p&gt;In other words, Using many task specific interfaces is better than using one general purpose interface.&lt;/p&gt;

&lt;p&gt;Below example shows the usage of general purpose interface.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface MultifunctionPrinter {
    void printDocument(Document document);
    void scanDocument(Document document);
    void faxDocument(Document document);
}

public class BasicPrinter implements MultifunctionPrinter {
    @Override
    public void printDocument(Document document) {
        System.out.println("Printing: " + document.name());
    }

    @Override
    public void scanDocument(Document document) {
        throw new UnsupportedOperationException("Scanning not supported.");
    }

    @Override
    public void faxDocument(Document document) {
        throw new UnsupportedOperationException("Faxing not supported.");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Using a general-purpose interface like MultifunctionPrinter forces us to implement unnecessary methods, which is considered bad practice. Let’s explore how we can apply the Interface Segregation Principle to this scenario.&lt;/p&gt;
&lt;h4&gt;
  
  
  Interfaces
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface Printer {
    void printDocument(Document document);
}

public interface Scanner {
    void scanDocument(Document document);
}

public interface Fax {
    void faxDocument(Document document);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Implementations
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class BasicPrinter implements Printer {
    @Override
    public void printDocument(Document document) {
        System.out.println("Printing: " + document.name());
    }
}

public class AdvancedPrinter implements Printer, Scanner {
    @Override
    public void printDocument(Document document) {
        System.out.println("Printing: " + document.name());
    }

    @Override
    public void scanDocument(Document document) {
        System.out.println("Scanning: " + document.name());
    }
}

public class FaxMachine implements Fax {
    @Override
    public void faxDocument(Document document) {
        System.out.println("Faxing: " + document.name());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;By applying the &lt;strong&gt;ISP&lt;/strong&gt; , we split it into smaller, role-specific interfaces — like Printer, Scanner, and Fax. This allows each class (e.g. BasicPrinter, AdvancedPrinter, or FaxMachine) to implement only the relevant functionality, promoting modularity and reducing unnecessary dependencies.&lt;/p&gt;
&lt;h4&gt;
  
  
  Benefits of following ISP
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Modular and Reusable Code&lt;/strong&gt; : By breaking down large interfaces into smaller, more specific ones, the code becomes more modular and reusable. Classes or modules can implement only the interfaces they need, reducing unnecessary dependencies and making it easier to reuse code across different parts of the system.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reduced Code Complexity&lt;/strong&gt; : When classes or modules depend only on the interfaces they need, the code becomes less complex and easier to understand. This is because developers do not have to deal with unnecessary methods or dependencies. These are not relevant to their specific use case.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improved Maintainability&lt;/strong&gt; : With smaller and more focused interfaces, it becomes easier to maintain the code. Changes to one interface are less likely to affect other parts of the system, reducing the risk of introducing bugs or breaking existing functionality.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Better Testability&lt;/strong&gt; : Smaller and more focused interfaces make it easier to write unit tests for individual components. This is because the tests can focus on specific behaviors without being affected by irrelevant methods or dependencies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Increased Flexibility&lt;/strong&gt; : By adhering to the ISP, the system becomes more flexible and easier to extend or modify. New features or requirements can be added by creating new interfaces or modifying existing ones without affecting the entire system.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Dependency Inversion Principle (DIP)
&lt;/h3&gt;

&lt;p&gt;Dependency Inversion Principle is the final principle of SOLID. Which was also introduced by &lt;strong&gt;Robert C. Martin&lt;/strong&gt;. This promotes loosely-coupled code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DIP&lt;/strong&gt; states few points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;High-level modules should not depend on low-level modules.&lt;/li&gt;
&lt;li&gt;Both should depend on abstraction.&lt;/li&gt;
&lt;li&gt;Abstraction should not depend on details.&lt;/li&gt;
&lt;li&gt;Details should depend on abstraction.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In simple terms, instead of a class directly depending on other specific classes (concrete implementations), it should depend on &lt;strong&gt;interfaces or abstract classes&lt;/strong&gt;. This makes the code more flexible and easier to maintain, as you can swap out implementations without changing the dependent class.&lt;/p&gt;
&lt;h4&gt;
  
  
  Tightly coupled code (without DIP)
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Keyboard {
    public void type() {
        System.out.println("Typing...");
    }
}

public class Computer {
    private Keyboard keyboard;

    public Computer() {
        this.keyboard = new Keyboard(); // Direct dependency
    }

    public void use() {
        keyboard.type();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;As shown in the example above, the Computer class directly depends on the Keyboard class.&lt;/p&gt;
&lt;h4&gt;
  
  
  Loosely coupled code (with DIP)
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface InputDevice {
    void type();
}

pubic class Keyboard implements InputDevice {
    @Override
    public void type() {
        System.out.println("Typing...");
    }
}

public class Computer {
    private InputDevice inputDevice;

    public Computer(InputDevice inputDevice) {
        this.inputDevice = inputDevice; // Depends on abstraction
    }

    public void use() {
        inputDevice.type();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now, Computer depends on the InputDevice interface, not a specific Keyboard. This makes it easy to switch to another input device, like a WirelessKeyboard, without modifying the Computer class.&lt;/p&gt;
&lt;h4&gt;
  
  
  Benefits of following DIP
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Loose Coupling&lt;/strong&gt; : By depending on abstractions rather than concrete implementations, the code becomes less tightly coupled, making it easier to change one part of the system without affecting others.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improved Maintainability&lt;/strong&gt; : Changes in low-level modules do not impact high-level modules, making the system easier to maintain and extend.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enhanced Testability&lt;/strong&gt; : High-level modules can be tested using mock implementations of the low-level modules, making testing faster and more reliable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Increased Reusability&lt;/strong&gt; : High-level modules can be reused in different contexts without needing to change the low-level modules they depend on.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;In conclusion, the SOLID principles: Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion provide essential guidelines for writing clean, maintainable, and scalable code in object-oriented programming.&lt;/p&gt;

&lt;p&gt;By adhering to these principles, developers can create systems that are easier to understand, modify, and extend, ultimately leading to higher quality software and more efficient development processes.&lt;/p&gt;
&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Thank you for reading this article! I hope you now have a solid understanding of the SOLID principles and how you can apply them to enhance your projects.&lt;/p&gt;

&lt;p&gt;Follow me on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;LinkedIn — &lt;a href="https://www.linkedin.com/in/nsadisha/" rel="noopener noreferrer"&gt;@nsadisha&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;GitHub — &lt;a href="https://github.com/nsadisha" rel="noopener noreferrer"&gt;@nsadisha&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Medium — &lt;a href="https://nsadisha.medium.com" rel="noopener noreferrer"&gt;@nsadisha&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Dev.to — &lt;a href="https://dev.to/nsadisha"&gt;@nsadisha&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;— Sadisha Nimsara&lt;/p&gt;

</description>
      <category>solid</category>
      <category>solidprinciplesinjav</category>
      <category>oop</category>
      <category>java</category>
    </item>
    <item>
      <title>OOP Simplified!</title>
      <dc:creator>Sadisha Nimsara</dc:creator>
      <pubDate>Thu, 04 Apr 2024 05:12:17 +0000</pubDate>
      <link>https://forem.com/nsadisha/oop-simplified-1bp6</link>
      <guid>https://forem.com/nsadisha/oop-simplified-1bp6</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F0%2AGRvpvC2nXPFe7Q6-.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%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F0%2AGRvpvC2nXPFe7Q6-.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;In this article, you will learn and &lt;strong&gt;understand&lt;/strong&gt; Object-Oriented Programming (OOP) principles, which are essential for every software engineer and developer. I emphasize “understand” here because, many individuals, especially beginners, acquire knowledge of OOP principles from various sources without grasping how to apply them in programming. Therefore, I hope that this article will assist them in understanding OOP principles thoroughly.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pre-requisites
&lt;/h3&gt;

&lt;p&gt;This article explains OOP concepts using &lt;strong&gt;Java&lt;/strong&gt;. To fully benefit from this content, I recommend that you possess a foundational understanding of programming fundamentals, including syntax, data types, variables, functions, and packages.&lt;/p&gt;

&lt;p&gt;Enjoy your learning journey!&lt;/p&gt;

&lt;h3&gt;
  
  
  Why OOP?
&lt;/h3&gt;

&lt;p&gt;OOP simplifies programs by translating real-world concepts into programming. It involves mapping real-world objects to objects within the program, making programs more manageable and comprehensible.&lt;/p&gt;

&lt;h3&gt;
  
  
  Classes &amp;amp; Objects
&lt;/h3&gt;

&lt;p&gt;Understanding this concept is crucial. If you’ve seen Java code previously, you’ve likely noticed the keyword class. We can view a class as a blueprint for a real-world object. A class contains properties and behaviours. In OOP, we call them instance variables and methods.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For instance, just like a building plan (blueprint) contains the entire structure of a building, in OOP terms, we can consider the blueprint as the class and the building as an object. It’s important to note that multiple buildings can be constructed using the same plan (blueprint).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To create an object from a class, we call the constructor. A class can have multiple constructors. In cases where the developer doesn’t specify one, a default constructor will be used. To create an object, we invoke the constructor using the new keyword, followed by the class name and parentheses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// defauled constructor&lt;/span&gt;
&lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// user defined constructor&lt;/span&gt;
&lt;span class="c1"&gt;// accepts name as a parameter&lt;/span&gt;
&lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="n"&gt;user2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Sadisha Nimsara"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Interface
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Interfaces&lt;/strong&gt; in programming define the &lt;strong&gt;structure of a class&lt;/strong&gt; , much like how a class serves as a blueprint for an object. &lt;strong&gt;Interfaces contain public static final variables and abstract methods&lt;/strong&gt;. (An abstract method is a method that does not have a body.)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// all variables must be declared as public, static, and final&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// this is also public, static, and final by default.&lt;/span&gt;
  &lt;span class="c1"&gt;// only in newer java version&lt;/span&gt;
  &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;_type&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// interface method (does not have a body)&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setType&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  OOP Concepts
&lt;/h3&gt;

&lt;p&gt;There are four OOP principles. These principles form the foundation of object-oriented design and programming principles.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Inheritance&lt;/li&gt;
&lt;li&gt;Abstraction&lt;/li&gt;
&lt;li&gt;Encapsulation&lt;/li&gt;
&lt;li&gt;Polymorphism&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s discuss them one by one.&lt;/p&gt;

&lt;h4&gt;
  
  
  Inheritance
&lt;/h4&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%2Fcdn-images-1.medium.com%2Fmax%2F561%2F0%2AD7hPwt037rE9P_Hb.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%2Fcdn-images-1.medium.com%2Fmax%2F561%2F0%2AD7hPwt037rE9P_Hb.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inheritance refers to establishing connections between classes.&lt;/p&gt;

&lt;h4&gt;
  
  
  Extend or Implement?
&lt;/h4&gt;

&lt;p&gt;In Java, we utilize the keywords extends and implements to accomplish inheritance. Inheritance can take various forms, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inherit class from another class — use extends&lt;/li&gt;
&lt;li&gt;Inherit class from an interface — use implements&lt;/li&gt;
&lt;li&gt;Inherit interface from another interface — use extends&lt;/li&gt;
&lt;/ul&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%2Fcdn-images-1.medium.com%2Fmax%2F543%2F0%2ANzSNXuKySywEB_kV.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%2Fcdn-images-1.medium.com%2Fmax%2F543%2F0%2ANzSNXuKySywEB_kV.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This process of inheritance establishes a relationship between a &lt;strong&gt;Parent&lt;/strong&gt; class (superclass) and a &lt;strong&gt;Child&lt;/strong&gt; class (subclass). Put simply, the parent class provides inheritance, while the child class receives it.&lt;/p&gt;

&lt;p&gt;The way we can achieve properties and methods from parent class is using the super keyword. If you want to call the constructor of the super class, you may call super(); .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="nf"&gt;calculateSalary&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// calculate the salary&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Employee&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Enployee&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// calls the constructor of the super class&lt;/span&gt;
    &lt;span class="kd"&gt;super&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// get a property value from super class&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;super&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="nf"&gt;getSalary&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// calling a method from super class&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;super&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;calculateSalary&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see in this example, User class has one property called name and one method called calculateSalary(). Employee class is extended from the User class. So it gets inheritance from User class. Thats why we can access nameand calculateSalary() methods within the Employee class by calling super.name and super.calculateSalary() .&lt;/p&gt;

&lt;p&gt;If you’re curious about how data is accessible to child classes, we can manage the access of inherited properties and methods using &lt;strong&gt;Access Modifiers&lt;/strong&gt;. This concept is known as &lt;strong&gt;Encapsulation&lt;/strong&gt; , and we’ll delve into it later in this article.&lt;/p&gt;

&lt;h4&gt;
  
  
  Inheritance Types
&lt;/h4&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%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AizXGHvvqFLk6GzuZ53dVLA.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%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AizXGHvvqFLk6GzuZ53dVLA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are multiple inheritance types as you can see in this picture. But, Java &lt;strong&gt;does not support Multiple inheritance&lt;/strong&gt; for classes by default. However, we can use interfaces to achieve multiple inheritance in java.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;A&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; 
  &lt;span class="cm"&gt;/* some methods */&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;B&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="cm"&gt;/* some methods */&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;C&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="no"&gt;A&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="no"&gt;B&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="cm"&gt;/* overriden methods from A and B */&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see in the above example, Class C inherits all the properties and behaviours in Interface A and Interface B .&lt;/p&gt;

&lt;h4&gt;
  
  
  Abstraction
&lt;/h4&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%2Fcdn-images-1.medium.com%2Fmax%2F816%2F1%2A9ltTi5e1G4c3FPbssgD-BQ.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%2Fcdn-images-1.medium.com%2Fmax%2F816%2F1%2A9ltTi5e1G4c3FPbssgD-BQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Abstraction stands as a fundamental principle in Object-Oriented Programming. It defines a model to create an application component. The implementation of abstraction depends on the language-specific features and processes.&lt;/p&gt;

&lt;p&gt;In a nutshell, This means hiding the implementation and providing the functionality.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For instance, when you start your car, you simply insert the key and turn it or press the start button. The complex internal workings involved in starting the car are abstracted from you, where the implementation remains hidden, and only the functionality is visible.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are two ways to achieve abstraction in java:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Abstract classes(0 to 100% abstraction)&lt;/li&gt;
&lt;li&gt;Interfaces (100% abstraction)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Abstract classes
&lt;/h4&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%2Fcdn-images-1.medium.com%2Fmax%2F640%2F0%2Az3vglqogXjTO_tsp.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%2Fcdn-images-1.medium.com%2Fmax%2F640%2F0%2Az3vglqogXjTO_tsp.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An abstract class is defined with the abstract keyword and can include data properties like a regular class. Additionally, it can contain both abstract and non-abstract methods. We cannot instantiate an object directly from an abstract class; instead, it must be extended by a child class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;abstract&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;salaryRate&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// regular method&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// abstract method&lt;/span&gt;
  &lt;span class="c1"&gt;// does not have a method body&lt;/span&gt;
  &lt;span class="c1"&gt;// must be overridn by a child class&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;abstract&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;calculateSalary&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Employee&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

  &lt;span class="nd"&gt;@Override&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;calculateSalary&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// calculate the salary&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// not allowed (error)&lt;/span&gt;

    &lt;span class="nc"&gt;Employee&lt;/span&gt; &lt;span class="n"&gt;employee1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Employee&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// allowed&lt;/span&gt;

    &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="n"&gt;employee2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Employee&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// allowed&lt;/span&gt;

  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Interfaces
&lt;/h4&gt;

&lt;p&gt;An interface is an example of an abstract class that achieves 100% abstraction. But, if we use interfaces, data properties are common for all the clid classes. Because, interfaces have &lt;strong&gt;public static and final&lt;/strong&gt; variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;accelerate&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;stop&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

  &lt;span class="nd"&gt;@Override&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// start a car&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;

  &lt;span class="nd"&gt;@Override&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;accelerate&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// accelerate a car&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;

  &lt;span class="nd"&gt;@Override&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;stop&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// stop a car&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="n"&gt;vehicle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// not allowed (error)&lt;/span&gt;

    &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="n"&gt;car1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// allowed&lt;/span&gt;

    &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="n"&gt;car2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// allowed&lt;/span&gt;

  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  When to use Abstract classes and when to user Interfaces
&lt;/h4&gt;

&lt;p&gt;Suppose A is an interface, and B and C are A’s subclasses.&lt;/p&gt;

&lt;p&gt;If B and C share the same properties with identical values, it’s preferable to use interfaces.&lt;/p&gt;

&lt;p&gt;However, if B and C have the same properties but different values for them, abstract classes would be a better choice.&lt;/p&gt;

&lt;h4&gt;
  
  
  Encapsulation
&lt;/h4&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%2Fcdn-images-1.medium.com%2Fmax%2F1000%2F0%2AY7yL2d_yBdS0IuQc.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%2Fcdn-images-1.medium.com%2Fmax%2F1000%2F0%2AY7yL2d_yBdS0IuQc.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Encapsulation involves restricting access to data and methods within classes. Classes consist of variables and methods. We can manage how other classes access these variables and methods. This concept is known as encapsulation.&lt;/p&gt;

&lt;p&gt;There are four access modifiers used to restrict access within a class:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Default (No keyword): Limits access to classes within the same package.&lt;/li&gt;
&lt;li&gt;Private: Limits access to the class itself.&lt;/li&gt;
&lt;li&gt;Protected: Limits access to the same class and its subclasses.&lt;/li&gt;
&lt;li&gt;Public: Removes all access restrictions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is a misconception about this: “Encapsulation increases security.” However, that is not the case. &lt;strong&gt;Encapsulation is not directly related to security&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Default (No keyword)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="nc"&gt;Date&lt;/span&gt; &lt;span class="n"&gt;birthday&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

  &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;calculateAge&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="cm"&gt;/*calculates the age from birthday*/&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All the variables and methods can be accessed within the package.&lt;/p&gt;

&lt;h4&gt;
  
  
  Private
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt; &lt;span class="n"&gt;birthday&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

  &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;calculateAge&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="cm"&gt;/*calculates the age from birthday*/&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, all variables can be accessed within the class. However, the calculateAge() method can only be accessed within the package.&lt;/p&gt;

&lt;h4&gt;
  
  
  Protected
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt; &lt;span class="n"&gt;birthday&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

  &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;calculateAge&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="cm"&gt;/*calculates the age from birthday*/&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Employee&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

  &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;super&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The property name can be accessed within the User class since it is a protected field. Consequently, child classes will also have access to protected properties.&lt;/p&gt;

&lt;h4&gt;
  
  
  Public
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the name field is private to the User class, meaning it cannot be accessed from outside the class. However, the getName() method is public, allowing it to be used from anywhere.&lt;/p&gt;

&lt;h4&gt;
  
  
  Abstraction vs Encapsulation
&lt;/h4&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%2Fcdn-images-1.medium.com%2Fmax%2F784%2F0%2Asd8pwRozW1iRbkeO.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%2Fcdn-images-1.medium.com%2Fmax%2F784%2F0%2Asd8pwRozW1iRbkeO.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Polymorphism
&lt;/h4&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%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F0%2AqbWX-_w8WuSYpr0H.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%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F0%2AqbWX-_w8WuSYpr0H.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Polymorphism stands out as a cornerstone concept in Object-Oriented Programming (OOP), highlighting the capacity of an entity to manifest or exist in multiple forms. These diverse manifestations emerge as entities that can assume varied meanings and serve different purposes across various contexts.&lt;/p&gt;

&lt;p&gt;The word polymorphism was also constructed using 2 words.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Poly — Means multiple&lt;/li&gt;
&lt;li&gt;Morphism — Behaviours&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, Cat, Dog, Cow are Animals. Here, we can take the Animal as the parent class and Cat, Dog, Cow as the child classes of Animal. All animals make sounds. But, differently. That is the concept of polymorphism.&lt;/p&gt;

&lt;p&gt;In programming, mainly there are 2 types of polymorphism.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Runtime polymorphism&lt;/li&gt;
&lt;li&gt;Compile-time polymorphism&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Runtime polymorphism
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Method overriding&lt;/strong&gt; enables the attainment of runtime polymorphism. In Java, the Java Virtual Machine (JVM) identifies the correct method to invoke during runtime, not during compilation. This mechanism is also referred to as dynamic or late binding.&lt;/p&gt;

&lt;p&gt;A behaviour of parent is replaced by the same behaviour of child.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// abstract method without a body&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Cat&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="nd"&gt;@Override&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// how cat speaks&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Meow"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="nd"&gt;@Override&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// how dog speaks&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Woof"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In runtime polymorphism, only the method body will change. It does not change the method signature.&lt;/p&gt;

&lt;h4&gt;
  
  
  Compile-time polymorphism
&lt;/h4&gt;

&lt;p&gt;Compile-time polymorphism is achieved by &lt;strong&gt;Method overloading&lt;/strong&gt;. When an object is associated with its functionality during compilation, it is termed compile-time polymorphism. During compilation, Java determines which method to invoke based on method signatures, leading to compile-time polymorphism, also known as static or early binding.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Calculator&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, you can observe that the Calculator class contains two distinct add() methods. It’s important to note that we cannot have the same method repeated within the same class. However, these methods are differentiated by their method signatures, making them distinct despite sharing the same name.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;public &lt;strong&gt;int&lt;/strong&gt; add( &lt;strong&gt;int&lt;/strong&gt; a, &lt;strong&gt;int&lt;/strong&gt;  b)&lt;/li&gt;
&lt;li&gt;public &lt;strong&gt;double&lt;/strong&gt; add( &lt;strong&gt;double&lt;/strong&gt; a, &lt;strong&gt;double&lt;/strong&gt;  b)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The first method accepts two &lt;strong&gt;integers&lt;/strong&gt; as parameters and returns an &lt;strong&gt;integer&lt;/strong&gt; , while the second method accepts two &lt;strong&gt;doubles&lt;/strong&gt; as parameters and returns a &lt;strong&gt;double&lt;/strong&gt;. During compile time, we can call either of these methods. The compiler determines which method to invoke based on the arguments provided when invoking these methods.&lt;/p&gt;

&lt;h4&gt;
  
  
  Compile Time vs Runtime polymorphism
&lt;/h4&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%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2ARcp1RrwUj5xGVpnsc1GADA.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%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2ARcp1RrwUj5xGVpnsc1GADA.png"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Source: GeeksForGeeks&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I hope this article has provided you with a simplified and comprehensive understanding of Object-Oriented Programming (OOP) concepts. Thank you for taking the time to read this article. May your journey in software development be filled with creativity and success!&lt;/p&gt;

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

</description>
      <category>java</category>
      <category>objectoriented</category>
      <category>oopprinciples</category>
      <category>oop</category>
    </item>
    <item>
      <title>Android MVVM data binding with ViewModel</title>
      <dc:creator>Sadisha Nimsara</dc:creator>
      <pubDate>Fri, 04 Nov 2022 06:45:48 +0000</pubDate>
      <link>https://forem.com/nsadisha/android-mvvm-data-binding-with-viewmodel-1bad</link>
      <guid>https://forem.com/nsadisha/android-mvvm-data-binding-with-viewmodel-1bad</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2A49B96zWRdA1mQbSiMkOkYA.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%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2A49B96zWRdA1mQbSiMkOkYA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hello everyone, this article is about how you can implement android MVVM architecture to your android application. I thought to right this article because I was having many troubles when I first using the android MVVM pattern. So, I wanted other people not to face same problems again.&lt;/p&gt;

&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;MVVM is an architectural design pattern, which helps us to accomplish separation of concerns. Also it is used to build reusable and testable native android applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is MVVM?
&lt;/h3&gt;

&lt;p&gt;MVVM stands for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Model&lt;/strong&gt;  — This holds the data of the application. It cannot directly talk to the View. Generally, it’s recommended to expose the data to the ViewModel through Observables.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;View&lt;/strong&gt;  — Simply this is the user interface of the application. Does not contain any application logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;View Model&lt;/strong&gt;  — It acts as a link between the Model and the View. It’s responsible for transforming the data from the Model. It provides data streams to the View. It also uses hooks or callbacks to update the View. It’ll ask for the data from the Model.&lt;/li&gt;
&lt;/ul&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%2Fcdn-images-1.medium.com%2Fmax%2F606%2F1%2A4qKsbWZYPRRUGOssAIw36A.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%2Fcdn-images-1.medium.com%2Fmax%2F606%2F1%2A4qKsbWZYPRRUGOssAIw36A.png"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;MVVM&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There are 3 possible ways to bind data with a view model in android. Those are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Two way data binding&lt;/li&gt;
&lt;li&gt;Binding using LiveData&lt;/li&gt;
&lt;li&gt;Binding using RxJava&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this article, we are going to learn binding using LiveData. We will be using Kotlin as the PL. Let’s begin.&lt;/p&gt;
&lt;h3&gt;
  
  
  Project structure
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F576%2F1%2AM8tP0SbIMHVpAHECU6tqhA.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%2Fcdn-images-1.medium.com%2Fmax%2F576%2F1%2AM8tP0SbIMHVpAHECU6tqhA.png"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Project structure&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Add libraries and dependencies
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Enable data binding and view binding libraries
&lt;/h4&gt;

&lt;p&gt;In order to do this, you need to open the build.gradle file and enable those as this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;android {
    buildFeatures {
        viewBinding true
        dataBinding true
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Add dependencies
&lt;/h4&gt;

&lt;p&gt;Add these dependencies in the build.gradle file under dependencies section.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here you have successfully completed the first step. Let’s create our model.&lt;/p&gt;
&lt;h3&gt;
  
  
  Create data model
&lt;/h3&gt;

&lt;p&gt;To store the data within the application run time, we are using a model. So let’s create a model called Counter as below.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h3&gt;
  
  
  Create View Model
&lt;/h3&gt;

&lt;p&gt;Create a view model as below.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h4&gt;
  
  
  important
&lt;/h4&gt;

&lt;p&gt;Remember that we cannot directly use _data.value.increment() method, because it does not update the value in MutableLiveData object. So we assign _data.value with _data.value.apply {this?.increament()} to awoid live data updating issues.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating the view
&lt;/h3&gt;

&lt;p&gt;Let’s create a simple view with a TextView and a Button.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h4&gt;
  
  
  Important
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;You need to remember that you need to have  tag inside the  tag. Otherwise it does not work.&lt;/li&gt;
&lt;li&gt;To bind a value, we use “@{viewModel.data}” format.&lt;/li&gt;
&lt;li&gt;We use android:onClick=”@{() -&amp;gt; viewModel.increase()}” format to bind events.&lt;/li&gt;
&lt;li&gt;Remember to use the same name in the  tag.&lt;/li&gt;
&lt;li&gt;Use android:text=”@{viewModel.data.toString()}” format. not android:text=”@={viewModel.data.toString()}”.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Associated kotlin file:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h4&gt;
  
  
  Important
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Here, we are getting the view model from the ViewModelProvider, because there will be having a single instance of the view model until we destroy the view.&lt;/li&gt;
&lt;li&gt;In line number 26, we initialise the binding variable from the DataBindingUtil class.&lt;/li&gt;
&lt;li&gt;We have to set the binding.viewModel to our view model (Line: 29). So that we can use the view model in xml file.&lt;/li&gt;
&lt;li&gt;One important thing most of the people forget to do is setting the lifecycleOwner (Line: 32). Without this, your data will update in the view model. But, your UI will not be updated.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thank you for reading this article. If you find something valuable in this article please give it a clap and leave your thoughts. Don’t forget to share.&lt;/p&gt;

&lt;p&gt;To be continued!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Start building your carrier as a web developer</title>
      <dc:creator>Sadisha Nimsara</dc:creator>
      <pubDate>Tue, 18 Oct 2022 19:13:58 +0000</pubDate>
      <link>https://forem.com/nsadisha/start-building-your-carrier-as-a-web-developer-2m88</link>
      <guid>https://forem.com/nsadisha/start-building-your-carrier-as-a-web-developer-2m88</guid>
      <description>&lt;p&gt;Hello guys, I am Sadisha Nimsara(nsadisha). This article is for beginners who interested in web development. Most of the people, even students in universities are familiar with web development. But most of them have no idea how they can start it as their carrier. So, in this article we are going to learn “What are the things you need to learn to become a expert in web development.”&lt;/p&gt;

&lt;h1&gt;
  
  
  Path ways
&lt;/h1&gt;

&lt;p&gt;In this path, you can be either “Front-end”, “Back-end”, or a “Full-stack” Developer.&lt;/p&gt;

&lt;h1&gt;
  
  
  Front-end developer
&lt;/h1&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%2Fmx3g6ed35afpfi6gu3jl.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmx3g6ed35afpfi6gu3jl.jpeg" alt="front-end development" width="800" height="476"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Front-end developer is a person who develop websites and web applications. Simply, the development of the client-side(how a web page will look like) is developed by a front-end developer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Three basic technologies
&lt;/h3&gt;

&lt;p&gt;Most basic elements in a web page.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/html/default.asp" rel="noopener noreferrer"&gt;HTML&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/css/default.asp" rel="noopener noreferrer"&gt;CSS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/js/default.asp" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Popular CSS and JavaScript frameworks
&lt;/h3&gt;

&lt;p&gt;These things will make the development process easier for you.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://getbootstrap.com" rel="noopener noreferrer"&gt;Bootstrap&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/whatis/whatis_w3css.asp" rel="noopener noreferrer"&gt;W3.CSS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/whatis/whatis_htmldom.asp" rel="noopener noreferrer"&gt;HTML DOM&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/js/js_json.asp" rel="noopener noreferrer"&gt;JSON&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/whatis/whatis_xml.asp" rel="noopener noreferrer"&gt;XML&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jquery.com" rel="noopener noreferrer"&gt;jQuery&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://vuejs.org" rel="noopener noreferrer"&gt;Vue&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://angular.io" rel="noopener noreferrer"&gt;Angular&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://reactjs.org" rel="noopener noreferrer"&gt;React&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Handling APIs
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://restfulapi.net" rel="noopener noreferrer"&gt;REST&lt;/a&gt; — Representative State Transfer&lt;/li&gt;
&lt;li&gt;&lt;a href="https://graphql.org" rel="noopener noreferrer"&gt;GraphQL&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  API data formats
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.w3schools.com/js/js_json.asp" rel="noopener noreferrer"&gt;JSON &lt;/a&gt;— JavaScript Object Notation&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.w3schools.com/xml/default.asp" rel="noopener noreferrer"&gt;XML&lt;/a&gt; — eXtensible Markup Language&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Version controlling
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/git/" rel="noopener noreferrer"&gt;Git&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can start by learning the above mentioned technologies. And also do some projects your own. It will help you a lot to understand how these things work together, what error can be occurred, and many more.&lt;/p&gt;

&lt;h1&gt;
  
  
  Back-end developer
&lt;/h1&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%2Fc6lu0o6yb7pcw5w9ph36.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%2Fc6lu0o6yb7pcw5w9ph36.png" alt="backend development" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Back-end developer is responsible for how the website/applications will work. All business logics and database related things are handled by him.&lt;/p&gt;

&lt;h3&gt;
  
  
  Languages
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/php/default.asp" rel="noopener noreferrer"&gt;PHP&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/java/default.asp" rel="noopener noreferrer"&gt;Java&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/js/default.asp" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/python/default.asp" rel="noopener noreferrer"&gt;Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/go/index.php" rel="noopener noreferrer"&gt;Go&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Ruby&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Frameworks
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://spring.io/projects/spring-boot" rel="noopener noreferrer"&gt;Springboot(Java)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://expressjs.com" rel="noopener noreferrer"&gt;ExpressJs(JavaScript)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://laravel.com" rel="noopener noreferrer"&gt;Laravel(PHP)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.djangoproject.com" rel="noopener noreferrer"&gt;Django(Python)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Database management
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.mongodb.com" rel="noopener noreferrer"&gt;MongoDB&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SQL/relational databases (MySQL, Oracle, PostgreSQL)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://firebase.google.com" rel="noopener noreferrer"&gt;Firebase&lt;/a&gt; — Complete platform for backend&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Web servers
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://httpd.apache.org" rel="noopener noreferrer"&gt;Apache&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.nginx.com" rel="noopener noreferrer"&gt;NGINIX&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Other tools
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.postman.com" rel="noopener noreferrer"&gt;Postman&lt;/a&gt; — used for testing API endpoints&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Full-stack developer
&lt;/h1&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%2F52dyuebvta8o57ptrnp2.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%2F52dyuebvta8o57ptrnp2.png" alt="full-stack development" width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Full-stack developer is a combination of both front-end and back-end developers. He is responsible for developing user interfaces, business logic, database integration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;** Mastering JavaScript will be a bigger advantage for a web developer regardless of his roll. **&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/xORdz1Hi9Gc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If you wish to learn more about back-end development, follow the following topics:&lt;/p&gt;

&lt;h3&gt;
  
  
  Caching
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;CDN (Cloud Delivery Network)&lt;/li&gt;
&lt;li&gt;Server-side caching&lt;/li&gt;
&lt;li&gt;Client-side cashing&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Web Security
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Hashing Algorithms
&lt;/li&gt;
&lt;li&gt;MD5
&lt;/li&gt;
&lt;li&gt;SHA Family
&lt;/li&gt;
&lt;li&gt;Scrypt
&lt;/li&gt;
&lt;li&gt;Bcrypt&lt;/li&gt;
&lt;li&gt;HTTPS&lt;/li&gt;
&lt;li&gt;CORS&lt;/li&gt;
&lt;li&gt;SSL/TLS&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Testing
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Unit testing&lt;/li&gt;
&lt;li&gt;Integrated testing&lt;/li&gt;
&lt;li&gt;E2E testing&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Containerisation/Virtualisation
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Docker&lt;/li&gt;
&lt;li&gt;Kubernetes&lt;/li&gt;
&lt;li&gt;RKT&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Architectural patterns
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Monolithic&lt;/li&gt;
&lt;li&gt;Microservices&lt;/li&gt;
&lt;li&gt;Serverless&lt;/li&gt;
&lt;li&gt;Scaling (Horizontal &amp;amp; Vertical)&lt;/li&gt;
&lt;li&gt;Load Balancers&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Cloud platforms
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;AWS (Amazon Web Services)&lt;/li&gt;
&lt;li&gt;GCP (Google Cloud Platform)&lt;/li&gt;
&lt;li&gt;Microsoft Azure&lt;/li&gt;
&lt;li&gt;Oracle Cloud&lt;/li&gt;
&lt;li&gt;SISCO&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Thank you for reading this article. If you find something valuable in this article please give it a clap and leave your thoughts. Don’t forget to share.&lt;/p&gt;

&lt;p&gt;To be continued!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>career</category>
      <category>html</category>
      <category>css</category>
    </item>
    <item>
      <title>Build your own Operating System #2_implementing_C</title>
      <dc:creator>Sadisha Nimsara</dc:creator>
      <pubDate>Wed, 21 Jul 2021 18:04:38 +0000</pubDate>
      <link>https://forem.com/nsadisha/build-your-own-operating-system-2implementingc-5aa9</link>
      <guid>https://forem.com/nsadisha/build-your-own-operating-system-2implementingc-5aa9</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuqrjqcxdty6gpvqhrtrf.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%2Fuqrjqcxdty6gpvqhrtrf.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;a href="https://dev.to/nsadisha/build-your-own-operating-system-1setupbooting-171-temp-slug-9396464"&gt;previous article&lt;/a&gt;, we guided you to setup the booting part of our operating system. In this article, we are going to implement C language to our project instead of Assembly language. Assembly is a very good programming for interacting with CPU and other hardware resources. But, C is much more human-friendly language when compared with Assembly language. So, we decided to use C as much as possible to make the development process easier and assembly language will be used only where it make sense.&lt;/p&gt;

&lt;p&gt;So, let’s get started!&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting up a stack
&lt;/h3&gt;

&lt;p&gt;Since all non-trivial(not lightweight) C programs use a stack, and setting up a stack is not harder than to make the &lt;code&gt;esp&lt;/code&gt; register point to the end of an area of free memory. So far, in this development process, the only things in memory are GRUB, BIOS, the OS kernel, and some memory mapped I/Os. This is not a good thing to do; because, we don’t know how much memory is available or if the &lt;code&gt;esp&lt;/code&gt; pointed memory area is used by something else.&lt;/p&gt;

&lt;p&gt;Reserving a piece of uninitialized memory in the &lt;code&gt;bss&lt;/code&gt; section in the ELF file of the kernel will be a solution. And also, this will reduce the OS executable size.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;KERNEL_STACK_SIZE equ 4096 ; size of stack in bytes

    section .bss
    align 4 ; align at 4 bytes
    kernel_stack: ; label points to beginning of memory
        resb KERNEL_STACK_SIZE ; reserve stack for the kernel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Add this section to &lt;code&gt;loader.s&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;And then, we need to setup the stack pointer by pointing &lt;code&gt;esp&lt;/code&gt; to the end of the &lt;code&gt;kernel\_stack&lt;/code&gt; memory. In order to do that, you need to add the following statement inside the &lt;code&gt;loader:&lt;/code&gt; block you your &lt;code&gt;loader.s&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mov esp, kernel_stack + KERNEL_STACK_SIZE ; point esp to the start of the
                                                ; stack (end of memory area)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;After all, loader.s file will look like this:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h3&gt;
  
  
  Calling C code from the Assembly
&lt;/h3&gt;

&lt;p&gt;Since we are using C language, we need to call the C code from the Assembly code. There are many different ways to do that. But in here, we will use &lt;a href="https://en.wikipedia.org/wiki/X86_calling_conventions#cdecl" rel="noopener noreferrer"&gt;cdecl&lt;/a&gt; calling convention. According to this convention, the arguments of the function should be pushed on the stack in a right-to-left order, that is, you push the rightmost argument first. And, the return value of the function is placed in the &lt;code&gt;eax&lt;/code&gt; register.&lt;/p&gt;

&lt;p&gt;For example, to call the following function in Assembly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* The C function */&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;sum_of_three&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;arg1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;arg2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;arg3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;arg1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;arg2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;arg3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You have to call it like this.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;; The assembly code
external sum_of_three ; the function sum_of_three is defined elsewhere

    push dword 3 ; arg3
    push dword 2 ; arg2
    push dword 1 ; arg1
    call sum_of_three ; call the function, result will be in eax
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In your project directory, create an empty file called &lt;code&gt;kmain.c&lt;/code&gt;. You can do it with &lt;code&gt;touch kmain.c&lt;/code&gt; command. You can keep this file empty for now.&lt;/p&gt;
&lt;h3&gt;
  
  
  Compiling the C code
&lt;/h3&gt;

&lt;p&gt;The next step will be this. For normal compilations, we can use &lt;code&gt;gcc fileName.c -o objectName&lt;/code&gt;. But, in this case, we are compiling them for an operating system. So, we have to use a lot of flags as below.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And, we recommend you to turn on all warnings and treat warnings as errors by adding these flaags:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-Wall -Wextra -Werror
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Build tools
&lt;/h3&gt;

&lt;p&gt;This is the last step for this article. In this step, we are going to build the OS. Previously, we used a lot of commands to compile each and every file separately, build the ISO image, and run the OS in &lt;code&gt;bochs&lt;/code&gt; emulator. But, we can do it in an easier way. In order to do that, you have to create a separate file to execute those commands. Execute &lt;code&gt;touch Makefile&lt;/code&gt; to create the file.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Save this file in &lt;code&gt;Makefile&lt;/code&gt;. Note that you have to do all the indentations with tabs, not with spaces.&lt;/p&gt;

&lt;p&gt;After all of these steps, your file structure should look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    .
    |-- bochsrc.txt
    |-- iso
    | |-- boot
    | |-- grub
    | |-- menu.lst
    | |-- stage2_eltorito
    |-- kmain.c
    |-- loader.s
    |-- Makefile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you should be able to run the OS in the &lt;code&gt;bochs&lt;/code&gt; emulator by executing the simple command &lt;code&gt;make run&lt;/code&gt;. This will compile the kernel and boot it up. Then check the &lt;code&gt;bochslog.txt&lt;/code&gt; to find &lt;code&gt;RAX=00000000CAFEBABE&lt;/code&gt; or &lt;code&gt;EAX=CAFEBABE&lt;/code&gt; to make sure that your OS has successfully booted.&lt;/p&gt;

&lt;p&gt;You can download a completed code that I have created for booting my OS from: &lt;a href="https://github.com/nsadisha/lemonOS/tree/implement_with_c" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you have successfully implemented C to OS and hope to catch you in the next article.&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Build your own Operating System #1_setup_booting</title>
      <dc:creator>Sadisha Nimsara</dc:creator>
      <pubDate>Mon, 12 Jul 2021 13:05:34 +0000</pubDate>
      <link>https://forem.com/nsadisha/build-your-own-operating-system-1setupbooting-2im3</link>
      <guid>https://forem.com/nsadisha/build-your-own-operating-system-1setupbooting-2im3</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy0xuuz6m6mg86ixb81ae.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%2Fy0xuuz6m6mg86ixb81ae.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the first article of “&lt;em&gt;Build your own OS&lt;/em&gt;” article series. In this article series, we hope to guide you how you can build your own operating system with &lt;em&gt;linux kernel&lt;/em&gt;. Developing a custom operating system is not an easy task. But, you will be able to develop your own simple operating system at the end of this article series.&lt;/p&gt;

&lt;p&gt;I will be using Ubuntu as the operating system for the development. Since we have to directly access the memory while developing, its better to try all these things in a virtual box environment for safety purposes. I will be using C and assembly languages in this article series.&lt;/p&gt;

&lt;p&gt;So, let’s get started!&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting up development environment
&lt;/h3&gt;

&lt;p&gt;Once you have done installing Ubuntu in a virtual box, the next step is installing some necessary packages ( &lt;strong&gt;build-essential&lt;/strong&gt; , &lt;strong&gt;nasm&lt;/strong&gt; , &lt;strong&gt;genisoimage&lt;/strong&gt; , &lt;strong&gt;bochs&lt;/strong&gt; and &lt;strong&gt;bochs-sdl&lt;/strong&gt; ). You can simply install them by executing this command in 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;sudo apt-get install build-essential nasm genisoimage bochs bochs-sdl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  build-essential
&lt;/h4&gt;

&lt;p&gt;This package contains GNU debugger, g++/GNU compiler collection, and some tools and libraries which are required to compile a C program.&lt;/p&gt;
&lt;h4&gt;
  
  
  nasm
&lt;/h4&gt;

&lt;p&gt;Since we are using assembly, we have to use nasm(Netwide Assembler) to compile assembly programs.&lt;/p&gt;
&lt;h4&gt;
  
  
  genisoimage
&lt;/h4&gt;

&lt;p&gt;We need this package to generate an ISO image file for the file system.&lt;/p&gt;
&lt;h4&gt;
  
  
  bochs
&lt;/h4&gt;

&lt;p&gt;This will be the emulator that we will be using to debug our operating system.&lt;/p&gt;
&lt;h3&gt;
  
  
  Booting
&lt;/h3&gt;

&lt;p&gt;Booting is the process of starting a computer. After you press the power button, computer will run several programs before handover the control of the computer to the operating system.&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%2Far3gp8v4toddg0107ymr.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%2Far3gp8v4toddg0107ymr.png" alt="Alt Text"&gt;&lt;/a&gt;Booting process diagram&lt;/p&gt;
&lt;h4&gt;
  
  
  BIOS
&lt;/h4&gt;

&lt;p&gt;BIOS program(stands for &lt;strong&gt;B&lt;/strong&gt;asic &lt;strong&gt;I&lt;/strong&gt;nput &lt;strong&gt;O&lt;/strong&gt;utput &lt;strong&gt;S&lt;/strong&gt;ystem) is usually stored on a read only memory chip on the motherboard of the PC. The original role of the BIOS program was to export some library functions for printing to the screen, reading keyboard input etc. After all, it will transfer the control of the computer to the bootloader.&lt;/p&gt;
&lt;h4&gt;
  
  
  Bootloader
&lt;/h4&gt;

&lt;p&gt;This program’s task is to handover the control of the computer to the operating system. But, due to some restrictions, the bootloader is often split into two parts. The first part of the bootloader will transfer control to the second part, which finally transfers the control to the operating system.&lt;/p&gt;

&lt;p&gt;We will be using an existing bootloader called “&lt;em&gt;GNU GRand Unified Bootloader (GRUB)&lt;/em&gt;”. Because we don’t need to write a lot of low-level codes. GRUB will load our operating system to the correct memory location.&lt;/p&gt;

&lt;p&gt;Download GRUB: &lt;a href="https://github.com/littleosbook/littleosbook/raw/master/files/stage2_eltorito" rel="noopener noreferrer"&gt;https://github.com/littleosbook/littleosbook/raw/master/files/stage2_eltorito&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Compiling the operating system
&lt;/h3&gt;

&lt;p&gt;In here we use little bit of assembly code. This program will write a very specific number 0xCAFEBABE to the eax register. Save the following code in a file called loader.s&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;The file loader.s can be compiled into a 32 bits ELF [18] object file with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nasm -f elf32 loader.s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Linking the Kernel
&lt;/h3&gt;

&lt;p&gt;Next, GRUB needs to load the Kernel into the memory. It should be loaded into a memory address larger than or equal to 0x00100000 (1 megabyte (MB)), because addresses lower than 1 MB are used by GRUB itself, BIOS and memory-mapped I/O. In order to do that, we will be using the following code.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Save the linker script into a file called link.ld. And then, the executable can now be linked with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ld -T link.ld -melf_i386 loader.o -o kernel.elf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The final executable file will be generated, called kernel.elf.&lt;/p&gt;

&lt;p&gt;Then, copy the downloaded file (stage2_eltorito) in to the same project location as loader.s and link.ld.&lt;/p&gt;
&lt;h3&gt;
  
  
  Building an ISO image file
&lt;/h3&gt;

&lt;p&gt;ISO image is the type that can be loaded by a virtual or physical machine. So, we will create the kernel ISO image with the genisoimage package. Before generating an ISO, we need to create a specific folder structure and copy the bootloader and the kernel into different locations. Which can be done by executing following commands.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir -p iso/boot/grub # create the folder structure
cp stage2_eltorito iso/boot/grub/ # copy the bootloader
cp kernel.elf iso/boot/ # copy the kernel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Finally, a configuration file menu.lst for GRUB must be created. This file tells GRUB where the kernel is located and configures some options:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Place the file menu.lst in the folder iso/boot/grub/. Then, the contents of the iso folder should now look like the following figure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iso
 |-- boot
       |-- grub
       |     |-- menu.lst
       |     |-- stage2_eltorito
       |-- kernel.elf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If your folder structure is correct, you can generate your ISO image with the following command.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;genisoimage -R \
            -b boot/grub/stage2_eltorito \
            -no-emul-boot \
            -boot-load-size 4 \
            -A os \
            -input-charset utf8 \
            -quiet \
            -boot-info-table \
            -o os.iso \
            iso
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now you have successfully created the os.iso file.&lt;/p&gt;
&lt;h3&gt;
  
  
  Running your OS in Bochs
&lt;/h3&gt;

&lt;p&gt;Now we can run the OS in the Bochs emulator using the os.iso ISO image. One last thing before that, Bochs needs a configuration file to start and an example of a simple configuration file is given below:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Save this file as bochsrc.txt in the root directory of your project(same location as loader.s). And run the following command to boot your os in Bochs emulator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bochs -f bochsrc.txt -q
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Extra: If you see any error in your terminal try changing display_library: sdl to display_library: sdl2 . And try!&lt;/p&gt;

&lt;p&gt;If you see some text on the bochs emulator, containing “Booting os”, quit the emulator. If emulator has no text on the screen, type continue in the terminal and hit enter. It will boot the OS.&lt;/p&gt;

&lt;p&gt;After quitting the Bochs, you can check the log generated by the Bochs. You can open it in a text editor or else execute the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat bochslog.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should now see the contents of the registers of the CPU simulated by Bochs somewhere in the output. If you find RAX=00000000CAFEBABE or EAX=CAFEBABE (depending on if you are running Bochs with or without 64 bit support) in the output;&lt;/p&gt;

&lt;p&gt;Congratulations!!! Your OS has successfully booted!&lt;/p&gt;

&lt;p&gt;You can download a completed code that I have created for booting my OS from: &lt;a href="https://github.com/nsadisha/lemonOS/tree/setup_booting_os" rel="noopener noreferrer"&gt;https://github.com/nsadisha/lemonOS/tree/setup_booting_os&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you have successfully booted your OS and hope to catch you in the next article.&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;

</description>
      <category>ubuntu</category>
      <category>opensource</category>
      <category>c</category>
      <category>assembly</category>
    </item>
    <item>
      <title>Get pinned GitHub repositories as JSON</title>
      <dc:creator>Sadisha Nimsara</dc:creator>
      <pubDate>Tue, 22 Dec 2020 18:33:28 +0000</pubDate>
      <link>https://forem.com/nsadisha/get-pinned-github-repositories-as-json-1hff</link>
      <guid>https://forem.com/nsadisha/get-pinned-github-repositories-as-json-1hff</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffnpbaap4b74mgp93lm7i.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%2Fi%2Ffnpbaap4b74mgp93lm7i.png" alt="JSON" width="512" height="512"&gt;&lt;/a&gt;&lt;br&gt;
I saw a lot of people asking about how they can get pinned GitHub repositories as a JSON response. This can be done with GraphQL, but some of them are asking for a rest API solution. Fortunately, I found a solution for them.&lt;/p&gt;

&lt;p&gt;Visit this site:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://gh-pinned-repos-5l2i19um3.vercel.app/" rel="noopener noreferrer"&gt;https://gh-pinned-repos-5l2i19um3.vercel.app/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Type your GitHub username&lt;/li&gt;
&lt;li&gt;Click the ‘go’ button&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There you have your JSON response. Or else, you can just replace your Username in the following URL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://gh-pinned-repos-5l2i19um3.vercel.app/?username=Username
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This program was originally developed by &lt;a href="https://github.com/egoist" rel="noopener noreferrer"&gt;@egoist&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For contributors: &lt;a href="https://github.com/egoist/gh-pinned-repos" rel="noopener noreferrer"&gt;Source code&lt;/a&gt;&lt;/p&gt;

</description>
      <category>github</category>
      <category>json</category>
      <category>pinned</category>
      <category>repositories</category>
    </item>
    <item>
      <title>How to create a bootable flash drive with command prompt(cmd)</title>
      <dc:creator>Sadisha Nimsara</dc:creator>
      <pubDate>Fri, 04 Dec 2020 05:12:46 +0000</pubDate>
      <link>https://forem.com/nsadisha/how-to-create-a-bootable-flash-drive-with-command-prompt-cmd-19e6</link>
      <guid>https://forem.com/nsadisha/how-to-create-a-bootable-flash-drive-with-command-prompt-cmd-19e6</guid>
      <description>&lt;p&gt;In order to install windows to a computer that no DVD ROM, you need to prepare a bootable flash drive for that.&lt;/p&gt;

&lt;h3&gt;
  
  
  Formatting the flash drive
&lt;/h3&gt;

&lt;p&gt;First of all, plug-in a flash drive with a minimum of 4GB of capacity. Now, go to windows explorer, right-click on your flash drive and format it in a regular way.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a partition in the command prompt
&lt;/h3&gt;

&lt;p&gt;Next, you have to set up your flash drive to make it a bootable drive. To do that, you have to open your command prompt with &lt;em&gt;Run as administrator&lt;/em&gt;. And then, type the following command in your cmd.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This opens the diskpart.exe program. Now type,&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;And hit enter. This command shows information about all the drives that are connected at the time. Now you have to identify your flash drive with its capacity and remember its disk number. (eg: Disk 1)&lt;br&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%2Fi%2Fodna0knyn7ma3u9e7rff.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%2Fi%2Fodna0knyn7ma3u9e7rff.png" alt="List disk results"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, type the following command and hit enter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select disk 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will show a message that “Disk 1 is now the selected disk.” Now you have to remove the default setting in your flash drive. Type,&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;and hit enter. This will show the message “DiskPart succeeded in cleaning the disk.”&lt;br&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%2Fi%2Fre2aoj1zjlb5p6cwj5m4.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%2Fi%2Fre2aoj1zjlb5p6cwj5m4.png" alt="clean result"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To create a bootable disk, you need to have a separate partition for that. For that, type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create partition primary
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and hit enter. This will show “succeeded in creating the specified partition.” Now you need to select the partition. For that, type,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select partition 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and hit the enter key. This shows “Partition 1 is now selected partition.” message. Now you have to make that partition active. Type,&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This will show you “DiskPart marked the current partition as active.”&lt;br&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%2Fi%2F1tw9bzemjzlt1e3vqe0i.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%2Fi%2F1tw9bzemjzlt1e3vqe0i.png" alt="active results"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Formatting the partition
&lt;/h3&gt;

&lt;p&gt;Now, you need to format the partition as suitable. In order to do that, Type,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;format fs=fat32 quick
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and enter. Now, flash drive will be formatted, then shows “100 percent completed” and “DiskPart success fully formatted the volume.”&lt;/p&gt;

&lt;p&gt;Now you have to assign a dive letter to the flash drive. Type,&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;and enter. This will show the message “DiskPart successfully assigned the drive letter or mount point.” &lt;br&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%2Fi%2F2bxu6jc99qo5rzbe4eg5.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%2Fi%2F2bxu6jc99qo5rzbe4eg5.png" alt="assign results"&gt;&lt;/a&gt;&lt;br&gt;
Now you are done with the command prompt and you can close it by typing &lt;code&gt;exit&lt;/code&gt; and hit enter.&lt;br&gt;
Now, you are almost done! :)&lt;/p&gt;

&lt;h3&gt;
  
  
  Copy the setup files
&lt;/h3&gt;

&lt;p&gt;This is the last step of the process. You need to copy all the windows installation files to your flash drive.&lt;/p&gt;

&lt;p&gt;Now you can install windows to a computer using this flash drive.&lt;/p&gt;

</description>
      <category>windows</category>
      <category>cmd</category>
      <category>bootableflashdrive</category>
      <category>format</category>
    </item>
    <item>
      <title>Github git cheat sheet</title>
      <dc:creator>Sadisha Nimsara</dc:creator>
      <pubDate>Fri, 04 Dec 2020 04:39:07 +0000</pubDate>
      <link>https://forem.com/nsadisha/new-post-355m</link>
      <guid>https://forem.com/nsadisha/new-post-355m</guid>
      <description>&lt;h1&gt;
  
  
  GitHub Git Cheat Sheet
&lt;/h1&gt;

&lt;p&gt;Git  is an open  source  distributed  version  control  system  that  facilitates  GitHub  activities  on  your  laptop  or &lt;br&gt;
desktop. This cheat sheet will help you with commonly used Git command line instructions for quick reference.&lt;/p&gt;
&lt;h3&gt;
  
  
  Catalog
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Install Git&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;How to use Git&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Configure tooling&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Create repositories&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Make changes&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Group changes&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Refactor filenames&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Suppress tracking&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Save fragments&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Review history&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Redo commits&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Synchronize changes&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  INSTALL GIT
&lt;/h2&gt;
&lt;h3&gt;
  
  
  For Windows users
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Download &lt;a href="https://git-scm.com/download/win" rel="noopener noreferrer"&gt;Git for Windows Setup&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Install Git through the setup. Usually all configurations can be left in default settings.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  For macOS users
&lt;/h3&gt;

&lt;p&gt;Download &lt;a href="https://git-scm.com/download/mac" rel="noopener noreferrer"&gt;Git for Mac&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  For Linux users
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Debian/Ubuntu
&lt;/h4&gt;

&lt;p&gt;For the latest stable version for your release of Debian/Ubuntu&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get update
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get get &lt;span class="nb"&gt;install &lt;/span&gt;git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Ubuntu, this PPA provides the latest stable upstream Git version&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;add-apt-repository ppa:git-core/ppa
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Fedora
&lt;/h4&gt;

&lt;p&gt;For releases up to Fedora 21&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;yum &lt;span class="nb"&gt;install &lt;/span&gt;git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Fedora 22 and later&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;dnf &lt;span class="nb"&gt;install &lt;/span&gt;git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Arch Linux
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;pacman &lt;span class="nt"&gt;-S&lt;/span&gt; git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  HOW TO USE GIT
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Windows&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Right click on any location and click &lt;code&gt;git bash&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Linux and Mac&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Open &lt;code&gt;Terminal&lt;/code&gt; to use git.&lt;/p&gt;
&lt;h2&gt;
  
  
  CONFIGURE TOOLING
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Configure user information for all local repositories&lt;/strong&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Set the name you want attached to your commit transactions&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.name &lt;span class="s2"&gt;"[name]"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set the email address you want attached to your commit transactions&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.email &lt;span class="s2"&gt;"[email address]"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  CREATE REPOSITORIES
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Start a new repository or obtain one from an existing URL&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a new local repository with the specified name&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git init &lt;span class="o"&gt;[&lt;/span&gt;project-name]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Download a project and its entire version history&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git clone &lt;span class="o"&gt;[&lt;/span&gt;url]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  MAKE CHANGES
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Review edits and craft a commit transaction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;List all new or modified files to be commited&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Show file differences not yet staged&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git diff
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Snapshot a file in preparation for versioning&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git add &lt;span class="o"&gt;[&lt;/span&gt;file]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Snapshot all files of the current directory in preparation for versioning&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unstage the file (reset), but preserve its contents&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git reset &lt;span class="o"&gt;[&lt;/span&gt;file]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Record file snapshots permanently in version history&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"[descriptive message]"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  GROUP CHANGES
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Name a series of commits and combine completed efforts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;List all local branches in the current repository&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a new branch&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git branch &lt;span class="o"&gt;[&lt;/span&gt;branch-name]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Switch to the specified branch and updates the working directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git checkout &lt;span class="o"&gt;[&lt;/span&gt;branch-name]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Combine the specified branch's history into the current branch&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git merge &lt;span class="o"&gt;[&lt;/span&gt;branch-name]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Delete the specified branch&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git branch &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;branch-name]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  REFACTOR FILENAMES
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Relocate and remove versioned files&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Delete the file from the working directory and stages the deletion&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;file]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remove the file from version control but preserves the file locally&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git rm --cached [file]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change the file name and prepares it for commit&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git mv [file-original] [file-renamed]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  SUPPRESS TRACKING
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exclude temporary files and paths&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;List all ignored files in this project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git ls-files --other --ignored --exclude-standard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A text file named .gitignore suppresses accidental versioning of files and paths matching the specified paterns&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*.log
build/
temp-*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  SAVE FRAGMENTS
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Shelve and restore incomplete changes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Temporarily store all modified tracked files&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git stash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;List all stashed changesets&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git stash list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restore the most recently stashed files&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git stash pop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Discard the most recently stashed changeset&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git stash drop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  REVIEW HISTORY
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Browse and inspect the evolution of project files&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;List version history for the current branch&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;List version history for a file, including renames&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git log --follow [file]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Show content differences between two branches&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git diff [first-branch]...[second-branch]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output metadata and content changes of the specified commit&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git show [commit]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  REDO COMMITS
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Erase mistakes and craf replacement history&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Undo all commits afer [commit], preserving changes locally&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git reset [commit]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Discard all history and changes back to the specified commit&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git reset --hard [commit]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  SYNCHRONIZE CHANGES
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Register a repository bookmark and exchange version history&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Download all history from the repository bookmark&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git fetch [bookmark]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Combine bookmark’s branch into current local branch&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git merge [bookmark]/[branch]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Upload all local branch commits to GitHub&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git push [alias] [branch]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Download bookmark history and incorporates changes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git pull
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>github</category>
      <category>git</category>
      <category>cheats</category>
      <category>cheatsheet</category>
    </item>
    <item>
      <title>Dealing with databases</title>
      <dc:creator>Sadisha Nimsara</dc:creator>
      <pubDate>Fri, 25 Sep 2020 18:49:01 +0000</pubDate>
      <link>https://forem.com/nsadisha/dealing-with-databases-200b</link>
      <guid>https://forem.com/nsadisha/dealing-with-databases-200b</guid>
      <description>&lt;h3&gt;
  
  
  What is a database?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm1cih7kmz1hbvwfgqxvt.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm1cih7kmz1hbvwfgqxvt.jpeg" alt="Database image" width="800" height="327"&gt;&lt;/a&gt;A graphical image for a database&lt;/p&gt;

&lt;p&gt;Simply, A database is an organized collection of structured information, or data, typically stored electronically in a computer system.&lt;/p&gt;

&lt;h3&gt;
  
  
  Designing a database
&lt;/h3&gt;

&lt;p&gt;There are many ways you can design your database depending on what kind of database you are going to design. In general, Let’s see how to design a SQL database. There are 3 main to design a SQL database.&lt;/p&gt;

&lt;p&gt;Those are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Decide what are the objects you want to include in your database.&lt;/li&gt;
&lt;li&gt;Determine which of these objects should be tables and which should be columns within those tables.&lt;/li&gt;
&lt;li&gt;Define tables based on how you need to organize the objects.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Step 1: Define objects
&lt;/h4&gt;

&lt;p&gt;As the first step in designing a database, you have to select &lt;strong&gt;important&lt;/strong&gt; aspects of the system to include in the model. Treat each aspect as an object. List all the objects as you can think of.&lt;/p&gt;

&lt;p&gt;When you are done, decide how these objects related to each other. Each object considered as an entity. And each entity has its own attributes. Some of the objects are major entities and other objects are subsidiary to those major entities.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2: Identify tables and columns
&lt;/h4&gt;

&lt;p&gt;Major entities become database tables. Its attributes become table columns. Many business databases, for example, consider a CUSTOMER table that keeps track of customers’ names, addresses, and other permanent information. Each attribute of a customer — such as name, street, city, state, etc —becomes a column in the CUSTOMER table.&lt;/p&gt;

&lt;p&gt;It is better to find a set of rules to identify which objects should be tables and which attributes belong to which table.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 3: Define tables
&lt;/h4&gt;

&lt;p&gt;Now you have to define tables for each entity and columns for each attribute. You can use either a rapid application development (RAD) tool or SQL’s Data Definition Language (DDL) to create tables.&lt;/p&gt;

&lt;h3&gt;
  
  
  SQL
&lt;/h3&gt;

&lt;p&gt;All the data, that are organized and stored in databases, should be able to access. That is where SQL comes.&lt;/p&gt;

&lt;h4&gt;
  
  
  Introduction
&lt;/h4&gt;

&lt;p&gt;SQL which stands for &lt;em&gt;(Structured Query Language)&lt;/em&gt;, is used to access and modify data stored in databases. It was developed by Donald D. Chamberlin and Raymond F. Boyce at IBM in the early 1970s. It was originally called SEQUEL &lt;em&gt;(Structured English Query Language)&lt;/em&gt;, but later it became SQL.&lt;/p&gt;

&lt;h4&gt;
  
  
  What does SQL do?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Creating the database with SQL’s Data Definition Language (DDL).&lt;/li&gt;
&lt;li&gt;The main thing SQL does is accessing the data stored in databases.&lt;/li&gt;
&lt;li&gt;In a sense, SQL is the thing that stays in the middle and connects front-end with the back-end databases.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Commands
&lt;/h4&gt;

&lt;p&gt;SQL contains many important commands to deal with data.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SELECT — extracts data from a table&lt;/li&gt;
&lt;li&gt;DELETE — deletes data stored on a table&lt;/li&gt;
&lt;li&gt;CREATE DATABASE — creates a new database&lt;/li&gt;
&lt;li&gt;INSERT INTO — puts your data into a table&lt;/li&gt;
&lt;li&gt;ALTER DATABASE — makes changes to a database&lt;/li&gt;
&lt;li&gt;CREATE TABLE — creates a new table within a database&lt;/li&gt;
&lt;li&gt;CREATE INDEX — creates a new search key&lt;/li&gt;
&lt;li&gt;DROP — delete an existing table or a database&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With these commands, you can easily modify and manipulate data as you want.&lt;/p&gt;

&lt;p&gt;Examples:&lt;br&gt;
&lt;/p&gt;

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

CREATE TABLE Student_Info(
stdID int,
name varchar(50),
address varchar(50),
city varchar(20),
phoneNumber int
);

INSERT INTO Student_Info VALUES(
001,
'student name1',
'address1',
'city1',
99345638906
);

INSERT INTO Student_Info VALUES(
002,
'student name2',
'address2',
'city2',
99343213459
);

SELECT name FROM Student_Info WHERE stdID=001;

SELECT * FROM Student_Info
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Advantages
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;High speed&lt;/li&gt;
&lt;li&gt;Portable&lt;/li&gt;
&lt;li&gt;No coding skills needed&lt;/li&gt;
&lt;li&gt;Easy to learn and understand&lt;/li&gt;
&lt;li&gt;Multiple data views&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Disadvantages
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Difficult interface&lt;/li&gt;
&lt;li&gt;Some versions are costly&lt;/li&gt;
&lt;li&gt;Complete control is not given to the database&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Why SQL is Very Popular
&lt;/h4&gt;

&lt;p&gt;Businesses love SQL because it is a quick and efficient way of retrieving, viewing, and editing large volumes of data. &lt;a href="https://insights.stackoverflow.com/survey/2016" rel="noopener noreferrer"&gt;StackOverflow&lt;/a&gt; report that SQL is the second most used programming language (JavaScript is first) and regularly used by 58% of full-stack developers, 53% of back-end developers, and 25% of front-end developers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Physical databases
&lt;/h3&gt;

&lt;p&gt;Physical databases are both the actual device housing the information files and the search paths used to access information between sources. They are technically smaller units of storage. A field is the smallest unit of storage housing only a single file.&lt;/p&gt;

&lt;p&gt;As a summary, a physical database can be called as a refinement of the logical database design.&lt;/p&gt;

&lt;p&gt;According to Microsoft, the term “database” refers only to the logical database controlling information files for the entire system.&lt;/p&gt;

</description>
      <category>dealing</category>
      <category>database</category>
      <category>data</category>
      <category>sql</category>
    </item>
  </channel>
</rss>
