<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: limjy</title>
    <description>The latest articles on DEV Community by limjy (@jing).</description>
    <link>https://dev.to/jing</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%2F501310%2Fb9397fc8-8f8c-4f34-9213-39bcafc9579b.png</url>
      <title>DEV Community: limjy</title>
      <link>https://dev.to/jing</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jing"/>
    <language>en</language>
    <item>
      <title>System Design</title>
      <dc:creator>limjy</dc:creator>
      <pubDate>Sat, 29 May 2021 09:49:48 +0000</pubDate>
      <link>https://dev.to/jing/system-design-2c4p</link>
      <guid>https://dev.to/jing/system-design-2c4p</guid>
      <description>&lt;p&gt;System Design study guide / interview prep for me&lt;/p&gt;

&lt;p&gt;Content here is &lt;strong&gt;not original&lt;/strong&gt;. It is is a summary of the following sources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.freecodecamp.org/news/systems-design-for-interviews/"&gt;freeCodeCamp - System Design Interview Question&lt;/a&gt; (really comprehensive 20/10 will recommend you give it a read)&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  TOC
&lt;/h1&gt;

&lt;p&gt;&lt;u&gt; API design &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Http methods&lt;/li&gt;
&lt;li&gt;Standard Error Codes&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackprint.io/post/common-api-design-interview-questions"&gt;https://stackprint.io/post/common-api-design-interview-questions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;Basics&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Storage: Memory VS disk&lt;/li&gt;
&lt;li&gt;Latency VS Throughput&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;System Availability&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Availability: Intro&lt;/li&gt;
&lt;li&gt;High Availability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Caching &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why caching&lt;/li&gt;
&lt;li&gt;Use Cases&lt;/li&gt;
&lt;li&gt;Caching Strategies&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Proxy &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Proxy &amp;amp; how they work&lt;/li&gt;
&lt;li&gt;forward proxy VS reverse proxy&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Load Balancing &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why load balancing&lt;/li&gt;
&lt;li&gt;
server selection strategy

&lt;ul&gt;
&lt;li&gt;round robin, weighted round robin&lt;/li&gt;
&lt;li&gt;load based server selection&lt;/li&gt;
&lt;li&gt;IP hashing based selection&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Adding servers / handling failing servers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Database design &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CAP theorem&lt;/li&gt;
&lt;li&gt;Scaling: vertical VS horizontal&lt;/li&gt;
&lt;li&gt;
Relational Database

&lt;ul&gt;
&lt;li&gt;ACID properties&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
Non-relational database

&lt;ul&gt;
&lt;li&gt;BASE properties&lt;/li&gt;
&lt;li&gt;
Types of NoSQL

&lt;ul&gt;
&lt;li&gt;Graph database&lt;/li&gt;
&lt;li&gt;Document Store&lt;/li&gt;
&lt;li&gt;key-value store&lt;/li&gt;
&lt;li&gt;column-family DB&lt;/li&gt;
&lt;li&gt;Search Engine DB&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;NoSQL VS relational&lt;/li&gt;
&lt;li&gt;Replication &amp;amp; Sharding&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;Leader Election&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Leader Election - Basics&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Endpoint protection &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use cases

&lt;ul&gt;
&lt;li&gt;protecting against DOS&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;rate-limiting&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; pub-sub Messaging / MQs &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Benefits&lt;/li&gt;
&lt;li&gt;Use case / purpose&lt;/li&gt;
&lt;li&gt;pub/sub messaging&lt;/li&gt;
&lt;li&gt;comparison to DB&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;small&gt;&lt;u&gt;References to getting started&lt;/u&gt;&lt;/small&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;small&gt;&lt;a href="https://igotanoffer.com/blogs/tech/databases-system-design-interview"&gt;IGotAnOffer - Database: system design interview concepts&lt;/a&gt; &lt;/small&gt;&lt;/li&gt;
&lt;li&gt;&lt;small&gt;&lt;a href="https://www.freecodecamp.org/news/systems-design-for-interviews/"&gt;freeCodeCamp - System Design interview concepts&lt;/a&gt;&lt;/small&gt;&lt;/li&gt;
&lt;li&gt;
&lt;small&gt;&lt;a href="https://medium.com/javarevisited/25-software-design-interview-questions-to-crack-any-programming-and-technical-interviews-4b8237942db0"&gt;medium - 25 java software design questions&lt;/a&gt;&lt;/small&gt;
### &lt;a&gt;HTTP Methods&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;GET

&lt;ul&gt;
&lt;li&gt;retrieve resources&lt;/li&gt;
&lt;/ul&gt;


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

&lt;ul&gt;
&lt;li&gt;submit &lt;strong&gt;new data&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;


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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;update&lt;/strong&gt; / replace existing data&lt;/li&gt;
&lt;/ul&gt;


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

&lt;ul&gt;
&lt;li&gt;removes data &lt;/li&gt;
&lt;/ul&gt;


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

&lt;ul&gt;
&lt;li&gt;modify resource. &lt;em&gt;only contains changes&lt;/em&gt; not whole resource&lt;/li&gt;
&lt;/ul&gt;


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

&lt;ul&gt;
&lt;li&gt;requests available communication methods&lt;/li&gt;
&lt;/ul&gt;


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

&lt;ul&gt;
&lt;li&gt;request resource metadata without retrieve full resource representation&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;&lt;small&gt; reference: &lt;a href="https://stackoverflow.blog/2020/03/02/best-practices-for-rest-api-design/"&gt;SO&lt;/a&gt; &amp;amp; &lt;a href="https://stackprint.io/post/common-api-design-interview-questions"&gt;stackprint&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Standard Error Code&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;400 Bad request

&lt;ul&gt;
&lt;li&gt;client side input fail validation&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;401 Unauthorized

&lt;ul&gt;
&lt;li&gt;user not authenticated&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;403 forbidden

&lt;ul&gt;
&lt;li&gt;user authenticated but not privileged to access resources &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;404 Not Found

&lt;ul&gt;
&lt;li&gt;resource not found&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;500 Internal Server Error

&lt;ul&gt;
&lt;li&gt;generic server error. shouldn't be thrown explicitly.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;502 Bad gateway

&lt;ul&gt;
&lt;li&gt;invalid response from upstream server&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;503 Service Unavailable

&lt;ul&gt;
&lt;li&gt;something unexpected happen on server side (server overload, some parts fiail(
&lt;small&gt; reference: &lt;a href="https://stackoverflow.blog/2020/03/02/best-practices-for-rest-api-design/"&gt;SO&lt;/a&gt;&lt;/small&gt;
&lt;/li&gt;
&lt;/ul&gt;


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

&lt;h3&gt;
  
  
  &lt;a&gt;Storage: Memory VS Disk&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;u&gt;Disk&lt;/u&gt; is persistent. (when power is off, data will "persist").&lt;br&gt;
&lt;u&gt;RAM&lt;/u&gt; is transient. When lost power memory is wiped away.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If data is useful only during session of server then keep it in Memory.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Keeping it in &lt;strong&gt;RAM is much faster and less expensive&lt;/strong&gt; than writing to persistent database. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Latency VS Throughput&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;u&gt;Latency&lt;/u&gt;: duration for action to complete / produce result&lt;br&gt;
&lt;u&gt;Throughput&lt;/u&gt;: maximum capacity of system / work done in unit time.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Latency:

&lt;ul&gt;
&lt;li&gt;load site fast &amp;amp; smoothly&lt;/li&gt;
&lt;li&gt;fast lookups&lt;/li&gt;
&lt;li&gt;avoid pinging distant servers. &lt;/li&gt;
&lt;/ul&gt;


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

&lt;ul&gt;
&lt;li&gt;can improve by reducing &lt;em&gt;bottleneck&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;system will only be as fast as its slowest &lt;em&gt;bottleneck&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;increase by improving &lt;em&gt;slowest bottleneck&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;Hard ware definition from   &lt;a href="https://www.comparitech.com/net-admin/latency-vs-throughput/"&gt;compritech&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;u&gt;Latency&lt;/u&gt;: time taken for packet to be transferred across network&lt;br&gt;
&lt;u&gt;Throughput&lt;/u&gt;: quantity of data being send &amp;amp; recevied per unit time&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Scaling: Vertical VS Horizontal&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Vertical Scaling&lt;/strong&gt;: adding compute (CPU) and memory (RAM, Disk, SSD) resources to a single computer.&lt;br&gt;
&lt;strong&gt;Horizontal Scaling&lt;/strong&gt;: adding more computers to a cluster&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Vertical

&lt;ul&gt;
&lt;li&gt;fairly straightforward&lt;/li&gt;
&lt;li&gt;much lower overall memory capacity&lt;/li&gt;
&lt;/ul&gt;


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

&lt;ul&gt;
&lt;li&gt;higher overall compute and storage capacity&lt;/li&gt;
&lt;li&gt;sized dynamically without downtime&lt;/li&gt;
&lt;li&gt;most popular DB model hard to scale horizontally. &lt;/li&gt;
&lt;/ul&gt;


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

&lt;h3&gt;
  
  
  &lt;a&gt;Availability: Intro&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;availability is like resiliency of system. fault tolerant system makes an available system. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt; Uptime &lt;/u&gt;&lt;br&gt;
Measured using (uptime): percentage time system's primary function is available in given window of time&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Service Level Agreement / Assurance &lt;/u&gt;&lt;br&gt;
set of guaranteed service level metrics. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;How to achieve High Availability&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Reduce or eliminate &lt;strong&gt;single points of failure&lt;/strong&gt;&lt;br&gt;
This is done by designing &lt;strong&gt;redundancy&lt;/strong&gt; into the system. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Eg. two or more servers to provide services. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Why Caching&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Caching helps reduce &lt;strong&gt;latency&lt;/strong&gt; of system. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;app can perform faster

&lt;ul&gt;
&lt;li&gt;faster to retrieve data from memory than disk&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;Works best when&lt;/p&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;store static / infrequently caching data&lt;/li&gt;
&lt;li&gt;source of change is single operations rather than user-generate operations&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;If &lt;strong&gt;data consistency &amp;amp; freshness is critical&lt;/strong&gt;. Caching may &lt;strong&gt;not be optimal&lt;/strong&gt; unless cache is refreshed frequently (refresh cache frequently may not be ideal either)&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Caching: Use Case&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;when using certain piece of data often&lt;/li&gt;
&lt;li&gt;backend has computationally intensive work (cache reduces complexity to O(1))&lt;/li&gt;
&lt;li&gt;server makes multiple netwrk requests &amp;amp; API calls &lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;Example&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CDN (content delivery network)

&lt;ul&gt;
&lt;li&gt;caches content (images / videos/ webpages) in proxy server located closer to end user than origin server&lt;/li&gt;
&lt;li&gt;can deliver content more quickly. &lt;/li&gt;
&lt;/ul&gt;


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

&lt;h3&gt;
  
  
  &lt;a&gt;Caching Strategy&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;deals with the "write" operations of cache.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;keep cache &amp;amp; DB in sync&lt;/li&gt;
&lt;li&gt;should it be done synchronously or asyncrhonouslt&lt;/li&gt;
&lt;li&gt;data eviction - Which old records to "kick out" for new data?&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;Caching Strategies&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;LIFO&lt;/li&gt;
&lt;li&gt;FIFO&lt;/li&gt;
&lt;li&gt;LRU&lt;/li&gt;
&lt;li&gt;LFU 
### &lt;a&gt;Proxy:basics&lt;/a&gt;
&lt;em&gt;proxy&lt;/em&gt;: basically a middleman between client &amp;amp; origin server. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are 2 kinds of proxies&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;forward &lt;/li&gt;
&lt;li&gt;reverse
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q-Tui5AP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9344cfhsnt8pth9gmfuj.png" alt="alt text"&gt;
Forward&lt;/li&gt;
&lt;li&gt;computer make requests to sites on internet&lt;/li&gt;
&lt;li&gt;proxy server intercepts request&lt;/li&gt;
&lt;li&gt;communicate to web server on behalf of clients &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yU2dBwRi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ro2x3wczwuz2xl8vlstn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yU2dBwRi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ro2x3wczwuz2xl8vlstn.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
Reverse&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;client send request to origin server of website&lt;/li&gt;
&lt;li&gt;requests intercepted at network edge by reverse proxy server&lt;/li&gt;
&lt;li&gt;reverse proxy sends request to &amp;amp; receive response from origin server&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Forward VS Reverse Proxy&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;proxy&lt;/em&gt;: basically a middleman between client &amp;amp; origin server. &lt;/p&gt;

&lt;p&gt;&lt;u&gt; How proxies work&lt;/u&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;u&gt;Forward&lt;/u&gt;: sits in front of client, no origin server communicates with specific client. Server has no knowledge of client&lt;br&gt;
&lt;u&gt;Reverse&lt;/u&gt;: sits in front of origin server, no client communicate directly with origin server. Client has no knowledge of server. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Forward proxy&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;avoid company browsing restrictions. &lt;/li&gt;
&lt;li&gt;clients connect to proxy rather than directly to sites they are visiting &lt;/li&gt;
&lt;li&gt;block access to certain content&lt;/li&gt;
&lt;li&gt;school network, configure to connect to web via proxy that blocks stuff&lt;/li&gt;
&lt;li&gt;privacy&lt;/li&gt;
&lt;li&gt;IP address of client is harder to tarce, only IP address of prxy server is visible&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;Reverse proxy &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;load balancing&lt;/li&gt;
&lt;li&gt;distribute incoming traffic among different origin servers&lt;/li&gt;
&lt;li&gt;protection from attacks&lt;/li&gt;
&lt;li&gt; web site/service never needs to reveal IP address of original server&lt;/li&gt;
&lt;li&gt;harder to have targeted attack against origin server (eg. DDoS). hackers can only target reverse proxy. Reverse proxy will have tighter security &amp;amp; more resources.&lt;/li&gt;
&lt;li&gt;Global Server Local Balancing&lt;/li&gt;
&lt;li&gt;website distributed on several servers around the globe. &lt;/li&gt;
&lt;li&gt;reverse proxy send clients to server geographically closets to them. &lt;/li&gt;
&lt;li&gt;Caching&lt;/li&gt;
&lt;li&gt;reverse proxy can cache content -&amp;gt; faster performance &lt;/li&gt;
&lt;li&gt;SSL encryption&lt;/li&gt;
&lt;li&gt;reverse proxy can decrypt all incoming requests &amp;amp; encrypt all outgoing repsonses &lt;/li&gt;
&lt;li&gt;free up valuable resources on origin server. &lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;&lt;small&gt;Reference: &lt;a href="https://www.cloudflare.com/learning/cdn/glossary/reverse-proxy/"&gt;cloudflare&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Why Load balancing&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Maintain &lt;strong&gt;availability&lt;/strong&gt; &amp;amp; &lt;strong&gt;throughput&lt;/strong&gt;&lt;br&gt;
By &lt;strong&gt;distributing incoming request loads across multiple servers&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When server get lots of requests it can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;slow down (throughput reduces, more latency)&lt;/li&gt;
&lt;li&gt;fail (no availability)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Load Balancing helps this by &lt;strong&gt;Distribute incoming traffic among origin servers&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Load Balancing Strategies&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Probability server selection&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Round Robin

&lt;ul&gt;
&lt;li&gt;loop through servers in fixed sequence&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Weighted Round Robin

&lt;ul&gt;
&lt;li&gt;assign different weights / probabilities each server. &lt;/li&gt;
&lt;li&gt;traffic split up according to weights&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Load-based server selection

&lt;ul&gt;
&lt;li&gt;monitor current capacity / performance of servers&lt;/li&gt;
&lt;li&gt;send request to server with highest throughput / lowest latency.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;IP Hashing based selection

&lt;ul&gt;
&lt;li&gt;hash IP address of incoming request&lt;/li&gt;
&lt;li&gt;use hash value to allocate server &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Path / Service based selection

&lt;ul&gt;
&lt;li&gt;route requests based on path / service provided.&lt;/li&gt;
&lt;/ul&gt;


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

&lt;h3&gt;
  
  
  &lt;a&gt;CAP Theorem&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;any distributed DB can only satisfy 2 of three features&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Consistency&lt;/strong&gt;: every node responds with most recent version of data&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Availability&lt;/strong&gt;: Any node can send a response&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Partition tolerance&lt;/strong&gt;: system continues working even if communication between any of the nodes is broken&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;DB is usually &lt;strong&gt;CP or AP database&lt;/strong&gt;. Since cannot garuntee statbility of network, P is non-negotiable. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Relational Database&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;database using a &lt;strong&gt;relational data model&lt;/strong&gt;, organizes data in tables with rows of data entries and columns of predetermined data types. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt; Use when&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;many-to-many relatinoship between entries&lt;/li&gt;
&lt;li&gt;data needs to follow predetermined schema&lt;/li&gt;
&lt;li&gt;consistent transactions are important&lt;/li&gt;
&lt;li&gt;relationship between data always need to be accurate&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;ACID properties&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Atomicity

&lt;ul&gt;
&lt;li&gt;transaction is atomic / smallest unit. &lt;/li&gt;
&lt;li&gt;all instructions in transaction will execute or non at all&lt;/li&gt;
&lt;/ul&gt;


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

&lt;ul&gt;
&lt;li&gt;If DB in initially consistent, it should remain consistent after every transaction&lt;/li&gt;
&lt;li&gt;eg. write operation (transfer money from A to B) failed &amp;amp; transaction not rolled back. Db is inconsistent because amount of money between A &amp;amp;B (A+B) not equal before &amp;amp; after transaction&lt;/li&gt;
&lt;/ul&gt;


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

&lt;ul&gt;
&lt;li&gt;multiple transaction running concurrently they should be affected by each other&lt;/li&gt;
&lt;li&gt;result should be same as result obtained if transactions running sequentially.&lt;/li&gt;
&lt;/ul&gt;


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

&lt;ul&gt;
&lt;li&gt;changes committed to DB should remain even in case of software &amp;amp; system failure. &lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;&lt;small&gt; Reference &lt;a href="https://www.educative.io/edpresso/what-are-acid-properties-in-a-database"&gt;educative&lt;/a&gt; &amp;amp; &lt;a href="https://www.tutorialspoint.com/dbms/dbms_transaction.htm"&gt;tutorialspoint&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Non-relational Database&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;also known as NoSQL database. &lt;br&gt;
at core, DB hold data in hash-table like structure.&lt;br&gt;
&lt;strong&gt;Use cases&lt;/strong&gt;: caching, environment variables, configuration files / session state&lt;br&gt;
&lt;strong&gt;Use environment&lt;/strong&gt;: in memory &amp;amp; persisten storage&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Since their structure is like hashtable there is minimal over head&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;extremely fast&lt;/li&gt;
&lt;li&gt;simple &amp;amp; easy to use&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;NoSQL Base properties&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Basically available&lt;/strong&gt;: system guarantees availability&lt;br&gt;
&lt;strong&gt;soft state&lt;/strong&gt;: state of system may change over time even without input&lt;br&gt;
&lt;strong&gt;eventual consistency&lt;/strong&gt;: system will be consistent over very short period of time unless inputs are received&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Types of Nosql DB&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Graph database

&lt;ul&gt;
&lt;li&gt;many-to-many realtinoships&lt;/li&gt;
&lt;li&gt;fase at following graph edges&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Document Store

&lt;ul&gt;
&lt;li&gt;isolated documents, retrieve by a key&lt;/li&gt;
&lt;li&gt;documents with different schemas that are easy to update&lt;/li&gt;
&lt;li&gt;easy to scale&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Key-value store

&lt;ul&gt;
&lt;li&gt;like a very large hashtable&lt;/li&gt;
&lt;li&gt;opaque values (DB has no notion of what is stored in value only provides read, overwrite and delete operations)&lt;/li&gt;
&lt;li&gt;simple operations (no schemas, joins or indices)&lt;/li&gt;
&lt;li&gt;minimal overhead - easy to scale&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;suitable for caching implementations&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;column-family DB&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;NoSQL VS Relational&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;NoSQL&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;dynamic schema. &lt;/li&gt;
&lt;li&gt;dev can use "unstructured data" can build application without defining schema&lt;/li&gt;
&lt;li&gt;Scaling&lt;/li&gt;
&lt;li&gt;scales horizontally over cheap commodity servers&lt;/li&gt;
&lt;li&gt;Simple Operations&lt;/li&gt;
&lt;li&gt;data retrieval is simple&lt;/li&gt;
&lt;li&gt;Cheap hardware&lt;/li&gt;
&lt;li&gt;app deployed to commodity hardware like public clouds&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;SQL&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;workload volume is consistent&lt;/li&gt;
&lt;li&gt;ACID garuntees required&lt;/li&gt;
&lt;li&gt;data is predictable &amp;amp; highly structured&lt;/li&gt;
&lt;li&gt;data est expressed relationally&lt;/li&gt;
&lt;li&gt;write safety required&lt;/li&gt;
&lt;li&gt;app deployed to large high-end hardware&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;&lt;a href="https://www.mongodb.com/scale/nosql-vs-relational-databases"&gt;https://www.mongodb.com/scale/nosql-vs-relational-databases&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.mongodb.com/nosql-explained/when-to-use-nosql"&gt;https://www.mongodb.com/nosql-explained/when-to-use-nosql&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.microsoft.com/en-us/dotnet/architecture/cloud-native/relational-vs-nosql-data#considerations-for-relational-vs-nosql-systems"&gt;https://docs.microsoft.com/en-us/dotnet/architecture/cloud-native/relational-vs-nosql-data#considerations-for-relational-vs-nosql-systems&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Leader Election: Basics&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;When system scales horizontally, some tasks require precise coordination between nodes. Where there is &lt;em&gt;leader&lt;/em&gt; nodes directing &lt;em&gt;follower&lt;/em&gt; nodes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Leader Election algo&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;how cluster of nodes without leader communicate with each other &amp;amp; choose one to be leader.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;algo executed when cluster starts or when leader node goes down. &lt;/p&gt;

&lt;p&gt;&lt;u&gt; Use Case &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Any node can be leader, no single point of failure required to coordinate system&lt;/li&gt;
&lt;li&gt;System doing complex work that need good coordination 

&lt;ul&gt;
&lt;li&gt;eg. compute how protein folds. cluster needs leader node to assign each node to work on different part then add results together&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;System executes many distributed writes to data &amp;amp; requires &lt;em&gt;strong consistency&lt;/em&gt;

&lt;ul&gt;
&lt;li&gt;no matter which node handles request user will always have most up-to-date version of data. &lt;/li&gt;
&lt;li&gt;leader creates consistency by being source of truth on what the most recent state of system is. &lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;&lt;u&gt; Drawbacks &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;split brain

&lt;ul&gt;
&lt;li&gt;bad implementation -&amp;gt; 2 nodes controlling system&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;single point of failure / bottleneck&lt;/li&gt;
&lt;li&gt;leader starts making bad decisions entire system will follow&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://igotanoffer.com/blogs/tech/leader-election-system-design-interview"&gt;iGotAnOffer&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;MQ Benefits&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Resilience

&lt;ul&gt;
&lt;li&gt;app specific faults wont impact system&lt;/li&gt;
&lt;li&gt;if one component fails, all others can continue interacting with queue, processing / producing messages. &lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;&lt;small&gt;Reference: &lt;a href="https://www.ibm.com/cloud/learn/message-queues"&gt;IBM&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Core Java / Java Theory</title>
      <dc:creator>limjy</dc:creator>
      <pubDate>Thu, 27 May 2021 16:02:23 +0000</pubDate>
      <link>https://dev.to/jing/core-java-java-theory-ge</link>
      <guid>https://dev.to/jing/core-java-java-theory-ge</guid>
      <description>&lt;p&gt;Theory stuff about Java &lt;/p&gt;

&lt;p&gt;Content here is &lt;strong&gt;not original&lt;/strong&gt;. It is my summary of the following resources &lt;br&gt;
References:&lt;br&gt;
This &lt;a href="https://medium.com/edureka/java-oop-cheat-sheet-9c6ebb5e1175" rel="noopener noreferrer"&gt;medium post by Edureka&lt;/a&gt; (along with other articles in the series) are insanely good  &lt;/p&gt;

&lt;p&gt;in28Minutes github - this is a great resource for interview prep. (&lt;small&gt; However do double check with other sources. I find their explanation of encapsulation &amp;amp; unchecked VS checked exception strange &lt;/small&gt;)&lt;/p&gt;

&lt;p&gt;Other good resources:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://javarevisited.blogspot.com/2013/08/10-equals-and-hashcode-interview.html" rel="noopener noreferrer"&gt;javarevisited&lt;/a&gt; is a very good resource for in-depth questions. It's good for harder / obscure questions and makes your understanding clearer by doing a deep dive. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.edureka.co/blog/interview-questions/oops-interview-questions/" rel="noopener noreferrer"&gt;https://www.edureka.co/blog/interview-questions/oops-interview-questions/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Quick Summaries of OOP:&lt;br&gt;
&lt;a href="https://blog.udemy.com/oops-interview-questions/" rel="noopener noreferrer"&gt;https://blog.udemy.com/oops-interview-questions/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://blog.udemy.com/oop-interview-questions/" rel="noopener noreferrer"&gt;https://blog.udemy.com/oop-interview-questions/&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  TOC
&lt;/h1&gt;
&lt;h4&gt;
  
  
  Java Stuff
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Language

&lt;ul&gt;
&lt;li&gt;statically typed&lt;/li&gt;
&lt;li&gt;class-based&lt;/li&gt;
&lt;li&gt;object-oriented programming&lt;/li&gt;
&lt;li&gt;not pure OOP&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Execution System

&lt;ul&gt;
&lt;li&gt;platform independence&lt;/li&gt;
&lt;li&gt;JVM, JDK, JRE&lt;/li&gt;
&lt;li&gt;Just-In-Time Compilation&lt;/li&gt;
&lt;li&gt;Memory Management&lt;/li&gt;
&lt;li&gt;java heap space VS stack memory&lt;/li&gt;
&lt;li&gt;garbage collection&lt;/li&gt;
&lt;li&gt;comparison to Python&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Java syntax
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Basics

&lt;ul&gt;
&lt;li&gt;Objects &amp;amp; classes&lt;/li&gt;
&lt;li&gt;Variables &amp;amp; methods&lt;/li&gt;
&lt;li&gt;method signature&lt;/li&gt;
&lt;li&gt;Packages&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Modifiers (Access &amp;amp; Non-access modifiers)

&lt;ul&gt;
&lt;li&gt;access modifiers&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Non access modifiers

&lt;ul&gt;
&lt;li&gt;
abstract keyword

&lt;ul&gt;
&lt;li&gt;illegal modifiers with abstract&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;final-keyword&lt;/li&gt;
&lt;li&gt;static-keyword&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  block
&lt;/h4&gt;

&lt;p&gt;-static VS instance block&lt;/p&gt;
&lt;h4&gt;
  
  
  Wrapper Class
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;immutable&lt;/li&gt;
&lt;li&gt;why wrapper classes&lt;/li&gt;
&lt;li&gt;constructor VS valueOf&lt;/li&gt;
&lt;li&gt;
Autoboxing &amp;amp; Unboxing

&lt;ul&gt;
&lt;li&gt;autoboxing unboxing advantages&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
Typecasting

&lt;ul&gt;
&lt;li&gt;implicit/widening&lt;/li&gt;
&lt;li&gt;explicit/narrowing&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Strings
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.javatpoint.com/java-string#:~:text=interfaces-,CharSequence%20Interface,The,-CharSequence" rel="noopener noreferrer"&gt;Implements CharSequence Interface&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;immutability&lt;/li&gt;
&lt;li&gt;
where are strings stored in memory

&lt;ul&gt;
&lt;li&gt;String pool&lt;/li&gt;
&lt;li&gt;heap &amp;amp; stack &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;String Interning&lt;/li&gt;
&lt;li&gt;how many objects created in new String()&lt;/li&gt;
&lt;li&gt;String (+) is bad in loop&lt;/li&gt;
&lt;li&gt;String VS StringBuffer&lt;/li&gt;
&lt;li&gt;StringBuilder VS StringBuffer&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Objects class / Java Objects basics
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
What is a class

&lt;ul&gt;
&lt;li&gt;state&lt;/li&gt;
&lt;li&gt;behaviour&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;What is an object&lt;/li&gt;
&lt;li&gt;== VS equals()&lt;/li&gt;
&lt;li&gt;super class of every class&lt;/li&gt;
&lt;li&gt;toString metho&lt;/li&gt;
&lt;li&gt;
equals() method

&lt;ul&gt;
&lt;li&gt;equals() method critera&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
hashCode() method

&lt;ul&gt;
&lt;li&gt;hashCode() method criteria&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;importance of equals() &amp;amp; hashCode()&lt;/li&gt;
&lt;li&gt;instanceOf VS getClass&lt;/li&gt;
&lt;li&gt;Object class Inheritance&lt;/li&gt;
&lt;li&gt;[constructors]&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Data Structure Implementations(&lt;small&gt; knpcode.com has really good tutorials and  write ups for DS implementations &lt;/small&gt;)
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;HashMap

&lt;ul&gt;
&lt;li&gt;
how hashmap works internally

&lt;ul&gt;
&lt;li&gt;16 initial buckets, 0.75 load factor, threshold of 12&lt;/li&gt;
&lt;li&gt;hashCode for bucket index calculation&lt;/li&gt;
&lt;li&gt;LinkedList for collision&lt;/li&gt;
&lt;li&gt;equals() to compare keys&lt;/li&gt;
&lt;li&gt;rehashing when meet threshold, buckets are doubled &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;null key added&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;HashSet

&lt;ul&gt;
&lt;li&gt;
hashset internal implementation in Java

&lt;ul&gt;
&lt;li&gt;implemented with hashmap&lt;/li&gt;
&lt;li&gt;set element are hashmap keys&lt;/li&gt;
&lt;li&gt;all hashmap values are a dummy object.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;ArrayList

&lt;ul&gt;
&lt;li&gt;capacity VS size&lt;/li&gt;
&lt;li&gt;
how arraylist works internally

&lt;ul&gt;
&lt;li&gt;implemented with array&lt;/li&gt;
&lt;li&gt;initial capacity of 10 &lt;/li&gt;
&lt;li&gt;grows 50% when no space&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Vector

&lt;ul&gt;
&lt;li&gt;
Java vector class

&lt;ul&gt;
&lt;li&gt;thread safe arraylist&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Stack

&lt;ul&gt;
&lt;li&gt;
how is stack implemented by java

&lt;ul&gt;
&lt;li&gt;empty on creation&lt;/li&gt;
&lt;li&gt;dynamic array &lt;em&gt;NOT linkedlist&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Queue

&lt;ul&gt;
&lt;li&gt;
queue implementations in Java

&lt;ul&gt;
&lt;li&gt;interface not a class&lt;/li&gt;
&lt;li&gt;implemented by PriorityQueue &amp;amp; LinkedList&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Java Implementations / Interfaces / Common Classes (&lt;small&gt; will only go through &lt;a href="https://docs.oracle.com/javase/tutorial/collections/implementations/index.html" rel="noopener noreferrer"&gt;general-purpose implementations&lt;/a&gt; coz no time &lt;/small&gt;)
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
Map Implementations

&lt;ul&gt;
&lt;li&gt;HashMap&lt;/li&gt;
&lt;li&gt;TreeMap&lt;/li&gt;
&lt;li&gt;LinkedHashMap&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
Set Implementations

&lt;ul&gt;
&lt;li&gt;HashSet&lt;/li&gt;
&lt;li&gt;TreeSet&lt;/li&gt;
&lt;li&gt;LinkedHashSet&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
List Implementations

&lt;ul&gt;
&lt;li&gt;ArrayList&lt;/li&gt;
&lt;li&gt;LinkedList&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Queue Implementations (see above)

&lt;ul&gt;
&lt;li&gt;PriorityQueue&lt;/li&gt;
&lt;li&gt;LinkedList&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Dequeue Implementations (double-ended queue) (&lt;small&gt; going to skip this &lt;/small&gt;)

&lt;ul&gt;
&lt;li&gt;LinkedList&lt;/li&gt;
&lt;li&gt;ArrayDequeue&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  OOP Concepts &amp;amp; OOP in Java(&lt;small&gt; references in this section mainly from educative articles: &lt;a href="https://www.educative.io/blog/object-oriented-programming#what-is" rel="noopener noreferrer"&gt;OOP&lt;/a&gt; &amp;amp; &lt;a href="https://www.educative.io/blog/object-oriented-programming-concepts-java" rel="noopener noreferrer"&gt;OOP in Java&lt;/a&gt;&lt;/small&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;What is OOP&lt;/li&gt;
&lt;li&gt;4 Pillars of OOP

&lt;ul&gt;
&lt;li&gt;
inheritance

&lt;ul&gt;
&lt;li&gt;Types of Inheritance&lt;/li&gt;
&lt;li&gt;single inheritance&lt;/li&gt;
&lt;li&gt;multilevel&lt;/li&gt;
&lt;li&gt;multiple&lt;/li&gt;
&lt;li&gt;hierarchical&lt;/li&gt;
&lt;li&gt;hybrid&lt;/li&gt;
&lt;li&gt;inheritance-in-java&lt;/li&gt;
&lt;li&gt;extends VS implements&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
Abstraction

&lt;ul&gt;
&lt;li&gt;abstraction in java&lt;/li&gt;
&lt;li&gt;abstract class VS interface&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
Encapsulation

&lt;ul&gt;
&lt;li&gt;
encapsulation in java

&lt;ul&gt;
&lt;li&gt;getters &amp;amp; setters &lt;/li&gt;
&lt;li&gt;tight encapsulation&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
Polymorphism

&lt;ul&gt;
&lt;li&gt;compile time VS runtime&lt;/li&gt;
&lt;li&gt;
method overloading
&lt;/li&gt;
&lt;li&gt;method overloading conditions&lt;/li&gt;
&lt;li&gt;method overriding&lt;/li&gt;
&lt;li&gt;
method overriding rules

&lt;ul&gt;
&lt;li&gt;
overriding VS hiding (static methods) &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Abstraction VS Encapsulation (&lt;a href="https://stackoverflow.com/a/51304341" rel="noopener noreferrer"&gt;https://stackoverflow.com/a/51304341&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Relationships (&lt;a href="https://www.c-sharpcorner.com/UploadFile/3614a6/is-a-and-has-a-relationship-in-java/" rel="noopener noreferrer"&gt;https://www.c-sharpcorner.com/UploadFile/3614a6/is-a-and-has-a-relationship-in-java/&lt;/a&gt;)

&lt;ul&gt;
&lt;li&gt;IS-A relationship (inheritance)&lt;/li&gt;
&lt;li&gt;HAS-A relationship (composition)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Other concepts

&lt;ul&gt;
&lt;li&gt;
Association

&lt;ul&gt;
&lt;li&gt;association (2 classes have a link, need to communicate between them)&lt;/li&gt;
&lt;li&gt;aggregation (weak association, child can exist independently of the parent)&lt;/li&gt;
&lt;li&gt;composition (strong association, child cannot exist independent of parent)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/a/10394722" rel="noopener noreferrer"&gt;association VS aggregation VS composition&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Coupling&lt;/li&gt;
&lt;li&gt;Cohesion&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Java Exception Handling (&lt;small&gt;&lt;a href="https://www.journaldev.com/1696/exception-handling-in-java" rel="noopener noreferrer"&gt;JournalDev Exception Handling article&lt;/a&gt; primarily used as reference for this section &lt;/small&gt;)
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;runtime exceptions&lt;/li&gt;
&lt;li&gt;
exception handling keyword

&lt;ul&gt;
&lt;li&gt;try&lt;/li&gt;
&lt;li&gt;catch&lt;/li&gt;
&lt;li&gt;finally&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
Java Exception Hierarchy

&lt;ul&gt;
&lt;li&gt;Unchecked VS Runtime Exception&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Exception Class Methods&lt;/li&gt;
&lt;li&gt;Excpetion Handling criteria&lt;/li&gt;
&lt;li&gt;Exception Handling Best Practice&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  OOP Concepts
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;SOLID (&lt;a href="https://www.baeldung.com/solid-principles" rel="noopener noreferrer"&gt;https://www.baeldung.com/solid-principles&lt;/a&gt;)

&lt;ul&gt;
&lt;li&gt;single responsibility&lt;/li&gt;
&lt;li&gt;openfor extension closed to modfication&lt;/li&gt;
&lt;li&gt;lishov subsitution (sub subclass for base class)&lt;/li&gt;
&lt;li&gt;interface segregation (split big interface itno smaller ones)&lt;/li&gt;
&lt;li&gt;dependency inversion (depend on abstract classes/ interfaces instead of classes)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  UML
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;needed to understand different design patterns&lt;/li&gt;
&lt;li&gt;
Class Diagram

&lt;ul&gt;
&lt;li&gt;Association&lt;/li&gt;
&lt;li&gt;inheritance / generalization / abstraction&lt;/li&gt;
&lt;li&gt;multiplicty&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Sequence Diagram&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Design Patterns
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Creational

&lt;ul&gt;
&lt;li&gt;singleton&lt;/li&gt;
&lt;li&gt;factory &amp;amp; abstract factory&lt;/li&gt;
&lt;li&gt;Builder&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Structural

&lt;ul&gt;
&lt;li&gt;decorator&lt;/li&gt;
&lt;li&gt;flyweight&lt;/li&gt;
&lt;li&gt;adapter&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Behavioural 

&lt;ul&gt;
&lt;li&gt;
observer &lt;/li&gt;
&lt;li&gt;strategy&lt;/li&gt;
&lt;li&gt;state&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;MultiThreading&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;thread VS process&lt;/li&gt;
&lt;li&gt;Threads &amp;amp; Runnable&lt;/li&gt;
&lt;li&gt;Thread VS Runnable&lt;/li&gt;
&lt;li&gt;keywords

&lt;ul&gt;
&lt;li&gt;synchronized&lt;/li&gt;
&lt;li&gt;volatile&lt;/li&gt;
&lt;li&gt;wait() &lt;/li&gt;
&lt;li&gt;notify()&lt;/li&gt;
&lt;li&gt;notifyAll()
&lt;a href="https://howtodoinjava.com/java/multi-threading/wait-notify-and-notifyall-methods/" rel="noopener noreferrer"&gt;https://howtodoinjava.com/java/multi-threading/wait-notify-and-notifyall-methods/&lt;/a&gt;
&lt;a href="https://dzone.com/articles/difference-between-volatile-and-synchronized-keywo" rel="noopener noreferrer"&gt;https://dzone.com/articles/difference-between-volatile-and-synchronized-keywo&lt;/a&gt;
&lt;a href="https://stackoverflow.com/a/3519736" rel="noopener noreferrer"&gt;https://stackoverflow.com/a/3519736&lt;/a&gt;
&lt;a href="https://howtodoinjava.com/java/multi-threading/java-runnable-vs-thread/" rel="noopener noreferrer"&gt;https://howtodoinjava.com/java/multi-threading/java-runnable-vs-thread/&lt;/a&gt;
&lt;a href="https://stackoverflow.com/a/15471504" rel="noopener noreferrer"&gt;https://stackoverflow.com/a/15471504&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Statically Typed&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Reference: &lt;a href="https://docs.oracle.com/cd/E57471_01/bigData.100/extensions_bdd/src/cext_transform_typing.html" rel="noopener noreferrer"&gt;Oracle Documentation&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;perform type checking at compile time&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;provides &lt;em&gt;type safety&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;if Java code contains errors, it will fail to compile until the errors have been fixed&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;declare data types of variables before you use them&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;int num; num = 5;&lt;/code&gt; VS &lt;code&gt;num =5&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;expects variables to be declared before it can be assigned value. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Opposite of statically typed is &lt;strong&gt;dynamically-typed&lt;/strong&gt; (eg. python)&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Class based&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Reference: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Details_of_the_Object_Model" rel="noopener noreferrer"&gt;mozilla developer docs&lt;/a&gt; &amp;amp; &lt;a href="https://stackoverflow.com/a/11620705" rel="noopener noreferrer"&gt;stack overflow&lt;/a&gt; &amp;amp; &lt;a href="https://li60.zendesk.com/hc/en-us/articles/115002448751-Class-based-vs-prototype-based-languages" rel="noopener noreferrer"&gt;zendesk&lt;/a&gt; &amp;amp; &lt;a href="https://en.wikipedia.org/wiki/Class-based_programming" rel="noopener noreferrer"&gt;wikipedia&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Class based programming / class-orientation is a style of Object-oriented programming (OOP)&lt;br&gt;
&lt;u&gt;Class-based&lt;/u&gt;: makes distinction between objects &amp;amp; class.&lt;br&gt;
&lt;u&gt;prototype-based&lt;/u&gt;: no distinction. It has objects. start with an instance / object &amp;amp; modify it. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Defining class

&lt;ul&gt;
&lt;li&gt;define class in class definition &amp;amp; specify methods (constructors) to create instances of the class.&lt;/li&gt;
&lt;li&gt;
&lt;u&gt; prototype &lt;/u&gt;: class definition not separate from constructor. constructor function creates object with initial set of properties &amp;amp; values&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Subclass / inheritance

&lt;ul&gt;
&lt;li&gt;create heirachy via class definition &lt;code&gt;Manager extends Employee&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;prototype&lt;/u&gt;: associate object with any construtor function. (call another object in the constructor function of subclass)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Adding &amp;amp; removing properties

&lt;ul&gt;
&lt;li&gt;cannot change type / number of properties after class definition&lt;/li&gt;
&lt;li&gt;class created at compile time &amp;amp; objects instantiated at compile or run time&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;prototype&lt;/u&gt;: ca remove or add properties of any object at run time. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Opposite of class based is &lt;strong&gt;protoype-based / object-based&lt;/strong&gt; (eg. javascript)&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;What is Object-oriented programming&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Reference: &lt;a href="https://en.wikipedia.org/wiki/Object-oriented_programming" rel="noopener noreferrer"&gt;wiki&lt;/a&gt; &amp;amp; &lt;a href="https://www.educative.io/blog/object-oriented-programming" rel="noopener noreferrer"&gt;educative&lt;/a&gt; &amp;amp; &lt;a href="https://www.educative.io/courses/learn-object-oriented-programming-in-javascript/B19oGJg5JWo" rel="noopener noreferrer"&gt;educative - Oop JS&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;OOP is a &lt;em&gt;programming paradigm&lt;/em&gt; based on the concept of "objects".&lt;br&gt;
Program is broken down  into segments of &lt;em&gt;objects&lt;/em&gt; that communicate with each other.&lt;br&gt;
Each objct is define by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;its functions (called &lt;strong&gt;methods&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;its data (called &lt;strong&gt;properties&lt;/strong&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is a general overview of OOP. as seen in previous section that are also different "styles" of OOP (object-based &amp;amp; class-based).&lt;/p&gt;

&lt;p&gt;From some articles we can also see the question "Is  a OOP langauge?" is not a straight forward yes or no answer. &lt;/p&gt;

&lt;p&gt;To be OOP language, programming language has to satisfy a list of OOP condition / properties. Depending on whether programming language has satisfied some / all OOP conditions we can then say "yes" or "no". &lt;br&gt;
Even if the answer is "yes" programming language is OO. There is still the question of "is  &lt;em&gt;purely&lt;/em&gt; object-oriented?"&lt;/p&gt;

&lt;p&gt;&lt;u&gt; Alternatives / Opposite &lt;/u&gt;&lt;br&gt;
There is no "opposite" of object -oriented proramming. But there are different programming paradigms like: (reference: &lt;a href="https://stackoverflow.com/a/6295260" rel="noopener noreferrer"&gt;SO&lt;/a&gt;)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;procedural&lt;/li&gt;
&lt;li&gt;fuctional
etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Java not pure OOP&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Reference: &lt;a href="https://www.geeksforgeeks.org/java-not-purely-object-oriented-language/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt; &amp;amp; &lt;a href="https://data-flair.training/blogs/is-java-an-object-oriented-language/" rel="noopener noreferrer"&gt;dataflair&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Java is &lt;strong&gt;not a pure object-oriented language&lt;/strong&gt;. Because it has:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;primitive data type&lt;/li&gt;
&lt;li&gt;static keyword&lt;/li&gt;
&lt;li&gt;wrapper class&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;To fulfill pure OOP, language must satisfy all 7 conditions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Encapsulation / Data Hiding&lt;/li&gt;
&lt;li&gt;inheritance&lt;/li&gt;
&lt;li&gt;polymorphism&lt;/li&gt;
&lt;li&gt;abstraction&lt;/li&gt;
&lt;li&gt;All predefined types are objects&lt;/li&gt;
&lt;li&gt;All user defined types are objects&lt;/li&gt;
&lt;li&gt;All operations performed on objects must be only through methods exposed at objects&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;Java fails condition 5(&lt;em&gt;all predefined types are objects&lt;/em&gt;) &amp;amp; 7(&lt;em&gt;operations performed on objects must be only through methods exposed at objects&lt;/em&gt;)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;primitive data types

&lt;ul&gt;
&lt;li&gt;primitives are &lt;a href="https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html#:~:text=new%20keyword%20isn't%20used%20when%20initializing%20a%20variable%20of%20a%20primitive%20type.%20primitive%20types%20are%20special%20data%20types%20built%20into%20the%20language%3B%20they%20are%20not%20objects%20created%20from%20a%20class" rel="noopener noreferrer"&gt;not objects&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;static keyword

&lt;ul&gt;
&lt;li&gt;when class is static, it can be used without objects&lt;/li&gt;
&lt;li&gt;static function / variables. can be called without creating an object of class.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Wrapper class

&lt;ul&gt;
&lt;li&gt;unboxing: when using arithemtic operators (% or +=) are performed on wrapper classes. compiler &lt;a href="https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html#:~:text=remainder%20(%25)%20and%20unary%20plus%20(%2B%3D)%20operators%20do%20not%20apply%20to%20integer%20objects%2C%20you%20may%20wonder%20why%20the%20java%20compiler%20compiles%20the%20method%20without%20issuing%20any%20errors.%20the%20compiler%20does%20not%20generate%20an%20error%20because%20it%20invokes%20the%20intvalue%20method%20to%20convert%20an%20integer%20to%20an%20int%20at%20runtime%3A" rel="noopener noreferrer"&gt;converts object to primitive datatype&lt;/a&gt; at runtime. Thus violating condition 5 (primitive types are not objects) &lt;/li&gt;
&lt;li&gt;arithmetic operations on object &lt;code&gt;String test = "hello" + " world"&lt;/code&gt; use of arithmetic operations on wrapper class also violate condition 7 (can communicate with objects with calling their methods)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Java platform Independent&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Java is WORA (Write once Run anywhere). java source code can run on all operating systems. &lt;br&gt;
byte code (.class) generated by javac compiler can be executed on any OS. Bytecode is understandable is any JVM installed on any OS. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;JAVA is platform-independent language, the JVM is platform-dependent.&lt;/strong&gt;&lt;br&gt;
must install different JVM for different OS.&lt;/p&gt;

&lt;p&gt;JVM will convert bytecode (.class) to machine code&lt;br&gt;
Since machine code is run, this makes run time faster. &lt;/p&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://www.javatpoint.com/features-of-java" rel="noopener noreferrer"&gt;javatpoint&lt;/a&gt; &amp;amp; &lt;a href="https://www.codingninjas.com/blog/2020/10/26/how-is-java-platform-independent/" rel="noopener noreferrer"&gt;codingningjas&lt;/a&gt; &amp;amp; &lt;a href="https://www.guru99.com/java-platform.html#14" rel="noopener noreferrer"&gt;guru99&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Java: JVM, JRE, JDK&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ibjak3ccfhcwfpglabx.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%2F2ibjak3ccfhcwfpglabx.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;JDK&lt;/strong&gt;: Java development Kit&lt;br&gt;
software development environment used for making applets &amp;amp; Java applications. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JRE + compiler + debugger 
&lt;strong&gt;JRE&lt;/strong&gt;: Java Runtime Environment
software designed to run other software.  To &lt;strong&gt;run Java&lt;/strong&gt; you &lt;strong&gt;need JRE&lt;/strong&gt;. It contains class libraries, loader class &amp;amp; JVM. &lt;/li&gt;
&lt;li&gt;JVM + libraries + other components (to run applets / java applications) 
&lt;strong&gt;JVM&lt;/strong&gt;: &lt;/li&gt;
&lt;li&gt;Virtual machine running java bytecode&lt;/li&gt;
&lt;li&gt;maeks java portable &lt;/li&gt;
&lt;li&gt;comes with JIT(Just-In-Time) compiler that converts java source code to low-level machine langauge. &lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://www.guru99.com/difference-between-jdk-jre-jvm.html#13" rel="noopener noreferrer"&gt;guru99&lt;/a&gt; &amp;amp; &lt;a href="https://www.javatpoint.com/difference-between-jdk-jre-and-jvm" rel="noopener noreferrer"&gt;javatpoint&lt;/a&gt; &amp;amp; &lt;a href="https://www.geeksforgeeks.org/differences-jdk-jre-jvm/" rel="noopener noreferrer"&gt;geeksforgeeks&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Java JIT Compilation&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Just-In-Time (JIT) Compilation also known as &lt;em&gt;dynamic compilation&lt;/em&gt;.&lt;br&gt;
Program is compiled to native code during runtime to improve performance. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In JIT compilation,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;translates bytecode(.class) to machine code instructions of running machines

&lt;ul&gt;
&lt;li&gt;resulting machine code is &lt;strong&gt;optimized for running machine's CPU architecture&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;compilation is done at runtime of program (as opposed to prior to execution)&lt;/li&gt;
&lt;li&gt;since compilation takes place in run time, JIT compiler has access t dynamic runtime information enabling it to mae better optimizations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The hope is that the efficiency of running machine code will overcome inefficiency of recompiling program every time it runs. &lt;/p&gt;

&lt;p&gt;&lt;u&gt;Optimizations&lt;/u&gt;&lt;br&gt;
JVM execute bytecode &amp;amp; mantians count of how many times function is executed&lt;br&gt;
If count exceeds pre-defined limit, JIT compiles code into machine lanaguage that can directly be execute by processor. &lt;/p&gt;

&lt;p&gt;Next time, function is calaculated, compiled code is executed again unlike normal interpretatio --&amp;gt; faster execution&lt;/p&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://www.freecodecamp.org/news/just-in-time-compilation-explained/" rel="noopener noreferrer"&gt;freeCodeCamp&lt;/a&gt; &amp;amp; &lt;a href="https://www.geeksforgeeks.org/just-in-time-compiler/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt; &amp;amp; &lt;a href="https://www.javatpoint.com/jit-in-java" rel="noopener noreferrer"&gt;javatpoint&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Memory Managment in Java&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Memory management is the process of allocation &amp;amp; de-allocation of objects. Java uses automatic memory management system called &lt;strong&gt;garbage collector&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://www.javatpoint.com/memory-management-in-java" rel="noopener noreferrer"&gt;javatpoint&lt;/a&gt; &amp;amp; &lt;a href="https://docs.oracle.com/cd/E13150_01/jrockit_jvm/jrockit/geninfo/diagnos/garbage_collect.html" rel="noopener noreferrer"&gt;oracle docs&lt;/a&gt; &amp;amp; &lt;a href="https://medium.com/@peterlee2068/java-memory-management-37f5483b23c1" rel="noopener noreferrer"&gt;peter lee medium&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt; Java: Heap Space VS Stack Memory&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;To run application in optiomal way, JVM divide memory into stack &amp;amp; heap memory&lt;br&gt;
&lt;u&gt;Stack&lt;/u&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;used for execution of thread&lt;/li&gt;
&lt;li&gt;primitive values specific to a method&lt;/li&gt;
&lt;li&gt;references to objects that are in a heap, referred from method.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;thread-safe&lt;/em&gt;: eahc thread operated in its own stack
&lt;u&gt;Heap&lt;/u&gt;: &lt;/li&gt;
&lt;li&gt;actual objects &lt;/li&gt;
&lt;li&gt;dynamic memory allocation for Java objects &amp;amp; JRE classes at runtime&lt;/li&gt;
&lt;li&gt;String Pool&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;not thread-safe&lt;/em&gt;: needs to be guarded by properly synchronizing code&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;New objects are always created in heap space and the references to this objects are stored in stack memory. When the heap becomes full, garbage is collected. So, no longer used are cleared, thus making space for new objects. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Heap

&lt;ul&gt;
&lt;li&gt;created when JVM starts up &amp;amp; may increase/decrease in size while application runs&lt;/li&gt;
&lt;li&gt;when heap is full, &lt;strong&gt;garbage is collected&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;new objects created in heap space &lt;em&gt;references to objects stored in stack memory&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;objects have &lt;strong&gt;global access&lt;/strong&gt; and can be accessed from anywhere in the application, not thread safe&lt;/li&gt;
&lt;li&gt;Broken down to 3 parts&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Young Generation&lt;/strong&gt;: all new objects are allocated &amp;amp; aged.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Old / Tenured Generation&lt;/strong&gt;: long surviving objects stored. object stored in young gen, threshold for its age set. when threshold reached. Object moved to old gen&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Permanent Generation&lt;/strong&gt;: JVM metatdata for runtime classes &amp;amp; application methods.&lt;/li&gt;
&lt;li&gt;When heap becomes full garbage is collected&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Stack

&lt;ul&gt;
&lt;li&gt;referenced in LIFO order&lt;/li&gt;
&lt;li&gt;when new method is called, new block on top of stack is created which contains values specific to that method (eg. primitive variables &amp;amp; references to objets)&lt;/li&gt;
&lt;li&gt;method finish execution -&amp;gt; corresponding stack frame is flushed, flow goes back to calling method. space available for next method
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.journaldev.test;

public class Memory {

    public static void main(String[] args) { // Line 1
        int i=1; // Line 2
        Object obj = new Object(); // Line 3
        Memory mem = new Memory(); // Line 4
        mem.foo(obj); // Line 5
    } // Line 9

    private void foo(Object param) { // Line 6
        String str = param.toString(); //// Line 7
        System.out.println(str);
    } // Line 8

}

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

&lt;/div&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%2F87mmh1sljdvhamz5yq03.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%2F87mmh1sljdvhamz5yq03.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run program -&amp;gt; load runtime classes to Heap space&lt;/li&gt;
&lt;li&gt;main() method found at line 1, runtime create stack mem to be used by main() method thread.
Whenever new object created,&lt;/li&gt;
&lt;li&gt;object created in heap memory&lt;/li&gt;
&lt;li&gt;stack memory contains the reference for it. &lt;/li&gt;
&lt;li&gt;when new method called -&amp;gt; new block created &lt;strong&gt;on top&lt;/strong&gt; of stack (LIFO)&lt;/li&gt;
&lt;li&gt;String, reference in stack mem -&amp;gt; reference points to String pool in heap space&lt;/li&gt;
&lt;li&gt;when method (foo())terminates, stack becomes free (stack mem created for function destroyed) &lt;/li&gt;
&lt;li&gt;move to next program below (main())&lt;/li&gt;
&lt;/ol&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%2Fdevxpspb94etd10loiem.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%2Fdevxpspb94etd10loiem.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://stackify.com/java-heap-vs-stack/" rel="noopener noreferrer"&gt;stackify&lt;/a&gt; &amp;amp; &lt;a href="https://www.baeldung.com/java-stack-heap" rel="noopener noreferrer"&gt;baledung&lt;/a&gt; &amp;amp; &lt;a href="https://www.journaldev.com/4098/java-heap-space-vs-stack-memory" rel="noopener noreferrer"&gt;JournalDev&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Java Garbage Collection&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;GC: Process by which Java performs automatic memory management&lt;br&gt;
When Java programs run on JVM, objects are created on the &lt;strong&gt;heap&lt;/strong&gt;. When some objects no longer needed. GC will find the, delete them to free up memory.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;4 garbage collectors: &lt;small&gt;planning to bomb this if asked &lt;/small&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;serial&lt;/li&gt;
&lt;li&gt;parallel&lt;/li&gt;
&lt;li&gt;concurrent mark sweep&lt;/li&gt;
&lt;li&gt;G1 (h=garbage first)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Benefits &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;automatically handles deletion of unused objects / objects out of reach to free up virtual memory resources. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://stackify.com/what-is-java-garbage-collection/#:~:text=Java%20garbage%20collection%20is%20the,Machine%2C%20or%20JVM%20for%20short.&amp;amp;text=The%20garbage%20collector%20finds%20these,them%20to%20free%20up%20memory." rel="noopener noreferrer"&gt;stackify&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Java: Comparison to Python&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Java programs expected to run &lt;strong&gt;faster&lt;/strong&gt; than python&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python tun time typing, python run time "works harder" than java (more tasks to do&lt;/li&gt;
&lt;li&gt;python run time must inspect objects and find type then invoke operation&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Java programs take &lt;strong&gt;longer time to develop&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Java programs are &lt;strong&gt;longer (number of lines of code)&lt;/strong&gt; than python&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;java is statically typed&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;small&gt;Reference: &lt;a href="https://www.python.org/doc/essays/comparisons/" rel="noopener noreferrer"&gt;python org&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Objects &amp;amp; Classes&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Class&lt;/em&gt;: user defined blueprint from which object is created&lt;br&gt;
&lt;em&gt;Object&lt;/em&gt;: basic unit of OOP, instance of a class. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;objects can be created from class via constructor. There are 2 kinds&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Default / non-parameterised

&lt;ul&gt;
&lt;li&gt;0 arguments&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Parameterised

&lt;ul&gt;
&lt;li&gt;constructors have specific number of arguments to be passed&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;constructor cannot be abstract final or static&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Variables &amp;amp; Methods&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Types of variables&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;local&lt;/li&gt;
&lt;li&gt;instance&lt;/li&gt;
&lt;li&gt;static&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;each object has own copy of instance variable however, all objects will share only one copy of static variable &lt;/p&gt;
&lt;/blockquote&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%2Flbcosjofnlbb48ipnym0.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%2Flbcosjofnlbb48ipnym0.png" alt="alt text"&gt;&lt;/a&gt;&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%2Fuploads%2Farticles%2F23qr93dcekwyg3mb0n65.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%2F23qr93dcekwyg3mb0n65.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt; Methods &lt;/u&gt;&lt;br&gt;
Methods consist of&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;modifier

&lt;ul&gt;
&lt;li&gt;eg. private / public&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;return type&lt;/li&gt;
&lt;li&gt;method name&lt;/li&gt;
&lt;li&gt;parameters&lt;/li&gt;
&lt;li&gt;method body / logic&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;static methods belong to a class, no need to instantiate object to use the method&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Method Signature&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Method signature is &lt;code&gt;&amp;lt;method name&amp;gt;()&amp;lt;argument types&amp;gt;)&lt;/code&gt; &lt;br&gt;
Does &lt;strong&gt;NOT include&lt;/strong&gt;: access modifier &amp;amp; return type&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In java, you &lt;strong&gt;cannot have &amp;gt;=2 methods with same method signature in the same class&lt;/strong&gt; (even if methods have different return types)&lt;br&gt;
&lt;/p&gt;

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

// ERROR: duplicate method Signature
public String display(String info){
  // logic
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;a&gt;Packages&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Group of classes &amp;amp; interfaces &amp;amp; sub-packages which has similar functionalities. &lt;br&gt;
Provide folder structure to organise classes &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;packages naming style: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;lower case&lt;/li&gt;
&lt;li&gt;reverse domain&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Access Modifiers&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Modifiers set accessibility of classes or methods or any memebers&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;public &lt;/li&gt;
&lt;li&gt;private&lt;/li&gt;
&lt;li&gt;protected&lt;/li&gt;
&lt;li&gt;default (no modifiers)&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F08e90tnpnpy0idpdewjj.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%2F08e90tnpnpy0idpdewjj.png" alt="alt text"&gt;&lt;/a&gt;&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%2Fuploads%2Farticles%2Fhex8luco8jf70wborw5l.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%2Fhex8luco8jf70wborw5l.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="http://tutorials.jenkov.com/java/access-modifiers.html" rel="noopener noreferrer"&gt;Jenkov tutorials&lt;/a&gt; &amp;amp; &lt;a href="https://www.geeksforgeeks.org/access-modifiers-java/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Abstract Keyword&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;non-access modifier applicable for classes and methods but &lt;strong&gt;not variables&lt;/strong&gt;&lt;br&gt;
Used to achieve abstraction in Java (one of the pillars of OOP)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt; Abstract class &lt;/u&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;cannot create / instantiate object of abstract class&lt;br&gt;
Any subclass of abstract class must either implement all abstract methods or be declared abstract itself.&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract class class-name{
    //body of class
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Due to partial implementation of classes, object cannot be instantiated. &lt;br&gt;
Abstract class depend on subclass to provide complete implementation.&lt;br&gt;
Any sub &lt;/p&gt;

&lt;p&gt;&lt;u&gt; Abstract method&lt;/u&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Abstract method dont contain body. sub classes will implement them&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract type method-name(parameter-list);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;any class containing abstract method must be abstarct&lt;/li&gt;
&lt;li&gt;the following combinations of modifiers &lt;strong&gt;cannot&lt;/strong&gt; be used with abstract

&lt;ul&gt;
&lt;li&gt;final (class &amp;amp; method)&lt;/li&gt;
&lt;li&gt;private (method)&lt;/li&gt;
&lt;li&gt;static (method)&lt;/li&gt;
&lt;li&gt;synchronized (method)&lt;/li&gt;
&lt;li&gt;native / strictfp&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Further reading of abstract method on &lt;a href="https://javagoal.com/abstract-method-in-java/" rel="noopener noreferrer"&gt;Java Goal&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt; References: &lt;a href="https://www.geeksforgeeks.org/abstract-keyword-in-java/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt; &amp;amp; &lt;a href="https://www.javatpoint.com/abstract-keyword-in-java" rel="noopener noreferrer"&gt;javatpoint&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Abstract Illegal modifiers&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt; Abstract final &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Class: final used to prevent inheritance

&lt;ul&gt;
&lt;li&gt;Abstract classes depend on child classes to complete implementation. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Method: final used to prevent overidding
-abstarct method need to be overidden in sub classes&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Abstract private &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Method: private method cannot be accessed outside current class

&lt;ul&gt;
&lt;li&gt;child classes cannot access private abstract methods &amp;amp; cannot implement it. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Class: nested class. everything within class can access a nested private class

&lt;ul&gt;
&lt;li&gt;can have a nested private abstract class &lt;a href="https://stackoverflow.com/questions/23882308/private-abstract-classes-in-java" rel="noopener noreferrer"&gt;SO example&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;small&gt;Reference: &lt;a href="https://www.tutorialspoint.com/can-we-declare-an-abstract-method-private-protected-public-or-default-in-java" rel="noopener noreferrer"&gt;tutorialspoint&lt;/a&gt; &amp;amp; &lt;a href="https://stackoverflow.com/questions/2874350/cant-declare-an-abstract-method-private" rel="noopener noreferrer"&gt;stackoverflow&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt; Abstract static &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Method: static methods can be hidden &lt;strong&gt;but not overidden&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;abstract method must be overidden to be implemented. Static methods cannot be overidden, so they cannot be abstarct.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;small&gt;Reference: &lt;a href="https://www.tutorialspoint.com/Why-can-t-static-method-be-abstract-in-Java#:~:text=A%20static%20method%20belongs%20to,a%20static%20method%20as%20abstract." rel="noopener noreferrer"&gt;tutorialspoint&lt;/a&gt; &amp;amp; &lt;a href="https://stackoverflow.com/a/372544" rel="noopener noreferrer"&gt;stackoverflow&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt; Abstract synchronized&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Method: synchronised. thread gets lock on object on entering method

&lt;ul&gt;
&lt;li&gt;thread entering synchronized method must get lock of the object in which method is define. cannot instantiate abstract class so no object with lock. 
&lt;a href="https://javagoal.com/abstract-method-in-java/" rel="noopener noreferrer"&gt;https://javagoal.com/abstract-method-in-java/&lt;/a&gt;
&lt;a href="https://stackoverflow.com/a/12805823" rel="noopener noreferrer"&gt;https://stackoverflow.com/a/12805823&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Abstract strictfp&lt;/u&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;strictgp is a an access-modifier. no modifiers allowed on abstarct methods except public and protected. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Final Keyword&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;for &lt;strong&gt;classes, variables &amp;amp; methods&lt;/strong&gt; &lt;br&gt;
used to &lt;strong&gt;finalize implementation&lt;/strong&gt; of them&lt;/p&gt;
&lt;/blockquote&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%2Fdsx17rczxlgtzatr42es.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%2Fdsx17rczxlgtzatr42es.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Final variable

&lt;ul&gt;
&lt;li&gt;to create constant variable&lt;/li&gt;
&lt;li&gt;cannot change the value of final variable once it is assigned. It will be constant.&lt;/li&gt;
&lt;li&gt;can be initialized in constructor. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Final method

&lt;ul&gt;
&lt;li&gt;prevent method overriding&lt;/li&gt;
&lt;li&gt;can be inherited but cannot be overridden.&lt;/li&gt;
&lt;li&gt;constructor &lt;strong&gt;cannot be made final&lt;/strong&gt;. constructor cannot be inherited so it cannot be overriden, will have compile time error. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Final class

&lt;ul&gt;
&lt;li&gt;prevent inheritance&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;small&gt; references &lt;a href="https://www.javatpoint.com/final-keyword" rel="noopener noreferrer"&gt;javatpoint&lt;/a&gt; &amp;amp; &lt;a href="https://www.geeksforgeeks.org/final-keyword-java/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt; &amp;amp; &lt;a href="https://www.tutorialspoint.com/Can-a-constructor-be-made-final-in-Java" rel="noopener noreferrer"&gt;tutorialspoint&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Static Keyword&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;for &lt;strong&gt;variables, methods, block, nested class&lt;/strong&gt; &lt;br&gt;
used to define classes members &lt;strong&gt;indepedent from any instances&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;static variable

&lt;ul&gt;
&lt;li&gt;single copy of variable is create &amp;amp; shared among all objects at class level &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;static methods

&lt;ul&gt;
&lt;li&gt;can be accessed before any objects of class created &amp;amp; without reference to any object. &lt;/li&gt;
&lt;li&gt;can only directly call other static methods&lt;/li&gt;
&lt;li&gt;can only directly access static data&lt;/li&gt;
&lt;li&gt;cannot refer to &lt;em&gt;this&lt;/em&gt; or &lt;em&gt;super&lt;/em&gt; &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;static nested / inner class

&lt;ul&gt;
&lt;li&gt;mainly for convinience&lt;/li&gt;
&lt;li&gt;no need to instantiate outer class to instantiate inner class&lt;/li&gt;
&lt;li&gt;refer to: &lt;a href="https://stackoverflow.com/a/47568544" rel="noopener noreferrer"&gt;https://stackoverflow.com/a/47568544&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;useful for: builder pattern (inner builder class is static)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;static block

&lt;ul&gt;
&lt;li&gt;do computation to initialize static variables&lt;/li&gt;
&lt;li&gt;is executed exactly once - when class is first loaded.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Test {
    // static variable
    static int a = 10;
    static int b;

    // static block
    static {
        System.out.println("Static block initialized.");
        b = a * 4;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt; References: &lt;a href="https://www.geeksforgeeks.org/static-keyword-java/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt; &amp;amp; &lt;a href="https://www.javatpoint.com/static-keyword-in-java" rel="noopener noreferrer"&gt;javatpoint&lt;/a&gt; &amp;amp; &lt;a href="https://www.baeldung.com/java-static" rel="noopener noreferrer"&gt;Baeldung&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Static VS Instance block&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;static block: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;runs at time of class loading&lt;/li&gt;
&lt;li&gt;will execute in same order they appear in the class&lt;/li&gt;
&lt;li&gt;static block of parent class execute FIRST because compiler loads parent class BEFORE child class&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;instance block:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;runs at time of instance creation&lt;/li&gt;
&lt;li&gt;executees during every constructor invocation&lt;/li&gt;
&lt;li&gt;parents instance block will run first BEFORE child's instance block&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Order is&lt;br&gt;
Super class - static&lt;br&gt;
Sub class - static&lt;br&gt;
Super class - instance&lt;br&gt;
Super class - constructor&lt;br&gt;
Sub class - instance &lt;br&gt;
sub class - constructor&lt;/p&gt;

&lt;p&gt;Note that by default JVM will insert &lt;code&gt;super()&lt;/code&gt; ins first line of sub class constructor if developer has not done so. &lt;/p&gt;

&lt;p&gt;&lt;small&gt;ref: &lt;a href="https://www.quora.com/In-Java-does-every-object-constructor-automatically-call-super-in-object-before-its-own-constructors" rel="noopener noreferrer"&gt;https://www.quora.com/In-Java-does-every-object-constructor-automatically-call-super-in-object-before-its-own-constructors&lt;/a&gt;&lt;/small&gt;&lt;br&gt;
&lt;small&gt;ref: &lt;a href="https://www.javamadesoeasy.com/2015/06/differences-between-instance.html" rel="noopener noreferrer"&gt;https://www.javamadesoeasy.com/2015/06/differences-between-instance.html&lt;/a&gt;&lt;/small&gt;&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%2Fce0m5v2ubhw7cfi1b943.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%2Fce0m5v2ubhw7cfi1b943.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;ref: &lt;a href="https://www.baeldung.com/java-static-instance-initializer-blocks" rel="noopener noreferrer"&gt;https://www.baeldung.com/java-static-instance-initializer-blocks&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Wrapper Classes are immutable&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Wrapper classes are immutable so &lt;strong&gt;operations&lt;/strong&gt; like add, subtarct &lt;strong&gt;create new object&lt;/strong&gt; and &lt;strong&gt;do not modify the old&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Reference: &lt;a href="https://www.geeksforgeeks.org/primitive-wrapper-classes-are-immutable-in-java/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt;&lt;br&gt;
eg.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args)  {
        Integer i = new Integer(12);
        System.out.println(i); // 12
        modify(i);
        System.out.println(i); //12
}

private static void modify(Integer i) {
        i = i + 1;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;paramete &lt;em&gt;i&lt;/em&gt; is referenced in modify however it does not change since objects are immutable.&lt;/p&gt;

&lt;p&gt;&lt;u&gt; Creating new object &lt;/u&gt;&lt;br&gt;
Reference: &lt;a href="https://stackoverflow.com/questions/5560176/is-integer-immutable" rel="noopener noreferrer"&gt;SO&lt;/a&gt; &amp;amp; []&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Integer a=3;
Integer b=3;
a+=b; // a=a+b
System.out.println(a); // 6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, &lt;code&gt;a+=b&lt;/code&gt; actually does &lt;code&gt;a = new Integer(3+3)&lt;/code&gt;&lt;br&gt;
&lt;em&gt;a&lt;/em&gt; is a reference, in the line &lt;code&gt;a+=b&lt;/code&gt;, the code changes the reference &lt;em&gt;a&lt;/em&gt; to points to a different, equally immutable Integer. &lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Why wrapper class&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Wrapper classes  wraps around data type and give it an object appearance, this provides object methods to primitive types. &lt;br&gt;
Reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;null is possible value&lt;/li&gt;
&lt;li&gt;use it in Collection&lt;/li&gt;
&lt;li&gt;methods that support object (eg. creation from other types &lt;code&gt;Integer test = new Integer("55");&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt;Different wrapper classes &lt;/u&gt;&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%2Fuploads%2Farticles%2Fhzrn993q843vona8kxa8.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%2Fhzrn993q843vona8kxa8.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Constructor VS valueOf &lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;There are two ways to create wrapper class&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;constructor
&lt;code&gt;Integer test = new Integer("100");&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;valueOf
&lt;code&gt;Integer test = Integer.valueOf("100");&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;u&gt;constructor&lt;/u&gt;: always &lt;strong&gt;creates new object&lt;/strong&gt;&lt;br&gt;
&lt;u&gt;valueOf&lt;/u&gt;: may return a cached value if it is within range. (eg. if long is between -128 to 127, valueOf implements a cache). If not in cache gives new object.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;valueOf is &lt;a href="https://stackoverflow.com/a/2974852" rel="noopener noreferrer"&gt;generally recommended&lt;/a&gt; since it results in better space and time performance by caching frequently requeste values. &lt;/p&gt;

&lt;p&gt;Since wrapper classes are immutable, its important to reuse values.  &lt;/p&gt;

&lt;p&gt;Under the hood autoboxing also invokes the static valueOf method&lt;/p&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.7" rel="noopener noreferrer"&gt;java docs&lt;/a&gt; &amp;amp; &lt;a href="https://stackoverflow.com/a/408668" rel="noopener noreferrer"&gt;SO answer&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Autoboxing &amp;amp; Unboxing&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;automatic conversion Java compiler makes between primitive types &amp;amp; their corresponing object wrapper class.&lt;br&gt;
Conversion the other way is called unboxing.&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// autoboxing
Integer test = 9; 

// autounboxing
Integer test1 = Integer.valueOf(10);
test1++;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt; Autoboxing &lt;/u&gt;&lt;br&gt;
create Integer object from primitive data type&lt;br&gt;
&lt;code&gt;Integer test = Integer.valueOf(9);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Auto Unboxing&lt;/u&gt;&lt;br&gt;
airthmetic operations (+, %, +=) do not apply to Integer objects. Java compiler compiles code with no errors since it does autounboxing, invoking &lt;code&gt;intValue&lt;/code&gt; to convert &lt;code&gt;Integer&lt;/code&gt; to an &lt;code&gt;int&lt;/code&gt; at runtime. &lt;code&gt;test1.intValue()++;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt; reference: &lt;a href="https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html#:~:text=Autoboxing%20is%20the%20automatic%20conversion,a%20Double%2C%20and%20so%20on.&amp;amp;text=List%20li%20%3D%20new,add(i)%3B" rel="noopener noreferrer"&gt;java docs&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Autoboxing Advantages&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;lets developers write cleaner code that is easier to read.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Additionally, Autoboxing uses static valueOf method which is more efficient &lt;/p&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html" rel="noopener noreferrer"&gt;java docs&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Typecasting - Implicit &amp;amp; Explicit&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Typecasting&lt;/strong&gt;: converting &lt;em&gt;primitive/interface/class&lt;/em&gt; in Java into another type. &lt;br&gt;
If 2 types are compatible java performs conversion &lt;em&gt;automatically&lt;/em&gt; else they need to be converted &lt;em&gt;explicitly&lt;/em&gt;. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Implicit/widening/automatic

&lt;ul&gt;
&lt;li&gt;happens if both types are compatible &amp;amp; &lt;strong&gt;target type&lt;/strong&gt; is &lt;strong&gt;larger&lt;/strong&gt; than &lt;strong&gt;source type&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg3jxxesi84bgzcq92ohq.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%2Fg3jxxesi84bgzcq92ohq.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;small&gt; casting smaller value to a larger variable types &lt;/small&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;byte i = 50; // 50
short j = i; // 50
int k = j; // 50
long l = k; // 50
float m = l; // 50.0
double n = m; // 50.0   
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Explicit/narrowing

&lt;ul&gt;
&lt;li&gt;assigning &lt;strong&gt;larger type&lt;/strong&gt; to a &lt;strong&gt;smaller type&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;


&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnnff2ef870xkpsxyhsui.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%2Fnnff2ef870xkpsxyhsui.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;small&gt; casting larger value to a smaller variable types &lt;/small&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;double d = 75.0; // 75.0
float f = (float) d; // 75.0
long l = (long) f; // 75 
int i  = (int) l; // 75
short s = (short) i; // 75
byte b = (byte) s; // 75
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt;Reference: &lt;a href="https://www.geeksforgeeks.org/type-conversion-java-examples/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt; &amp;amp; &lt;a href="https://www.javainterviewpoint.com/type-casting-java-implicit-explicit-casting/" rel="noopener noreferrer"&gt;javainterviewpoint&lt;/a&gt; &amp;amp; &lt;a href="https://www.edureka.co/blog/type-casting-in-java/" rel="noopener noreferrer"&gt;edureka&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Strings - immutable&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Value of String object once created &lt;strong&gt;cannot be modified&lt;/strong&gt;. &lt;br&gt;
Any modification creates a String object&lt;br&gt;
String is mainly immutable becuase it &lt;em&gt;encapsulates a char[]&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String test = "hello";
test.concat(" world");
System.out.println(test); // hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;value of String object was &lt;strong&gt;not modified&lt;/strong&gt;. the &lt;code&gt;concat()&lt;/code&gt;operator like &lt;code&gt;toUppercase()&lt;/code&gt; operator &lt;em&gt;produces a new String&lt;/em&gt;. The &lt;strong&gt;original value remains unchanged&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String str = "hello";
str = str + "world";
System.out.println(str); //hello world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code snippet, &lt;code&gt;str&lt;/code&gt; was &lt;strong&gt;not changed&lt;/strong&gt;. Rather a new String object "hello world" was instantiated and assigned to the reference &lt;code&gt;str&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://stackoverflow.com/a/5560220" rel="noopener noreferrer"&gt;SO&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Where are string values stored i memory?&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;depends on how we create them&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;String literal -&amp;gt; String constant pool (in heap)&lt;/li&gt;
&lt;li&gt;new Object -&amp;gt; heap memory&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;String literal

&lt;ul&gt;
&lt;li&gt;value stored in String constant pool  (heap memory)&lt;/li&gt;
&lt;li&gt;compiler finds String literal -&amp;gt; check if exists in pool, reused. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;String object constructor

&lt;ul&gt;
&lt;li&gt;new object created on heap, reference in stack.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;not reuse of values&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Java String Pool&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;String Pool in java is a pool of Strings sorted in Java Heap memory. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;saves space for Java runtime&lt;/li&gt;
&lt;li&gt;more time to create string. &lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&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%2F45uynr0ebnsws4q30ffh.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%2F45uynr0ebnsws4q30ffh.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;only possible becuase&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;String is immutable in Java&lt;/li&gt;
&lt;li&gt;implementation of String interning concept&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;String pool is an example of Flyweight design pattern. &lt;/p&gt;

&lt;p&gt;&lt;u&gt; String literal &lt;/u&gt;&lt;br&gt;
&lt;code&gt;String test = "hello";&lt;/code&gt;&lt;br&gt;
when create string via String literal,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;java looks for string with same value in string pool

&lt;ul&gt;
&lt;li&gt;found: returns reference&lt;/li&gt;
&lt;li&gt;else: create new String in pool -&amp;gt; return reference. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; String constructor &lt;/u&gt;&lt;br&gt;
force Java to create new String object in heap space&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String s1 = "Cat";
String s2 = "Cat";
String s3 = new String("Cat");

System.out.println(s1==s2); // true
System.out.println(s1==s3); // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://www.journaldev.com/797/what-is-java-string-pool" rel="noopener noreferrer"&gt;JournalDev&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Java String Interning&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;method of &lt;em&gt;storing only 1 copy of each distinct String value&lt;/em&gt;, which must be immutable. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Java String class has public method &lt;code&gt;intern()&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;invoke &lt;code&gt;intern()&lt;/code&gt; method on String object. &lt;/li&gt;
&lt;li&gt;looks for the string contained by object in the pool&lt;/li&gt;
&lt;li&gt;if string is found

&lt;ul&gt;
&lt;li&gt;string from pool is returned&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;else: 

&lt;ul&gt;
&lt;li&gt;String object added to pool &amp;amp; reference to String object returned.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;So by applying String.intern() on strings will ensure all strings with same content share same memory. eg. if 'hello' appears 100 times, interning ensures 1 'hello' is actually allocated memory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String s1 = "Test"; // s1 in SCP
String s2 = "Test"; // s2 in SCP
String s3 = new String("Test"); // s3 in heap
final String s4 = s3.intern(); // s4 in SCP
System.out.println(s1 == s2); // true
System.out.println(s2 == s3); // false
System.out.println(s3 == s4); // false
System.out.println(s1 == s3); // false
System.out.println(s1 == s4); // true
System.out.println(s1.equals(s2)); // true
System.out.println(s2.equals(s3)); // true
System.out.println(s3.equals(s4)); // true
System.out.println(s1.equals(s4)); // true
System.out.println(s1.equals(s3)); // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://www.geeksforgeeks.org/interning-of-string/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt; &amp;amp; &lt;a href="https://dzone.com/articles/string-interning-what-why-and" rel="noopener noreferrer"&gt;DZone&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Number of Objects created in String Construction&lt;/a&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String str = new String("Cat");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Either 1 or 2 objects created&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;String literal 

&lt;ul&gt;
&lt;li&gt;"Cat" String created in String pool (if does not exist)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;String &lt;code&gt;str&lt;/code&gt; object

&lt;ul&gt;
&lt;li&gt;String object created on heap
&lt;small&gt; Reference: &lt;a href="https://www.journaldev.com/797/what-is-java-string-pool" rel="noopener noreferrer"&gt;JournalDev&lt;/a&gt; &amp;amp; &lt;a href="https://stackoverflow.com/a/19672578" rel="noopener noreferrer"&gt;SO&lt;/a&gt;&lt;/small&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Never + String in loops&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;each concatenation creates a new object, since string in immutable&lt;br&gt;
&lt;strong&gt;use String Buffer/Builder&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String test = "lup";
String test2 = "dup";
for (int i=0;i&amp;lt;100000;i++){
  test = test + test2;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Loop creates about 100 000 String objects.&lt;/p&gt;

&lt;p&gt;&lt;u&gt; String Buffer &lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;StringBuilder test = new StringBuilder("lup");
String test2 = "dup";
for (int i=0;i&amp;lt;100000;i++){
  test.append(test2);
}
String result = test.toString();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would yield better performance. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;String VS StringBuffer&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;String immutable, StringBuffer used to represent values that can be modifed. &lt;/li&gt;
&lt;li&gt;both are thread safe&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;StringBuilder VS StringBuffer&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;String Builder &lt;strong&gt;not thread safe&lt;/strong&gt; String Buffer is&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Java What is a class&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;template for creating multiple objects.&lt;br&gt;
It defines:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;state &lt;/li&gt;
&lt;li&gt;behaviour
that an object can exhibit&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt; State &lt;/u&gt;&lt;br&gt;
Values object has.&lt;br&gt;
In Java, this would be the &lt;strong&gt;instance variables&lt;/strong&gt; of the object&lt;/p&gt;

&lt;p&gt;&lt;u&gt; Behaviour &lt;/u&gt;&lt;br&gt;
&lt;strong&gt;methods&lt;/strong&gt; that are part of the class&lt;/p&gt;

&lt;p&gt;State of object can &lt;strong&gt;change with time&lt;/strong&gt;, can change via &lt;strong&gt;behaviour&lt;/strong&gt; / class methods. &lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Java: &lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;instance of class&lt;br&gt;
Can create objects via &lt;strong&gt;constructor&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;ParentClass of every class&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Java &lt;strong&gt;Object  class&lt;/strong&gt; is the super / parent class of every class in Java&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Useful if you want to &lt;em&gt;refer to any object whose type you dont know&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Classes will inherit all properties &amp;amp; methods of Java Object class.&lt;br&gt;
eg.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;toString&lt;/li&gt;
&lt;li&gt;hashCode&lt;/li&gt;
&lt;li&gt;equals&lt;/li&gt;
&lt;li&gt;clone &lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Java Object toString method&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;used to print content of object&lt;br&gt;
It is inherited from the Java objects class. &lt;br&gt;
&lt;u&gt; Default &lt;/u&gt;: print hash code&lt;br&gt;
&lt;u&gt; overridden &lt;/u&gt;: content returns by toString overidden implementation is printed. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The toString() method &lt;strong&gt;MUST&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;be public&lt;/li&gt;
&lt;li&gt;return type: String&lt;/li&gt;
&lt;li&gt;not accept any parameteres&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;Object class default toString method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public String toString()
{
      return getClass().getName()+"@"+Integer.toHexString(hashCode());
}

MyClass test = new MyClass();
System.out.println(test);
// com.example.demo.MyClass@f7e66a96
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://www.geeksforgeeks.org/object-tostring-method-in-java/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt; &amp;amp; in28Minutes &lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Java equals() method&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;used to &lt;strong&gt;compare 2 object&lt;/strong&gt;&lt;br&gt;
Inhierited from java Objects class&lt;br&gt;
&lt;u&gt;Default&lt;/u&gt;: uses &lt;code&gt;==&lt;/code&gt; operator (check if references point to the same object)&lt;br&gt;
&lt;u&gt;overidden&lt;/u&gt;: usually implemented as checking all properties of object have equals value&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If making you own custom class, &lt;strong&gt;must override equals method&lt;/strong&gt; to check the contents of the object. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;equals() Method Criteria&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;All implementation of equals method must meet following criteria&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reflexive&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;For any reference values x, x.equals(x) returns true&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Symmetric&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;x.equals(y) == y.equals(x)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;transitive&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;if x.equals(y) = true &amp;amp; y.equals(z) = true, thenx.equals(z) == true.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consistent&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;multiple invocations x.equals(y) will &lt;em&gt;consistently&lt;/em&gt; return true or &lt;em&gt;consistently / always&lt;/em&gt; return false. &lt;/li&gt;
&lt;li&gt;outcome wont change when operation is repeated.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Null comparison&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;For any non null reference x, x.equals(null) must return false. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Usually just use IDE to generate&lt;/p&gt;

&lt;p&gt;&lt;small&gt; Reference &lt;a href="https://www.journaldev.com/21095/java-equals-hashcode#:~:text=equals()%20method%2C%20any%20implementation%20should%20adhere%20to%20following%20principles." rel="noopener noreferrer"&gt;JournalDev&lt;/a&gt; &amp;amp; in28minutes&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Java hashCode() method&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;used in collections like hashmap. &lt;br&gt;
&lt;u&gt;Default&lt;/u&gt;: &lt;a href="https://howtodoinjava.com/java/basics/java-hashcode-equals-methods/#:~:text=by%20default%2C%20integer%20value%20is%20mostly%20derived%20from%20memory%20address%20of%20the%20object%20in%20heap%20(but%20it%E2%80%99s%20not%20mandatory%20always)." rel="noopener noreferrer"&gt;derived from memory address&lt;/a&gt; of object used in heap&lt;br&gt;
Used in &lt;strong&gt;hashing&lt;/strong&gt; to &lt;em&gt;decide which bucket object should be place in&lt;/em&gt;.&lt;br&gt;
Therefore, hashCode() &lt;strong&gt;decides the effectiveness of Hashing&lt;/strong&gt;.&lt;br&gt;
Good hashing function will distribute objects &lt;strong&gt;evenly&lt;/strong&gt; across different buckets. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;hashCode Method Criteria&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Good hashCode should have following proerties&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;obj1.equals(obj2) == true --&amp;gt; obj1.hashCode() == obj2.hashCode()&lt;/li&gt;
&lt;li&gt;consistent. obj.hashCode() shuould &lt;strong&gt;return same value&lt;/strong&gt; when run multiple times &lt;em&gt;if values used in obj equals() have not changed&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;if obj1.equals(obj2) == false --&amp;gt; obj1.hashCode &lt;strong&gt;MAY BE&lt;/strong&gt; == obj2.hashCode().&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;Basically.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;two unequal objects 

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;might&lt;/strong&gt; have same hashcode (hash collision)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;two equals objects

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;must&lt;/strong&gt; have same hashcode 

&lt;ul&gt;
&lt;li&gt;if 2 equal objects have same hashcode, they can be placed in different buckets.&lt;/li&gt;
&lt;li&gt;equals() function will never run on obj1 &amp;amp; obj2. obj2 will never replace obj1&lt;/li&gt;
&lt;li&gt;hashmap can hold duplicate keys &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Importance of equals() &amp;amp; hashCode()&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;It is a must to override / implement equals() &amp;amp; hashCode() method if you are &lt;strong&gt;using objects as hashma keys&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Implementtation of equals() &amp;amp; hashCoe() follow these rules / contarct:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;if o1.equals(o2) --&amp;gt; o1.hashCode() == o2.hashCode()&lt;/li&gt;
&lt;li&gt;if o1.hashCode() == o2.hashCode() == true, o1.equals(o2) MAY NOT be true&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So, if you implement equals method, its good practice to override hashCode so both methods follow contract.&lt;/p&gt;

&lt;p&gt;however, this will only really come into play if you use objects as &lt;strong&gt;hashmap keys&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In hashing&lt;br&gt;
&lt;u&gt;equals()&lt;/u&gt;:used to check if key exists in Hashmap&lt;br&gt;
If wrongly implemented,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;hashMap.get(obj) may return null, since wrong equals method cant tell that obj and key are equal&lt;/li&gt;
&lt;li&gt;hashMap.put(obj1) may give "duplicate" keys. Since Java cant tell that obj1.equals(obj) and make obj1 override obj&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;hashCode()&lt;/u&gt;: decide which bucket obj will be placed in&lt;br&gt;
If wrongly implemented:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;equivalent objects can get placed in two different buckets.

&lt;ul&gt;
&lt;li&gt;since equals() only runs on 1 bucket, Java cant tell that obj already exists on HashMap&lt;/li&gt;
&lt;li&gt;HashMap can store "duplciate" keys. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;small&gt;Reference: &lt;a href="https://www.journaldev.com/21095/java-equals-hashcode#:~:text=%20you%20are%20planning%20to%20use%20a%20class%20as%20hash%20table%20key%2C%20then%20it%E2%80%99s%20must%20to%20override%20both%20equals()%20and%20hashcode()%20methods." rel="noopener noreferrer"&gt;JournalDev&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Java Objects Inheritance&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;process where one class aquires properties (methods &amp;amp; field) of another. &lt;br&gt;
IS-A type of relationship&lt;br&gt;
&lt;u&gt; class &lt;/u&gt;: ChildClass &lt;strong&gt;extends&lt;/strong&gt; ParentClass&lt;br&gt;
&lt;u&gt; interface &lt;/u&gt;: ChildClass &lt;strong&gt;implements&lt;/strong&gt; Interfae1, Interface2&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt;Sub Class&lt;/u&gt;: child class&lt;br&gt;
&lt;u&gt;Super class&lt;/u&gt;: parent class&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Only 1 superClass&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
In Java,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;child class can only &lt;strong&gt;extend 1 Parent Class&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;child class can &lt;strong&gt;implement &amp;gt;=1 Interface&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Inheriting constructors&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
subclass inherits all memebers (fields methods, nested classes). but constructos are nont members &amp;amp; are &lt;strong&gt;not inhierted&lt;/strong&gt;.&lt;br&gt;
but constructor os superclass can be invoked from subclass &lt;code&gt;super()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Private member inheritance&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
subclass does not inherit private members of parent class. &lt;br&gt;
but subclass can use superclass's public / protected methods (eg. getter, setter) To access superclass's private fields. &lt;/p&gt;

&lt;p&gt;During inheritance, only object of subclass created not super class&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 ChildClass extends ParentClass{
}
ChildClass test = new ChildClass()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, only 1 ChildClass object created no ParentClass object is created. &lt;/p&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://www.geeksforgeeks.org/inheritance-in-java/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt; &amp;amp; &lt;a href="https://www.tutorialspoint.com/java/java_inheritance.htm" rel="noopener noreferrer"&gt;tutorialspoint&lt;/a&gt; &amp;amp; &lt;a href="https://www.w3schools.com/java/java_inheritance.asp" rel="noopener noreferrer"&gt;w3schools&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Java == VS equals&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;==: compares if 2 references point to the same object &lt;br&gt;
can apply &lt;code&gt;==&lt;/code&gt; for &lt;strong&gt;every primitive type&lt;/strong&gt;&lt;br&gt;
equals(): overrides Object equals method. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt;String class&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;String pool ensures '==' works for string literals  (references will point to same object / address in pool)&lt;/li&gt;
&lt;li&gt;equals(): can check the value of the String object 
(String pool ensures == works for string literals)
For String, can check value of object&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;Object class&lt;/u&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;java Object's &lt;strong&gt;default implemenetation&lt;/strong&gt; of equals() is &lt;a href="https://www.infoworld.com/article/3305792/comparing-java-objects-with-equals-and-hashcode.html#:~:text=public%20boolean%20equals(object%20obj)%20%7B%20return%20(this%20%3D%3D%20obj)%3B%20%7D" rel="noopener noreferrer"&gt;actually ==&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public boolean equals(Object obj) {
  return (this == obj);
}

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

&lt;/div&gt;



&lt;p&gt;For &lt;strong&gt;custom object&lt;/strong&gt; to correctly implement the &lt;em&gt;equals()&lt;/em&gt; method you &lt;strong&gt;MUST  override the default implementation.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Override
public boolean equals(Object o) {
  if (this == o) {
    return true;
  }
  if (o == null || getClass() !=  o.getClass()) {
    return false;
  }
  Simpson simpson = (Simpson) o;
  return age == simpson.age &amp;amp;&amp;amp; weight == simpson.weight &amp;amp;&amp;amp; name.equals(simpson.name);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://www.geeksforgeeks.org/difference-equals-method-java/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt; &amp;amp; &lt;a href="https://www.infoworld.com/article/3305792/comparing-java-objects-with-equals-and-hashcode.html" rel="noopener noreferrer"&gt;infoworld&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;How hashmap works internally&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Hashamp works on principle of &lt;strong&gt;hashing&lt;/strong&gt;- &lt;em&gt;an algorithm to map object data to some representative integer value&lt;/em&gt;&lt;br&gt;
&lt;u&gt; load factor &lt;/u&gt;:  entries / buckets (0.75)&lt;br&gt;
&lt;u&gt; capacity &lt;/u&gt;: number of buckets (16)&lt;br&gt;
&lt;u&gt; threshold &lt;/u&gt;: capacity * load factor (12)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In Java, threshold (default) is 12. that means after the 12th kay value air is added, capacity of hashmap will increase (double) &lt;/p&gt;

&lt;p&gt;There are two main scenarios in a Java Hashmap&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;constructing &amp;amp; putting items in (&lt;code&gt;hashMap.put(key,value)&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;retrieving items from hashmap via key (&lt;code&gt;value = hashMap.get(key)&lt;/code&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  &lt;u&gt;Constructing HashMap&lt;/u&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;16 initial buckets

&lt;ul&gt;
&lt;li&gt;initial capacity = number of buckets = 16 (&lt;code&gt;new HashMap&amp;lt;&amp;gt;()&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;default load factor is 0.75&lt;/li&gt;

&lt;li&gt;default threshold = 12

&lt;ul&gt;
&lt;li&gt;default threshold = 16 * 0.75 = 12&lt;/li&gt;
&lt;li&gt;rehash is performed on 12th key value pair insert&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;get hashCode of key

&lt;ul&gt;
&lt;li&gt;on &lt;code&gt;hashmap.put(key,value)&lt;/code&gt;, Java calculate &lt;strong&gt;hashCode() of key&lt;/strong&gt; &lt;code&gt;key.hashcode()&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;calculate bucket index (eg. 6) 

&lt;ul&gt;
&lt;li&gt;since hashcode may be bigger than number of buckets&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;bitwise AND&lt;/em&gt;. hashCode AND number of bucket. to determine bucket index to insert key value pair in&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Create Node object with key-value pair

&lt;ul&gt;
&lt;li&gt;Node like LinkeList &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Since hashCodes are not unique, there will be a &lt;strong&gt;collision&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Collision&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;get key1.hashCode()&lt;/li&gt;
&lt;li&gt;get bucket index of key1 (eg. 6)&lt;/li&gt;
&lt;li&gt;there is an object at index 6&lt;/li&gt;
&lt;li&gt;check that inserted object and existing one are not equals

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;key.equals(key1)&lt;/strong&gt; to check equality&lt;/li&gt;
&lt;li&gt;if same: replace&lt;/li&gt;
&lt;li&gt;else: &lt;em&gt;collision&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Connect node of key1 to node of key via &lt;strong&gt;linked list&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;keyNode.next = key1Node&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;both key-value pairs stored at index 6&lt;/li&gt;
&lt;/ul&gt;


&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fald0adv5g4leu39dnd1a.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%2Fald0adv5g4leu39dnd1a.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As more and more objects are inserted, load factor increases. An increasing load factor means more complex get() / put() which will defeat the great advantage of hashmap (ie. O(1) gets and puts)&lt;/p&gt;

&lt;p&gt;To keep load factor low, once treashold is exceed, &lt;strong&gt;rehashing&lt;/strong&gt; occurs&lt;/p&gt;

&lt;p&gt;&lt;u&gt; Rehashing &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Threshold (12) exceeded&lt;/li&gt;
&lt;li&gt;after 12th insert -&amp;gt; rehashing&lt;/li&gt;
&lt;li&gt;new Hashmp object created with &lt;strong&gt;double&lt;/strong&gt; the old capacity (so 32 buckets)&lt;/li&gt;
&lt;li&gt;repeat &lt;code&gt;hashMap.put(key,value)&lt;/code&gt; on all elements of old hashMap. 

&lt;ul&gt;
&lt;li&gt;all key-value pairs of old hashmap are placed into new hashMap&lt;/li&gt;
&lt;li&gt;must recalculate their hashcode, index&lt;/li&gt;
&lt;li&gt;then insert (linkedlist if collision)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Rehashing process is both space &lt;code&gt;O(number of buckets)&lt;/code&gt; and Time consuming &lt;code&gt;O(number of entries)&lt;/code&gt;.&lt;br&gt;
Therefore, a good balance must be struck between theshold and rehashing.  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;High threshold 

&lt;ul&gt;
&lt;li&gt;rarely rehash &lt;/li&gt;
&lt;li&gt;BUT: hashmap load factor is high&lt;/li&gt;
&lt;li&gt;get and put will be complex&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Low threshold

&lt;ul&gt;
&lt;li&gt;load factor of hashmap is low, will have efficient gets and puts&lt;/li&gt;
&lt;li&gt;rehash very often -&amp;gt; waste time and space &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;u&gt;Getting Item from HashMap&lt;/u&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;Load factor (&amp;amp; hashing function) will affect the complexity of get()&lt;br&gt;
&lt;code&gt;value = hashMap.get(key)&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;calculate hashCode of key&lt;/li&gt;
&lt;li&gt;calculate index of key (eg. 6)&lt;/li&gt;
&lt;li&gt;go to bucket of index&lt;/li&gt;
&lt;li&gt;compare first Node with key sing &lt;strong&gt;equals()&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;node.equals(key)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;if both are equal: return value&lt;/li&gt;

&lt;li&gt;else go down linked list and check if node exists. &lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;small&gt;Reference: &lt;a href="https://stackoverflow.com/a/10901821" rel="noopener noreferrer"&gt;SO answer&lt;/a&gt; &amp;amp;&amp;amp;&lt;a href="https://javaconceptoftheday.com/initial-capacity-and-load-factor-of-hashmap-in-java/" rel="noopener noreferrer"&gt;javaconceptoftheday&lt;/a&gt; &amp;amp;&amp;amp; &lt;a href="https://javarevisited.blogspot.com/2011/02/how-hashmap-works-in-java.html" rel="noopener noreferrer"&gt;javarevisited&lt;/a&gt; &amp;amp;&amp;amp; &lt;a href="https://examples.javacodegeeks.com/core-java/maphashmap-works-internally-java/" rel="noopener noreferrer"&gt;javacodegeeks&lt;/a&gt; &amp;amp;&amp;amp; &lt;a href="https://www.geeksforgeeks.org/internal-working-of-hashmap-java/" rel="noopener noreferrer"&gt;geeksforgeeks&lt;/a&gt; &amp;amp;&amp;amp; &lt;a href="https://www.baeldung.com/java-hashmap-load-factor" rel="noopener noreferrer"&gt;baeldung&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Adding Null key to hashmap&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;only one null key is permitted&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;hash calculation is &lt;strong&gt;not done&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;(key,value) pair always added to bucket 0&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://knpcode.com/java/collections/hashmap-internal-implementation-in-java/#:~:text=what%20happens%20when%20the%20null%20key%20is%20added" rel="noopener noreferrer"&gt;knpcode&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;HashSet internal implementation in Java&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Hashset uses &lt;strong&gt;HashMap internally&lt;/strong&gt; a dummy object is always added as value to backing HashMap.&lt;br&gt;
HashSet class used to create collection that uses &lt;em&gt;hash table for storage&lt;/em&gt;. It contains &lt;em&gt;unique elements only&lt;/em&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Like HashMap,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Capacity = 16&lt;/li&gt;
&lt;li&gt;load factor = 0.75&lt;/li&gt;
&lt;li&gt;threshold = 0.75 * 16 = 12&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; add values &lt;/u&gt;&lt;br&gt;
HashSet implementation, values are stored as hashmap keys. So set only contains unique elements.&lt;br&gt;
In the underlying hashMap data, a &lt;strong&gt;dummy object is always added as value&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;hashSet.add(element);&lt;/code&gt; &lt;br&gt;
underlying implementation is&lt;br&gt;
&lt;code&gt;hashMap.put(element,DUMMY)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt; get values &lt;/u&gt;&lt;br&gt;
there are not values. just use key iterator to get keys&lt;br&gt;
&lt;code&gt;hashMap.keySet().iterator()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;you can use hashMap to check if key is present in Set&lt;/p&gt;

&lt;p&gt;&lt;u&gt; remove values &lt;/u&gt;&lt;br&gt;
same as removing items in hashmap&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Reference: &lt;a href="https://knpcode.com/java/collections/hashset-internal-implementation-in-java/" rel="noopener noreferrer"&gt;knpcode&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;ArrayList: Capacity VS Size&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;u&gt;Capcity&lt;/u&gt;: maximum item list can hold before it can be resized&lt;br&gt;
&lt;u&gt;Size&lt;/u&gt;: number of itesm in the list.&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;Intger&amp;gt; test = new ArrayList(20);
test.add(1);
test.add(2);
test.add(3);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, capacity is 20, size is 3. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;How ArrayList works Internally in Java&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Arraylist is &lt;em&gt;resizeable array&lt;/em&gt; implementation in java.&lt;br&gt;
backed by an array &lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;default capacity = 10&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;add()&lt;/u&gt;: ensure arraylist has required capacity.

&lt;ul&gt;
&lt;li&gt;if capacity exhausted&lt;/li&gt;
&lt;li&gt;new array created with &lt;strong&gt;50% more capacity&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Arrays.copyOf()&lt;/em&gt; used to copy elements from old array to new array&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;u&gt;remove()&lt;/u&gt;: remove element from array

&lt;ul&gt;
&lt;li&gt;elements shift to fill gap created by removed element&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://www.geeksforgeeks.org/internal-working-of-arraylist-in-java/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt; &amp;amp;  &lt;a href="https://www.javatpoint.com/arraylist-implementation-in-java" rel="noopener noreferrer"&gt;javatpoint&lt;/a&gt; &amp;amp; &lt;a href="https://knpcode.com/java/collections/arraylist-internal-implementation-in-java/" rel="noopener noreferrer"&gt;knpcode&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Java Vector class&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Vector is basically a &lt;strong&gt;thread safe&lt;/strong&gt; arraylist.&lt;br&gt;
Vector is &lt;strong&gt;synchronised&lt;/strong&gt;, can use it in multiple threads. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Vector came first (before arraylist), in jdk since jdk 1.0 &lt;/p&gt;

&lt;p&gt;Synchronization has an overhead, so if you are not using multiple threads you can use a class without synchronization overhead. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;How is stack implemented by Java internally?&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Stack is LIFO (last-in-first-out) stack of objects&lt;br&gt;
operations: push, pop, peek, empty, search&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;No items on stack creation.&lt;/p&gt;

&lt;p&gt;implemented with underlying Vector class. Vector is a growable/dynamic array. &lt;/p&gt;

&lt;p&gt;This could be due to backwards compatibility (see Quora source) &lt;/p&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://stackoverflow.com/a/55037772" rel="noopener noreferrer"&gt;SO&lt;/a&gt; &amp;amp; &lt;a href="https://www.quora.com/Do-stack-class-in-Java-is-internally-implemented-using-linked-list" rel="noopener noreferrer"&gt;Quora&lt;/a&gt; &amp;amp; &lt;a href="https://docs.oracle.com/javase/8/docs/api/java/util/Stack.html" rel="noopener noreferrer"&gt;java docs&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Queue implementations in Java&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Queue is a FIFO (first-in-first-out) data structure&lt;br&gt;
operations: add, remove, element&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In java, Queue is an &lt;strong&gt;interface&lt;/strong&gt;.&lt;br&gt;
There is no Queue class, it has to be implemented.&lt;/p&gt;

&lt;p&gt;Implementations&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;LinkedList&lt;/li&gt;
&lt;li&gt;PriorityQueue 

&lt;ul&gt;
&lt;li&gt;based on &lt;em&gt;heap&lt;/em&gt; data structure.&lt;/li&gt;
&lt;li&gt;orders elemnts accoridng to order specified at construction time.&lt;/li&gt;
&lt;li&gt;queue retrieval operations (poll, remove, peek) access element at head of queue. &lt;/li&gt;
&lt;li&gt;if mutliple elements are tied for head of queue, &lt;em&gt;tie is broken arbitarrily&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Map Implementation: HashMap, TreeMap, LinkedHashMap&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;All offer unique key-&amp;gt; value mappings &amp;amp; implement Map interface .&lt;br&gt;
Difference is &lt;strong&gt;time guarantees &amp;amp; ordering of keys&lt;/strong&gt;&lt;br&gt;
&lt;u&gt;HashMap&lt;/u&gt;: implemented as hash table &amp;amp;  no ordering on keys or values. &lt;br&gt;
&lt;u&gt;TreeMap&lt;/u&gt;: implemented based on red-black tree structure, &amp;amp; ordered by the key.&lt;br&gt;
&lt;u&gt;LinkedHashMap&lt;/u&gt;: preserves the insertion order&lt;br&gt;
&lt;u&gt;Hashtable&lt;/u&gt;: synchronized HashMap. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;HashMap

&lt;ul&gt;
&lt;li&gt;implemented by array of linked lists&lt;/li&gt;
&lt;li&gt;O(1) look up &amp;amp; insertion&lt;/li&gt;
&lt;li&gt;key orders -&amp;gt; arbitrary&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;TreeMap

&lt;ul&gt;
&lt;li&gt;implemented by Red-Black Tree. &lt;/li&gt;
&lt;li&gt;O(logN) lookup &amp;amp; insertion&lt;/li&gt;
&lt;li&gt;keys orders -&amp;gt; ordered, need to iterate through keys in sorted order&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;does not use hashing for storing key-pair values&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Linked Hash

&lt;ul&gt;
&lt;li&gt;implemented doubly linked list between key-value pairs (on top hashmap implementation) that keeps track of insertion order&lt;/li&gt;
&lt;li&gt;O(1) look up &amp;amp; insertion&lt;/li&gt;
&lt;li&gt;keys orders -&amp;gt; insertion order&lt;/li&gt;
&lt;/ul&gt;
&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl41u4mkme836h5gqo2dt.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%2Fl41u4mkme836h5gqo2dt.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;small&gt; &lt;a href="https://tdkhiem.com/maps-in-java/" rel="noopener noreferrer"&gt;Source&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;LinkedHashmap operations

&lt;ul&gt;
&lt;li&gt;on top of hashmap, maintains an additional &lt;a href="https://stackoverflow.com/a/2889796" rel="noopener noreferrer"&gt;doubly-linked list&lt;/a&gt; to make it "aware" of ordering of key-value pairs&lt;/li&gt;
&lt;/ul&gt;
&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2e543dhznp1onip83zcb.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%2F2e543dhznp1onip83zcb.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;small&gt;LinkedHashMap, internal implementation &lt;a href="https://anmolsehgal.medium.com/java-linkedhashmap-internal-implementation-44e2e2893036" rel="noopener noreferrer"&gt;Medium article by Anmol Sehgal&lt;/a&gt; provides really good explanation of Linked hashamp&lt;/small&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TreeMap &lt;a href="https://www.javatpoint.com/how-treemap-works-internally-in-java" rel="noopener noreferrer"&gt;internal workings&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;does not use hashing&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;sorts object kyes using red-black-tree algorithm
&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%2Fz67x7u6zawsze19mrwiq.png" alt="alt text"&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://docs.oracle.com/javase/tutorial/collections/implementations/map.html" rel="noopener noreferrer"&gt;oracle docs&lt;/a&gt; &amp;amp; &lt;a href="https://www.geeksforgeeks.org/differences-treemap-hashmap-linkedhashmap-java/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt; &amp;amp; &lt;a href="https://dzone.com/articles/hashmap-vs-treemap-vs" rel="noopener noreferrer"&gt;DZone&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Set Implementation: HashSet, TreeSet, LinkedHashSet&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;HashSet -&amp;gt; HashMap&lt;br&gt;
TreeSet -&amp;gt; TreeMap&lt;/p&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://docs.oracle.com/javase/tutorial/collections/implementations/set.html" rel="noopener noreferrer"&gt;oracle docs&lt;/a&gt; &amp;amp; &lt;a href="https://www.geeksforgeeks.org/difference-and-similarities-between-hashset-linkedhashset-and-treeset-in-java/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &amp;lt;a name="arraylist-linkedlist-java
&lt;/h3&gt;

&lt;p&gt;"&amp;gt;List Implementation: ArrayList VS LinkedList&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;both implement List &lt;br&gt;
&lt;u&gt;Arraylist&lt;/u&gt;: dyamically add &amp;amp; remove items, automatically resizes iteself, elemnts stored in contiguous memory&lt;br&gt;
&lt;u&gt;LinkedList&lt;/u&gt;: linear data strucutres, every element is seaparate object with data &amp;amp; address part. elements are linked using points &amp;amp; addresses. &lt;/p&gt;
&lt;/blockquote&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%2F63k5xayv9s7hnw79eamg.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%2F63k5xayv9s7hnw79eamg.png" alt="alt text"&gt;&lt;/a&gt;&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%2Fb21jkgm5rt6kp49i06av.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%2Fb21jkgm5rt6kp49i06av.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;manipulating data like removing data. (arraylist, underlying array everything must shift). &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;small&gt;Referece: &lt;a href="https://www.javatpoint.com/difference-between-arraylist-and-linkedlist" rel="noopener noreferrer"&gt;javatpoint&lt;/a&gt; &amp;amp; &lt;a href="https://www.geeksforgeeks.org/arraylist-vs-linkedlist-java/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt; &amp;amp; &lt;a href="https://www.baeldung.com/java-arraylist-linkedlist" rel="noopener noreferrer"&gt;Baeldung&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;What is OOP&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;OOP is a programming prardigm that relies on the concepts of &lt;strong&gt;classes &amp;amp; objects&lt;/strong&gt;.&lt;br&gt;
Developer will strcuture code in terms of classes &amp;amp; objects&lt;/p&gt;
&lt;/blockquote&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%2Ffa5ownhdhv4knihze0zt.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%2Ffa5ownhdhv4knihze0zt.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An alternate paradisn is procedural programming.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;program is divided into samller parts called mathos&lt;/li&gt;
&lt;li&gt;methods are basic entities in this technique&lt;/li&gt;
&lt;li&gt;use methods for code reuability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;OOP's benefits are &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clear structure for program&lt;/li&gt;
&lt;li&gt;Reusable code, Java code is DRY (dont repeat yourself)&lt;/li&gt;
&lt;li&gt;code easier to maintain modify &amp;amp; debug&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;OOP Pillar: Inheritance&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Allows classes to inherit features of other classes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;mechanism to create new class by deriving old classs&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inheritance supports reusability&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Represents &lt;em&gt;IS-A relationship&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&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%2Fhnr3gdkc552rs6fbjpb4.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%2Fhnr3gdkc552rs6fbjpb4.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Subclasses are IS-A relationship with super class.&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 SuperClass{}
public class SubClass **extends** SuperClass{}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Java, object class is super class of all objects.&lt;/p&gt;

&lt;p&gt;&lt;small&gt; References: &lt;a href="https://www.javatpoint.com/inheritance-in-java" rel="noopener noreferrer"&gt;javatpoint&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Types of Inheritance&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;5 types&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;single&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;class inherit another class&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;multilevel&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;chain of inheritance &lt;/li&gt;
&lt;li&gt;Corgi extends Dog, Dog extends Animal&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;heirarchical&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;2 or more classes inherit single class&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;multiple&lt;/strong&gt; (interface) 

&lt;ul&gt;
&lt;li&gt;sub class has &amp;gt;1 super class&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;hybrid&lt;/strong&gt; (interface)

&lt;ul&gt;
&lt;li&gt;mix of 2 or more of above types. &lt;/li&gt;
&lt;li&gt;Since java calsses can't support mutiple inheritance, class cannot support hybrid inheritance. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&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%2Fh7rnqumbd3ijviwvuur0.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%2Fh7rnqumbd3ijviwvuur0.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;small&gt; image from &lt;a href="https://simplesnippets.tech/inheritance-in-java-types-of-inheritance/" rel="noopener noreferrer"&gt;simplesnippets&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt; Why Java class cannot support multiple iheritace &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;reduce complexity / simplify language
If sub class (C) inherits 2 classes (A,B).
If A &amp;amp; B have same method (&lt;code&gt;testMethod()&lt;/code&gt;) &amp;amp; method is called from subclass &lt;code&gt;C.testMethod()&lt;/code&gt;.
Does subclass implement method from A or B?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;small&gt; references: &lt;a href=""&gt;GeeksforGeeks&lt;/a&gt; &amp;amp; &lt;a href="https://www.javatpoint.com/inheritance-in-java" rel="noopener noreferrer"&gt;javatpoint&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Inheritance in Java: OOP&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Reference:&lt;a href="https://www.geeksforgeeks.org/inheritance-in-java/#:%7E:text=important%20facts%20about%20inheritance%20in%20java%20" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/inheritance-in-java/#:~:text=important%20facts%20about%20inheritance%20in%20java%20&lt;/a&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Inheritance in Java done via following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;key words

&lt;ul&gt;
&lt;li&gt;extends&lt;/li&gt;
&lt;li&gt;implements&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;types of classes

&lt;ul&gt;
&lt;li&gt;class&lt;/li&gt;
&lt;li&gt;interface&lt;/li&gt;
&lt;li&gt;abstract class&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt;Important facts&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Default super class

&lt;ul&gt;
&lt;li&gt;besides object, every Java class has super class&lt;/li&gt;
&lt;li&gt;every class is implicty subclass of objet class&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;only 1 super class&lt;/li&gt;
&lt;li&gt;inherit construcotrs

&lt;ul&gt;
&lt;li&gt;cannot inherit super class constructors&lt;/li&gt;
&lt;li&gt;can call super class constructors &lt;code&gt;super()&lt;/code&gt; in subclass constructor&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;private memeber inheritance

&lt;ul&gt;
&lt;li&gt;cannot inherit private memebts (fields, methods, nested classes)&lt;/li&gt;
&lt;li&gt;can access / modify private methodss via super class getter / setters (&lt;code&gt;super.getProperty()&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;What can be done&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inherited fields

&lt;ul&gt;
&lt;li&gt;use them&lt;/li&gt;
&lt;li&gt;Declare new field in subclass&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;inherited methods

&lt;ul&gt;
&lt;li&gt;use them&lt;/li&gt;
&lt;li&gt;override them (use same method signature as superclass &lt;code&gt;@Override&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hide&lt;/strong&gt; &lt;em&gt;static&lt;/em&gt; methods (use same method signature as superclass static method)&lt;/li&gt;
&lt;li&gt;declare new methods&lt;/li&gt;
&lt;li&gt;write new subclass constructor that uses constructor of superclass (&lt;code&gt;super()&lt;/code&gt;) &lt;/li&gt;
&lt;li&gt;Call to &lt;code&gt;super()&lt;/code&gt; must be &lt;strong&gt;first statement&lt;/strong&gt; in subclass&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Extends VS Implements&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu2sp02tb9o35mhf2cx8t.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%2Fu2sp02tb9o35mhf2cx8t.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;OOP Pillar: Abstration&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;process of hiding implementation details &amp;amp; only showing functionality to the user&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Abstractions lets developer focus on &lt;em&gt;what&lt;/em&gt; an object does instead of &lt;em&gt;how&lt;/em&gt; an object is doing it. &lt;/p&gt;

&lt;p&gt;Implementation of function is &lt;strong&gt;hidden from user&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://stackoverflow.com/a/51304341" rel="noopener noreferrer"&gt;SO&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;OOP Abstraction in Java&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Java has 2 ways to achieve abstraction&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Abstarct class (0-100%)&lt;/li&gt;
&lt;li&gt;Interface 100%&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Abstract class

&lt;ul&gt;
&lt;li&gt;class declared as &lt;strong&gt;abstract&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;can have abstarct &amp;amp; non-abstarct methods&lt;/li&gt;
&lt;li&gt;needs to be extended &lt;/li&gt;
&lt;li&gt;child class must implement &lt;strong&gt;all its abstarct methods&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;cannot be instantiated&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;can have constructor&lt;/strong&gt;, data members, abstract &amp;amp; non-abstarct methods.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract class Bike{  
  abstract void run();  
}  
class Honda4 extends Bike{  
  void run(){
  System.out.println("running safely");
}  
public static void main(String args[]){  
   Bike obj = new Honda4();  
   obj.run();   // running safely
 }  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Interface

&lt;ul&gt;
&lt;li&gt;can only have abstract methods (no method body)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Java 8 allows default &amp;amp; static methods&lt;/strong&gt; in interface&lt;/li&gt;
&lt;li&gt;allows multiple inheritance&lt;/li&gt;
&lt;li&gt;class implementing interface must &lt;strong&gt;implement all methods declared in interface&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;cannot be instantiated&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;all fields are public static final
&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%2Fplf96jznnkc7zr4k3gkk.png" alt="alt text"&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface Drawable{  
  void draw();  
  default void msg(){
    System.out.println("default method");
  }  
  static int cube(int x){
    return x*x*x;
  }
}  
class Rectangle implements Drawable{  
  public void draw(){
    System.out.println("drawing rectangle");
  }  
}  


Drawable d=new Rectangle();  
d.draw();  // drawing rectangle 
d.msg();  // default method
Drawable.cube(3); // 27
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://www.javatpoint.com/abstract-class-in-java" rel="noopener noreferrer"&gt;javatpoint&lt;/a&gt; &amp;amp; [javatpoint-interface]&lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Abstarct Class VS interface&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnx8lfensojb9efiimusg.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%2Fnx8lfensojb9efiimusg.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
 From oracle docs&lt;/p&gt;

&lt;p&gt;When to use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Abstract Class&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;share code among &lt;strong&gt;closely related classes&lt;/strong&gt;*&lt;/li&gt;
&lt;li&gt;expect classes extending abstract class have many common methods / fields / require access modifiers other than public (abstract classes can declare non-public methods &amp;amp; fields)&lt;/li&gt;
&lt;li&gt;declare static or non-final fields&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Interface&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;unrelated classes&lt;/strong&gt; will implement interface&lt;/li&gt;
&lt;li&gt;use multiple inheritance&lt;/li&gt;
&lt;li&gt;expect API to not change for a while (if change 1 interface method all classes must change) &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://techvidvan.com/tutorials/abstract-class-vs-interface/" rel="noopener noreferrer"&gt;techvidvan&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;OOP Pillar: Encapsulation&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;OOP technique of wrapping data &amp;amp; code in to &lt;strong&gt;achieve data hiding&lt;/strong&gt;. &lt;br&gt;
technique is &lt;br&gt;
&lt;u&gt;Data hiding&lt;/u&gt;: Unauthorized users should not have access to / modify data&lt;br&gt;
Benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;flexibility&lt;/strong&gt;: can decide which variables have read/ write priviledges&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;control&lt;/strong&gt;: class can control what is stored in fields (is setter is bad input, reject it) &lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&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%2F67yt5ts51drczoh00jus.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%2F67yt5ts51drczoh00jus.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;How does it achieve data hiding?&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;wrap data (vairables / fields) &amp;amp; code that manipualtes data (methods) together in a single unit&lt;/li&gt;
&lt;li&gt;variables are hidden from other classes&lt;/li&gt;
&lt;li&gt;variables are onlt accessed through methods in their current class
&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%2F9t6c7dgnc229kb8ax647.png" alt="alt text"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code now becomes like a "protective shield" that prevents data from being acessed by unauthorize users / means. &lt;/p&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://www.educative.io/blog/object-oriented-programming-concepts-java" rel="noopener noreferrer"&gt;Educative&lt;/a&gt; &amp;amp; &lt;a href="https://www.javatpoint.com/encapsulation" rel="noopener noreferrer"&gt;javatpoint&lt;/a&gt; &amp;amp; &lt;a href="https://www.geeksforgeeks.org/encapsulation-in-java/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt; &amp;amp; &lt;a href="https://www.tutorialspoint.com/java/java_encapsulation.htm" rel="noopener noreferrer"&gt;tutorialspoint&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Encapsulation in Java&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Encapsulation in Java is achieved by&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;declare  fields of class as private&lt;/li&gt;
&lt;li&gt;provide public setter an getter methods &amp;amp; modify and fields
&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class EncapTest {
   private int age;

   public int getAge() {
      return age;
   }

   public void setAge( int newAge) {
      age = newAge;
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Tight Encapsulation&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Class has only private variables / fields&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://stackoverflow.com/questions/11653229/tightly-encapsulated-class#:~:text=if%20a%20class%20is%20having%20only%20private%20variables%20and%20no%20other%20public%20variables%20then%20a%20class%20is%20said%20to%20be%20tightly%20encapsulated%20class" rel="noopener noreferrer"&gt;SO&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;OOP Pillar: Polymorphism&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;ability of object to take on many forms. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Compile-time Polymorphism /  Static polymorphism

&lt;ul&gt;
&lt;li&gt;method overloading &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Runtime Polymorphism / Dynamic method dispatch

&lt;ul&gt;
&lt;li&gt;method overriding
&lt;small&gt; In Java, inheritance allows for polymorphism (method overriding) &lt;/small&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Compile-time polymorphism (&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;static bining / early binding / overloading&lt;/li&gt;
&lt;li&gt;object bound with their functionality at compile time&lt;/li&gt;
&lt;li&gt;call is resolved by the compiler&lt;/li&gt;
&lt;li&gt;
&lt;u&gt; Fast execution&lt;/u&gt;: method to be executed known early (at compile time)&lt;/li&gt;
&lt;li&gt;&lt;u&gt; less flexible/u&amp;gt;: all things execute at compile time&lt;/u&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Run-time polymorphism&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;dynamic binding / late binding / overriding&lt;/li&gt;
&lt;li&gt;object bound with functionality at run time&lt;/li&gt;
&lt;li&gt;method invocation is determined by JVM not the compiler&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;Slow execution&lt;/u&gt;: method to be be executed only known at runtime&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;more flexible&lt;/u&gt; all things execute at runtime&lt;/li&gt;
&lt;/ul&gt;
&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8bbbohi2om1jnppq662d.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%2F8bbbohi2om1jnppq662d.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;small&gt; From: &lt;a href="https://www.geeksforgeeks.org/difference-between-compile-time-and-run-time-polymorphism-in-java/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt;&lt;/small&gt; &lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Polymorphism: Method Overloading&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Allows a class to have more than 1 method with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;same name&lt;/li&gt;
&lt;li&gt;different number &amp;amp; types of argument list
At time of compilation, method calls get resolved by compiler (&lt;code&gt;javac&lt;/code&gt;).
Also known as: compile-time polymorphism / early binding&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are 2 ways this can be performed&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;changing number of arguments&lt;/li&gt;
&lt;li&gt;changing the data type
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public void display(String info){
  System.out.println("String into");
}

// method overloading - change data type
public String display(int info){
  System.out.println(info);
  return "result";
}

public void display(String info1,String info2){
  System.out.println("2 information string");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;When call &lt;code&gt;display&lt;/code&gt; method compiler display results based on the arugments dev pass. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if argument is int

&lt;ul&gt;
&lt;li&gt;call &lt;code&gt;display(int)&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;argument is string

&lt;ul&gt;
&lt;li&gt;call &lt;code&gt;display(string)&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;type promotion can be performed (implicitly) if no matching type is found and if there is no ambiguity. &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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fipgzcmb9q6qtxvhs3w5y.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%2Fipgzcmb9q6qtxvhs3w5y.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Type Promotion Example&lt;/u&gt;&lt;br&gt;
if not matching data types found, one type promoted to another.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public void sum(int a long b){
  System.out.println(a+b);
}

// second argment (int literal) will be promoted to long. 
sum(20,20); // 40
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If there is ambiguity,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;no matching type aguments in metho&lt;/li&gt;
&lt;li&gt;each method promotes simliar number of arguments
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public void sum(int a,long b){
  System.out.println("a method invoked");
}

public void sum(long a,int b){
  System.out.println("b method invoked");
}

//ambiguity
sum(20,20); // Compile Time Error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now there is amiguity, both methods promote simliar number of arguments.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Benefits&lt;/u&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;increase readability of program

&lt;ul&gt;
&lt;li&gt;no need to create &amp;amp; remember different names for functions doing the same thing. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a&gt;Method Overloading Conditions&lt;/a&gt;&lt;br&gt;
&lt;u&gt;CANNOT&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;not possible&lt;/strong&gt; by &lt;strong&gt;changing return type of method only&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;if only change return type but ethod signature remains same, there is ambiguity, which method should be called?&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;can't  overload&lt;/strong&gt; methods that &lt;strong&gt;differ only by static keyword&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;number of parameters, type of parameters &amp;amp; method name is same&lt;/li&gt;
&lt;li&gt;same method signature -&amp;gt; not overlaoding
&lt;u&gt;CAN&lt;/u&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;can &lt;strong&gt;overload main() method&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;main() method usually received string array as arguments. &lt;/li&gt;
&lt;li&gt;but can overload main()method to receive no arguments / different arugments&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;method overloading with &lt;strong&gt;type promotion&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;one type can be &lt;strong&gt;promoted to another implicitly&lt;/strong&gt; if &lt;strong&gt;not matching datatye found&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;one type &lt;strong&gt;cannot be de-promoted&lt;/strong&gt; implicitly.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;can &lt;strong&gt;overload static method&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;can have &amp;gt;=2 static method with same name but difference in input parameters. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;small&gt; reference: &lt;a href="https://www.javatpoint.com/method-overloading-in-java" rel="noopener noreferrer"&gt;javatpoint&lt;/a&gt; &amp;amp; &lt;a href="https://www.geeksforgeeks.org/overloading-in-java/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Polymorphism: Method Overidding&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;allows subclass / child class to provide specific implementation of method that is already provided by by one of its super classes or parent classes&lt;br&gt;
Subclass methods must have&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;same name&lt;/li&gt;
&lt;li&gt;number &amp;amp; type of parameters&lt;/li&gt;
&lt;li&gt;retur type
JVM does the job of method resolution --&amp;gt;
Runtime polymorphism
Type of referred object determines which version of an overriden method will be executed
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Base {
  public void show(){}
}

class Derived extends Base {
  // method overriding
  public void show(){}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Derived der = new Derived();
der.show();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;JVM first checkls if child class (Derived) has provided any implementation to method (show). &lt;br&gt;
yes -&amp;gt; call derived overriden method,&lt;br&gt;
no -&amp;gt; call parent method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Base obj = new Derived();
obj.show();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;reference if of Base type, however object is still of Derived type.&lt;br&gt;
Method resolution takes place at runtime.&lt;br&gt;
show method of Derived class is called.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Derived obj = new Base(); // not valid
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is not valid. &lt;br&gt;
&lt;a&gt;Important&lt;/a&gt;&lt;br&gt;
&lt;u&gt;Important&lt;/u&gt;&lt;br&gt;
type of referred object etermine which version of overidden method will be executed &lt;strong&gt;NOT typoe of reference variable&lt;/strong&gt;.&lt;br&gt;
Runtime object determines which method will be called --&amp;gt; overiding = runtime polymorphism&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Rules&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MUST&lt;/strong&gt; have &lt;strong&gt;same retur type&lt;/strong&gt; or at least &lt;em&gt;subtype of parent's return type&lt;/em&gt;
&lt;u&gt;Exception Handling&lt;/u&gt;
&lt;/li&gt;
&lt;li&gt;super class overriden method does not throw exception

&lt;ul&gt;
&lt;li&gt;sub class overridding method can only throw unchecked exception (i.e. exceptions that are not checked at ompile time)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;super class overridding method throws exception

&lt;ul&gt;
&lt;li&gt;sub class overriding metho can only throw same subclass exception. 
&lt;u&gt;CAN&lt;/u&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;override access-modifiers

&lt;ul&gt;
&lt;li&gt;can &lt;em&gt;allow more but not less access&lt;/em&gt; (eg. protected instance method can be made public but not privde in sub class)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;final methods cannot be overidden

&lt;ul&gt;
&lt;li&gt;final keyword prevents overriding&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;call parent class method in overridding method

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;super.method()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;can override &lt;strong&gt;abstarct method&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;abstarct methods in interface / abstarct class are menat to be overidden in derived class&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;can override synchronied / strictfcp method
&lt;u&gt;CANNOT&lt;/u&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;static&lt;/strong&gt; methods cannot be overridden 

&lt;ul&gt;
&lt;li&gt;static method bound to class not object&lt;/li&gt;
&lt;li&gt;static method with saae method signature in subclass is &lt;em&gt;method hiding NOT method overidding&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;cannot override main method

&lt;ul&gt;
&lt;li&gt;main metod is static&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;private&lt;/strong&gt; methods cannot be overriden

&lt;ul&gt;
&lt;li&gt;private methods not inherited &lt;/li&gt;
&lt;li&gt;private methods bonded during compile time&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;cannot override &lt;strong&gt;constructor&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;parent &amp;amp; child constructor can never have same name&lt;/li&gt;
&lt;li&gt;constructors are not inhierited&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://www.geeksforgeeks.org/overriding-in-java/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt; &amp;amp; &lt;a href="https://www.javatpoint.com/method-overriding-in-java" rel="noopener noreferrer"&gt;javatpoint&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Overriding VS Hiding (static methods)&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;static methods cannot be overidden. But they can be hidden. &lt;br&gt;
When child class has same static method as parent class. Static method  &lt;strong&gt;hides&lt;/strong&gt; another static method. &lt;br&gt;
&lt;u&gt;Difference&lt;/u&gt; Overriding gives run-time polymorphism, hiding does not.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Code example and explanation taken from coderanch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Foo {
    public static void classMethod() {
        System.out.println("classMethod() in Foo");
    }

    public void instanceMethod() {
        System.out.println("instanceMethod() in Foo");
    }
}

class Bar extends Foo {
    public static void classMethod() {
        System.out.println("classMethod() in Bar");
    }

    public void instanceMethod() {
        System.out.println("instanceMethod() in Bar");
    }
}

class Test {
    public static void main(String[] args) {
        Foo f = new Bar();
        f.instanceMethod(); // instanceMethod in Bar
        f.classMethod(); // classMethod in Foo
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;&lt;strong&gt;instanceMethod(overriding)&lt;/strong&gt;&lt;/u&gt;: JVM finds actual class of the instance &lt;em&gt;f&lt;/em&gt; &lt;strong&gt;at run-time&lt;/strong&gt; and determines which method to run. &lt;em&gt;f&lt;/em&gt; is declared as &lt;em&gt;Foo&lt;/em&gt; however class created is actually &lt;em&gt;Bar&lt;/em&gt;. At run-time, JVM find that &lt;em&gt;f&lt;/em&gt; is &lt;em&gt;Bar&lt;/em&gt; instance and calls instanceMethod in Bar. &lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;classMethod(hiding)&lt;/strong&gt;&lt;/u&gt;: class/static method. JVM wont expect to need an actual instance to invoke method. At &lt;strong&gt;compile-time&lt;/strong&gt; compiler looks at &lt;em&gt;declared type (Foo)&lt;/em&gt; of reference to decide which method to call. &lt;/p&gt;

&lt;p&gt;Therefore &lt;strong&gt;static methods do not have run-time polymorphism&lt;/strong&gt;.&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%2Fhy1gdhom4wmqxyneab8a.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%2Fhy1gdhom4wmqxyneab8a.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt; References: &lt;a href="https://stackoverflow.com/a/5436790" rel="noopener noreferrer"&gt;Stack Overflow&lt;/a&gt; &amp;amp; &lt;a href="https://coderanch.com/wiki/659959/Overriding-Hiding" rel="noopener noreferrer"&gt;CodeRanch&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;OOP Java: Association&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Association is relation between 2 separate classes which establishes through their objects. Can be&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;one-to-one&lt;/li&gt;
&lt;li&gt;one-to-many&lt;/li&gt;
&lt;li&gt;many-to-one&lt;/li&gt;
&lt;li&gt;many-to-many
Composition &amp;amp; aggreagation are 2 forms of association&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&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%2Fv1pmta5h85eqza4a84ej.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%2Fv1pmta5h85eqza4a84ej.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Aggregation
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;special form of assocation&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Has-A&lt;/em&gt; relationship&lt;/li&gt;
&lt;li&gt;&lt;em&gt;unidirectional&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;parent can exist without the child &amp;amp; vice-versa
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Foo {
  private Bar bar;
  Foo(Bar bar) {
    this.bar = bar;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If Foo dies, object Bar can still "live".&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%2Fwz5kg36d5t9zget21s6t.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%2Fwz5kg36d5t9zget21s6t.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Composition
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;restricted form of aggreagation, 2 entities are &lt;strong&gt;highly dependent on each other&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;*part-of-realtionship&lt;/li&gt;
&lt;li&gt;child object &lt;strong&gt;cannot exist&lt;/strong&gt; without parent entity&lt;/li&gt;
&lt;li&gt;lifecycle of child is controlled by parent that owns it
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class House {
   private Room room;
   public House() {
       // without a house there can be no room, if house deleted, room is also deleted
       room = new Room();
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fjf9noljykjigaguxp6ei.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%2Fjf9noljykjigaguxp6ei.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Reference: &lt;a href="https://www.geeksforgeeks.org/association-composition-aggregation-java/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt; &amp;amp; &lt;a href="https://www.infoworld.com/article/3029325/exploring-association-aggregation-and-composition-in-oop.html" rel="noopener noreferrer"&gt;infoworld&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;OOP Java: Coupling&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;measure of how much class is dependent on other classes&lt;br&gt;
There should be iminmal dependencis -&amp;gt; low coupling&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;OOP Java: Cohesion&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;measure of how related responsibilitie of class are&lt;br&gt;
class must be highly cohesive (responsibilties shuold be highly related to one another) &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Exceptions handled&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Java Exception Handling frameowork &lt;strong&gt;handles runtime exceptions only&lt;/strong&gt;. Compile time exceptions must be handled by developer or else code wont run&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;small&gt;Reference: &lt;a href="https://www.journaldev.com/1696/exception-handling-in-java#:~:text=Core%20Java,errors%20only" rel="noopener noreferrer"&gt;JournalDev&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Exception Handling: keywords&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;throw
-throws
-try-catch
-finally&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;throw

&lt;ul&gt;
&lt;li&gt;used inside function / block of code&lt;/li&gt;
&lt;li&gt;to explicitly throw an exception in the rpgoram&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;throws

&lt;ul&gt;
&lt;li&gt;used in method signature&lt;/li&gt;
&lt;li&gt;declare exception that might get thrown by method &amp;amp; method will not be handling it.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;try-catch

&lt;ul&gt;
&lt;li&gt;code block for excpetion handling in code&lt;/li&gt;
&lt;li&gt;can have multiple catch blocks with a try block
-can be nested&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;try

&lt;ul&gt;
&lt;li&gt;start of block&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;catch

&lt;ul&gt;
&lt;li&gt;end of try block to handle exceptions&lt;/li&gt;
&lt;li&gt;required parameter that should be of type Exception&lt;/li&gt;
&lt;li&gt;java 7 automatic resource management (catch many resource in 1 catch block)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;catch(IOException | SQLException ex){}&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;finally

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;optional&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;always gets executed wheter exception occured or not&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;onlt NOT executed if exception thrown in finally or if JVM crashes in between (&lt;code&gt;System.exit()&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;can be used with try catch block&lt;/li&gt;
&lt;li&gt;since exceptions halts process of execution, may have some resources open that will not get closed, close them in finally block&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Java Exception Hierarchy&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;When exception is raise, an exception object is geting created.&lt;br&gt;
&lt;em&gt;Throwable&lt;/em&gt; is parent class of Java Exceptions Hierarchy &amp;amp; has 2 chid objects&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Error&lt;/li&gt;
&lt;li&gt;Exceptions

&lt;ul&gt;
&lt;li&gt;checked exceptions&lt;/li&gt;
&lt;li&gt;runtime exceptions&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Java Exceptions are hierarchichal &amp;amp; inheritance used to categorize different types of exceptions&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%2Fj6nco9dm0xr0zhq3y7al.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%2Fj6nco9dm0xr0zhq3y7al.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Errors&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;not possible to anticipate or recover from them (fatal)

&lt;ul&gt;
&lt;li&gt;hardware failure&lt;/li&gt;
&lt;li&gt;OutOfMemoryError&lt;/li&gt;
&lt;li&gt;StackOverflowError&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Exceptions&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;errors that can be anticiapted &amp;amp; recovered from&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Checked Exceptions&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;exceptions checked at compile time&lt;/li&gt;
&lt;li&gt;sually occures when interacting with outside resources&lt;/li&gt;
&lt;li&gt;FileNotFoundException&lt;/li&gt;
&lt;li&gt;IOException&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Runtime Exception&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;exceptions not checked at compile time&lt;/li&gt;
&lt;li&gt;usually due to bad programming / mistakes&lt;/li&gt;
&lt;li&gt;get element from array but give wrong index&lt;/li&gt;
&lt;li&gt;ArrayIndexOutOfBound, Arithemetic Exception&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Java Unchecked VS Runtime Exception&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;CheckedException: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;mandatory to provide try-catch / try-finally block&lt;/li&gt;
&lt;li&gt;force by compiler&lt;/li&gt;
&lt;li&gt;dealing with outside resoruces / networks
Runtime exception: not mandatory&lt;/li&gt;
&lt;li&gt;occur during runtime

&lt;ul&gt;
&lt;li&gt;programming errors&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Checked Exception

&lt;ul&gt;
&lt;li&gt;if not handled, will result in compile time errors

&lt;ul&gt;
&lt;li&gt;either handle with try-catch/  try-finally block or specify method uses &lt;code&gt;throws&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;usually error scenarios outside immediate control of program&lt;/li&gt;

&lt;li&gt;usually interacting with touside resources /networks

&lt;ul&gt;
&lt;li&gt;data base / network &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;eg.&lt;code&gt;ClassNotFoundException&lt;/code&gt;, &lt;code&gt;IOException&lt;/code&gt;, &lt;code&gt;SQLException&lt;/code&gt;, &lt;code&gt;FileNotFound&lt;/code&gt;
&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;li&gt;RuntimeException

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;not checked by compiler&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;will occur once buggy code is executed&lt;/li&gt;
&lt;li&gt;method not forced to delared unchecked exception thrown&lt;/li&gt;
&lt;li&gt;eg. &lt;code&gt;ArithmeticExcetion&lt;/code&gt;, &lt;code&gt;ArrayStoreException&lt;/code&gt;, &lt;code&gt;NullPointerException&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;Extend from CheckedExcetion or Runtime Excpetion?&lt;/u&gt;&lt;br&gt;
Checked Exception&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;method likely to fail &lt;/li&gt;
&lt;li&gt;Checked Exception to ensure alternalte processing in case of failure (enforces proper error handling)
Runtime Exception&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;BUT&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;can make code ugly (lots of boilerplate code)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;small&gt; reference: &lt;a href="https://www.geeksforgeeks.org/checked-vs-unchecked-exceptions-in-java/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt; VS &lt;a href="https://www.java67.com/2012/12/difference-between-runtimeexception-and-checked-exception.html" rel="noopener noreferrer"&gt;java67&lt;/a&gt; &amp;amp; &lt;a href="https://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html" rel="noopener noreferrer"&gt;javadocs&lt;/a&gt;&lt;/small&gt; &lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Java Exception Class Methods&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;all methods depend on parent &lt;code&gt;Throwable&lt;/code&gt; class&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;String getMessage()&lt;/li&gt;
&lt;li&gt;String getLocalizedMessage()&lt;/li&gt;
&lt;li&gt;synchronized Throwable getCause()&lt;/li&gt;
&lt;li&gt;String toString()&lt;/li&gt;
&lt;li&gt;void printStackTrace()&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;getMessage()

&lt;ul&gt;
&lt;li&gt;message String of Throwable&lt;/li&gt;
&lt;li&gt;message provided when creating exception through constructor&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;getLocalisedMessage()

&lt;ul&gt;
&lt;li&gt;subclass can override it to provide locale-specific message to calling program&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;getCause()

&lt;ul&gt;
&lt;li&gt;cause of exception or null if cause is unnown&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;toString()

&lt;ul&gt;
&lt;li&gt;name of throwable class &amp;amp; localised message&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;printStackTarce()

&lt;ul&gt;
&lt;li&gt;prints the stack trace information to the standard error stream &lt;/li&gt;
&lt;li&gt;is overloaded and can pass PrintStream or PrintWriter as an argument to write the stack trace information to file or stream&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Java Exception Handling Criteria&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;ALLOWED&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;finally can still be executed if try &amp;amp; catch have return statements&lt;/li&gt;
&lt;li&gt;try without catch is allowed (&lt;code&gt;try{}finally{}&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;NOT ALLOWED&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;try without catch &amp;amp; without finally &lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Java Exception Handling Best Practice&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use Specific Exceptions

&lt;ul&gt;
&lt;li&gt;dont throw base exception class&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;throw early / fail fast

&lt;ul&gt;
&lt;li&gt;throw exception as early as possible &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;catch late

&lt;ul&gt;
&lt;li&gt;throw exception to caller&lt;/li&gt;
&lt;li&gt;let caller decide how to handle &amp;amp; caller can get notification for exception&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;closing resources

&lt;ul&gt;
&lt;li&gt;close all resources i finally block &lt;/li&gt;
&lt;li&gt;java 7 &lt;a href="https://www.baeldung.com/java-try-with-resources" rel="noopener noreferrer"&gt;try-with-resources&lt;/a&gt; block &lt;/li&gt;
&lt;li&gt;eg. &lt;code&gt;try (Scanner scanner = new Scanner(new File("test.txt"))) {scanner.doSomething()}&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;log exceptions

&lt;ul&gt;
&lt;li&gt;log exception messages when throwing exceptions&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;single catch block for multiple exceptions

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;catch(SQLException|AnotherException ex){}&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://www.journaldev.com/1696/exception-handling-in-java#:~:text=Best%20Practices,Specific%20Exceptions" rel="noopener noreferrer"&gt;JournalDev&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;UML Class Diagram&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Designing the class&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%2Fuploads%2Farticles%2F5i1pphpocvmf8g452h22.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%2F5i1pphpocvmf8g452h22.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Association&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;very generic term&lt;br&gt;
one class used functionalities provided by another class&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%2Fuploads%2Farticles%2Fimo9cmv6wxai3n8bzgnb.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%2Fimo9cmv6wxai3n8bzgnb.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Composition&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;part-of&lt;/strong&gt; &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%2Fuploads%2Farticles%2Fudolq2bfv2coye177kxz.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%2Fudolq2bfv2coye177kxz.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Aggregation &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;one object "owns" another object but child can exist without parent&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%2Fuploads%2Farticles%2Fotjsajyfadsl1wfl2nhp.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%2Fotjsajyfadsl1wfl2nhp.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Multiplicty&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%2Fuploads%2Farticles%2F6r8zx57870lrlb54r9ux.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%2F6r8zx57870lrlb54r9ux.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Generalization / Inheritance / Abstraction&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%2Fuploads%2Farticles%2F1g1kv9hmgntia6jq1bi0.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%2F1g1kv9hmgntia6jq1bi0.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt; &lt;a href="https://www.visual-paradigm.com/guide/uml-unified-modeling-language/uml-aggregation-vs-composition/" rel="noopener noreferrer"&gt;source&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;UML Sequence Diagram&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;denote how objects and classes with code interact with each other&lt;br&gt;
show &lt;strong&gt;sequence of the events&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&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%2Fjymqg3nbpthu6fhm4u8u.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%2Fjymqg3nbpthu6fhm4u8u.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;OOP: Design Patterns&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;basket of pre designed solutions / blueprints to common patterns in OOP or to solve given design problem in code. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Creational: creating objects&lt;br&gt;
Structural: composition of classes &amp;amp; objects which form larger structures&lt;br&gt;
Behaviour: responsibility &amp;amp; interaction between objects &lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Singleton Design Pattern&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;restricts instantiation of class to one. Ensure only 1 instance of class exists in JVM.&lt;br&gt;
&lt;u&gt;Used for&lt;/u&gt;: logging, drivers object, cahcing &amp;amp; thread pool. &lt;br&gt;
&lt;u&gt;Implementation&lt;/u&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;private construtor to restrict instantiation of class from other classes&lt;/li&gt;
&lt;li&gt;private static variable of same class that is only instance of class&lt;/li&gt;
&lt;li&gt;public static method &lt;code&gt;getInstance()&lt;/code&gt; returning instance of class, so other classes can get instance of singleton&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;Techniques:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Eager initialization - create singleton BEFORE its used

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;public static final SingletonClass instance = new SingletongClass()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;use &lt;code&gt;static&lt;/code&gt; block&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Lazy Initlialization

&lt;ul&gt;
&lt;li&gt;creates instance in &lt;code&gt;getInstance()&lt;/code&gt; method. can cause issues in &lt;em&gt;multithreaded&lt;/em&gt; environment&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Thread Sage singleton (for laxy initialization)

&lt;ul&gt;
&lt;li&gt;make &lt;code&gt;getInstance()&lt;/code&gt; method &lt;code&gt;synchronized&lt;/code&gt; so only 1 thread executes this method at a time&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;use Enum to declare singleton

&lt;ul&gt;
&lt;li&gt;Java ensures any enum value only instantiated once. &lt;em&gt;does not allow lazy initialization&lt;/em&gt;. &lt;code&gt;public enum EnumSingleton{INSTANCE;}&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Serialization &amp;amp; singleton

&lt;ul&gt;
&lt;li&gt;implement &lt;code&gt;readResolve()&lt;/code&gt; method. When implement serializable interface, when deserialize singleton class, new instance of object is created. &lt;code&gt;protected Object readResolve() {return getInstance()}&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftqrwutqcmnqiod6dsxj0.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%2Ftqrwutqcmnqiod6dsxj0.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://vainolo.com/2012/04/29/singleton-design-pattern-sequence-diagram/" rel="noopener noreferrer"&gt;vainolo&lt;/a&gt; &amp;amp; &lt;a href="https://www.journaldev.com/1377/java-singleton-design-pattern-best-practices-examples" rel="noopener noreferrer"&gt;journalDev&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Factory Design Pattern&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;define an interface or abstract class for creating an object but let the subclasses decide which class to instantiate&lt;br&gt;
Responsibility of instantiation is on &lt;em&gt;factory class&lt;/em&gt; not &lt;em&gt;client program&lt;/em&gt;.&lt;/p&gt;
&lt;/blockquote&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%2Fzu09l9s39kiiu8jl3d1s.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%2Fzu09l9s39kiiu8jl3d1s.png" alt="alt text"&gt;&lt;/a&gt;&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%2Fuploads%2Farticles%2F9tlijortx4sknrbghe9f.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%2F9tlijortx4sknrbghe9f.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Implementation&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;super class (&lt;code&gt;Computer&lt;/code&gt;) can be interface , abstart class or normal class&lt;/li&gt;
&lt;li&gt;Factory class can be singleton or can keep the method returning classes (&lt;code&gt;getComputer&lt;/code&gt;) as static. 

&lt;ul&gt;
&lt;li&gt;very troublesome to keep instantiating factory clas&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;based on input parameter, different subclass created &amp;amp; returned
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class ComputerFactory {

    public static Computer getComputer(String type, String ram, String hdd, String cpu){
        if("PC".equalsIgnoreCase(type)) return new PC(ram, hdd, cpu);
        else if("Server".equalsIgnoreCase(type)) return new Server(ram, hdd, cpu);

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

&lt;/div&gt;


&lt;p&gt;Advantage&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;remove instantiation of actual classes from client code&lt;/li&gt;
&lt;li&gt;layer of abstraction between implementation classes(&lt;code&gt;PC&lt;/code&gt; &amp;amp; &lt;code&gt;Server&lt;/code&gt;) &amp;amp; client code (&lt;code&gt;ComputerFactory&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Abstract Factory &lt;/u&gt;&lt;br&gt;
Abstarct factory is like a factory of factories. &lt;/p&gt;

&lt;p&gt;&lt;small&gt;Reference: &lt;a href="https://www.javatpoint.com/factory-method-design-pattern" rel="noopener noreferrer"&gt;javatpoint&lt;/a&gt;&amp;amp;  &lt;a href="https://www.journaldev.com/1392/factory-design-pattern-in-java" rel="noopener noreferrer"&gt;JouralDev&lt;/a&gt; &amp;amp; &lt;a href="https://www.tutorialspoint.com/design_pattern/factory_pattern.htm" rel="noopener noreferrer"&gt;tutorialspoint&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Decorator Design Patterns&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Add new features to existing object with changing its structure&lt;br&gt;
Decorate class wraps original class &amp;amp; provides additional functionality, keeping class methods signature intact &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;uses abstract classes or interface with **composition&lt;/em&gt;* to implement*&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&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%2Fb73zmh25a0ippk1qq9h6.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%2Fb73zmh25a0ippk1qq9h6.png" alt="alt text"&gt;&lt;/a&gt;&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%2Fuseas80fsvkt0z3bupia.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%2Fuseas80fsvkt0z3bupia.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Decorator class implements HAS-A relationship with component interface. Concrete Decorators will extend base decorator functionality &amp;amp; modify component behaviour.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Component Implementations
public class BasicCar implements Car {

    @Override
    public void assemble() {
        System.out.print("Basic Car.");
    }

}

// Decorator
public class CarDecorator implements Car {

    protected Car car;

    public CarDecorator(Car c){
        this.car=c;
    }

    @Override
    public void assemble() {
        this.car.assemble();
    }

}

// Concrete Decorator
public class SportsCar extends CarDecorator {

    public SportsCar(Car c) {
        super(c);
    }

    @Override
    public void assemble(){
        super.assemble();
        System.out.print(" Adding features of Sports Car.");
    }
}
public class LuxuryCar extends CarDecorator {

    public LuxuryCar(Car c) {
        super(c);
    }

    @Override
    public void assemble(){
        super.assemble();
        System.out.print(" Adding features of Luxury Car.");
    }
}

// Testing Decorator Program
Car sportsCar = new SportsCar(new BasicCar());
sportsCar.assemble(); 
// Basic Car Adding features of Sports Car
        System.out.println("\n*****");

Car sportsLuxuryCar = new SportsCar(new LuxuryCar(new BasicCar())); sportsLuxuryCar.assemble(); 
// Basic car. Adding features of Luxury Car. Adding Features of SportsCar. 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://www.baeldung.com/java-decorator-pattern" rel="noopener noreferrer"&gt;Baeldung&lt;/a&gt; &amp;amp; &lt;a href="https://www.tutorialspoint.com/design_pattern/decorator_pattern.htm" rel="noopener noreferrer"&gt;tutorialspoint&lt;/a&gt; &amp;amp; &lt;a href="https://www.journaldev.com/1540/decorator-design-pattern-in-java-example" rel="noopener noreferrer"&gt;JournalDev&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Flyweight Design Pattern&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;factory which recycles created objects by storing them after creation. Existing object is returned otherwise new one created.&lt;br&gt;
&lt;strong&gt;Flyweight objects must be immutable, any operation on state must be performance by factory&lt;/strong&gt;.&lt;br&gt;
&lt;u&gt;Benefits&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;decrease memory footprint&lt;/li&gt;
&lt;li&gt;increase performance&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt; When to use &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;number of object to be created by application should be huge&lt;/li&gt;
&lt;li&gt;object creation heavy on memory &amp;amp; can be time consuming&lt;/li&gt;
&lt;li&gt;flyweight object must be divided into &lt;strong&gt;intrinsic&lt;/strong&gt; &amp;amp; &lt;strong&gt;extrinsic&lt;/strong&gt;. Intrinsic properties make object nuique, extrinsic properties are set by client code &amp;amp; used to perform different operations. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://www.baeldung.com/java-flyweight" rel="noopener noreferrer"&gt;Baeldung&lt;/a&gt; &amp;amp; &lt;a href="https://www.tutorialspoint.com/design_pattern/flyweight_pattern.htm" rel="noopener noreferrer"&gt;tutorialspoint&lt;/a&gt; &amp;amp; &lt;a href="https://www.journaldev.com/1562/flyweight-design-pattern-java" rel="noopener noreferrer"&gt;JournalDev&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Adapter Design Pattern&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;act as connector between 2 incompatible interfaces that otherwise cannot be connected directly. &lt;br&gt;
2 implementations&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;class adapter

&lt;ul&gt;
&lt;li&gt;uses &lt;strong&gt;inheritance&lt;/strong&gt; &amp;amp; extends adaptee interface&lt;/li&gt;
&lt;li&gt;single class called adaptor between 2 incompatible interfaces&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;object adapter

&lt;ul&gt;
&lt;li&gt;uses &lt;strong&gt;composition&lt;/strong&gt; &amp;amp; adapter contains adaptee object. &lt;/li&gt;
&lt;li&gt;wraps around class, allowing 2 classes / interface to work together without changing any code on either side. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt; Object Adapter&lt;/u&gt;&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%2Fuploads%2Farticles%2Fogt558q6r8in5dldzhkn.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%2Fogt558q6r8in5dldzhkn.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Client can only see target&lt;/li&gt;
&lt;li&gt;adapter class implements target interface &amp;amp; provides implementation for &lt;code&gt;Request()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;adapter is &lt;strong&gt;composed&lt;/strong&gt; with adaptee &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Process &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Client makes call to adapter&lt;/li&gt;
&lt;li&gt;adapter does conversion&lt;/li&gt;
&lt;li&gt;makes rqeuired call to adaptee
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class SocketObjectAdapterImpl implements Targer{

//Using Composition for adapter pattern
    private Adaptee sock = new Adaptee ();

    @Override
    public Volt get120Volt() {
        return sock.getVolt();
    }

    @Override
    public Volt get12Volt() {
        Volt v= sock.getVolt();
        return convertVolt(v,10);
    }

    @Override
    public Volt get3Volt() {
        Volt v= sock.getVolt();
        return convertVolt(v,40);
    }

    private Volt convertVolt(Volt v, int i) {
        return new Volt(v.getVolts()/i);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;u&gt;Class Adapter&lt;/u&gt;&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%2Fuploads%2Farticles%2Fra8x008gygn4w2szngx4.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%2Fra8x008gygn4w2szngx4.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;adaptor implements target&lt;/li&gt;
&lt;li&gt;inherits adaptee&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Process &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Client makes call to adapter&lt;/li&gt;
&lt;li&gt;adapter &lt;strong&gt;DOES NOT&lt;/strong&gt; delegate request to adaptee&lt;/li&gt;
&lt;li&gt;adapter uses &lt;strong&gt;inherited method&lt;/strong&gt; (&lt;code&gt;SpecificRequest()&lt;/code&gt;) from adaptee to handle specific request
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Using inheritance for adapter pattern
public class SocketClassAdapterImpl extends Adaptee implements Targer{

    @Override
    public Volt get120Volt() {
        return getVolt();
    }

    @Override
    public Volt get12Volt() {
        Volt v= getVolt();
        return convertVolt(v,10);
    }

    @Override
    public Volt get3Volt() {
        Volt v= getVolt();
        return convertVolt(v,40);
    }

    private Volt convertVolt(Volt v, int i) {
        return new Volt(v.getVolts()/i);
    }

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

&lt;/div&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%2Fp4gt5jhpm36f6dcee470.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%2Fp4gt5jhpm36f6dcee470.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt; &lt;a href="https://www.journaldev.com/1487/adapter-design-pattern-java" rel="noopener noreferrer"&gt;JournalDev&lt;/a&gt; &amp;amp; &lt;a href="https://www.geeksforgeeks.org/adapter-pattern/" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Observer Design Pattern&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;one-to-many&lt;/em&gt; dependency between objects so when 1 object (subject) changes state, all of its dependents (observers) are notified &amp;amp; updated automatically.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;eg. wishlist item is out of stock, tell website to notify you when it is in stock.&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%2Fuploads%2Farticles%2Fr3s497ri0g2oikegvyzd.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%2Fr3s497ri0g2oikegvyzd.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// subject
public interface Subject {

//methods to register and unregister observers
  public void register(Observer obj);
  public void unregister(Observer obj);

//method to notify observers of change
  public void notifyObservers();

//method to get updates from subject
  public Object getUpdate(Observer obj);
}

// object
public interface Observer {

//method to update the observer, used by subject
public void update();
// observers will print updated subject in this method

//attach with subject to observe
public void setSubject(Subject sub);
}

public class MyTopic implements Subject {

    private List&amp;lt;Observer&amp;gt; observers;
    private String message;
    private boolean changed;
    private final Object MUTEX= new Object();

    public MyTopic(){
        this.observers=new ArrayList&amp;lt;&amp;gt;();
    }
    @Override
    public void register(Observer obj) {
        if(obj == null) throw new NullPointerException("Null Observer");
        synchronized (MUTEX) {
        if(!observers.contains(obj)) observers.add(obj);
        }
    }

    @Override
    public void unregister(Observer obj) {
        synchronized (MUTEX) {
        observers.remove(obj);
        }
    }

    @Override
    public void notifyObservers() {
        List&amp;lt;Observer&amp;gt; observersLocal = null;
        //synchronization is used to make sure any observer registered after message is received is not notified
        synchronized (MUTEX) {
            if (!changed)
                return;
            observersLocal = new ArrayList&amp;lt;&amp;gt;(this.observers);
            this.changed=false;
        }
        for (Observer obj : observersLocal) {
            obj.update();
        }

    }

    @Override
    public Object getUpdate(Observer obj) {
        return this.message;
    }

    //method to post message to the topic
    public void postMessage(String msg){
        System.out.println("Message Posted to Topic:"+msg);
        this.message=msg;
        this.changed=true;
        notifyObservers();
    }

}

//create subject
MyTopic topic = new MyTopic();

//create observers
Observer obj1 = new MyTopicSubscriber("Obj1");
Observer obj2 = new MyTopicSubscriber("Obj2");
Observer obj3 = new MyTopicSubscriber("Obj3");

//register observers to the subject
topic.register(obj1);
topic.register(obj2);
topic.register(obj3);

//attach observer to subject
obj1.setSubject(topic);
obj2.setSubject(topic);
obj3.setSubject(topic);

//check if any update is available
obj1.update(); // Obj1:: No new message

//now send message to subject
topic.postMessage("New Message");

// OUTPUT
Message Posted to Topic:New Message
Obj1:: Consuming message::New Message
Obj2:: Consuming message::New Message
Obj3:: Consuming message::New Message
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://docs.oracle.com/javase/tutorial/essential/concurrency/newlocks.html" rel="noopener noreferrer"&gt;Mutex subject&lt;/a&gt; in code snippet is used for locks&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Sequence Diagramm&lt;/u&gt;&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%2Fuploads%2Farticles%2Fvun11twd1b0r1rkpdfcp.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%2Fvun11twd1b0r1rkpdfcp.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Reference: &lt;a href="https://www.vogella.com/tutorials/DesignPatternObserver/article.html" rel="noopener noreferrer"&gt;vogella&lt;/a&gt; &amp;amp; &lt;a href="https://www.journaldev.com/1739/observer-design-pattern-in-java" rel="noopener noreferrer"&gt;JournalDev&lt;/a&gt; &amp;amp; &lt;a href="https://www.baeldung.com/java-observer-pattern" rel="noopener noreferrer"&gt;Baeldung&lt;/a&gt; &amp;amp; &lt;a href="https://www.tutorialspoint.com/design_pattern/observer_pattern.htm" rel="noopener noreferrer"&gt;tutorialspoint&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Strategy Design Patterns&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;class behaviour or algorithm can be changed at runtime.&lt;br&gt;
eg. &lt;code&gt;Collections.sort()&lt;/code&gt;&lt;br&gt;
2 ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;interface &amp;amp; implement many times

&lt;ul&gt;
&lt;li&gt;start with interface which is used to apply an algorithm&lt;/li&gt;
&lt;li&gt;implement it multiple times for each possible algorithm&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Java 8 &amp;amp; lambdas

&lt;ul&gt;
&lt;li&gt;use lambda in place of anonymous inner type&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&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%2Fr5aq7vj4b13ga1kiq10d.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%2Fr5aq7vj4b13ga1kiq10d.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt; Interface &amp;amp; Implementations &lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Startegy interface
public interface Strategy {
   public int doOperation(int num1, int num2);
}

// Startegy concrete classes
public class OperationAdd implements Strategy{
   @Override
   public int doOperation(int num1, int num2) {
      return num1 + num2;
   }
}
public class OperationSubstract implements Strategy{
   @Override
   public int doOperation(int num1, int num2) {
      return num1 - num2;
   }
}
public class OperationMultiply implements Strategy{
   @Override
   public int doOperation(int num1, int num2) {
      return num1 * num2;
   }
}

// use context to call &amp;amp; execute startegy interface
public class Context {
   private Strategy strategy;

   public Context(Strategy strategy){
      this.strategy = strategy;
   }

   public int executeStrategy(int num1, int num2){
      return strategy.doOperation(num1, num2);
   }
}

Context context = new Context(new OperationAdd());      
      System.out.println(context.executeStrategy(10, 5)); // 15

context = new Context(new OperationSubstract());        
      System.out.println(context.executeStrategy(10, 5)); //5 

context = new Context(new OperationMultiply());     
      System.out.println(context.executeStrategy(10, 5)); // 50
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt; Using Java Lambdas &lt;/u&gt;&lt;br&gt;
Java 8 can create static methods in interfaces&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 Discounter {
    BigDecimal applyDiscount(BigDecimal amount);

    static Discounter christmasDiscounter() {
        return amount -&amp;gt; amount.multiply(BigDecimal.valueOf(0.9));
    }

    static Discounter newYearDiscounter() {
        return amount -&amp;gt; amount.multiply(BigDecimal.valueOf(0.8));
    }

    static Discounter easterDiscounter() {
        return amount -&amp;gt; amount.multiply(BigDecimal.valueOf(0.5));
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt; Sequence Diagram &lt;/u&gt;&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%2Fuploads%2Farticles%2Fyedw6xsauy422uc2qk8b.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%2Fyedw6xsauy422uc2qk8b.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://www.baeldung.com/java-strategy-pattern" rel="noopener noreferrer"&gt;Baeldung&lt;/a&gt; &amp;amp; &lt;a href="https://www.tutorialspoint.com/design_pattern/strategy_pattern.htm" rel="noopener noreferrer"&gt;tutorialspoint&lt;/a&gt; &amp;amp; &lt;a href="https://www.journaldev.com/1754/strategy-design-pattern-in-java-example-tutorial" rel="noopener noreferrer"&gt;JournalDev&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;State Design Patterns&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;allows object to change its behaviour (during run time) when the internal state of the object changes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;used when: object depends on its state &amp;amp; behaviour must be changed during run time depending on its internal state. 
Implementation
&lt;strong&gt;allow object to change its behaviour without changing its class&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&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%2Frs96f7y9hb14e6masog0.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%2Frs96f7y9hb14e6masog0.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
Context object will change its behaviour based on its internal state.&lt;br&gt;
Context object will have an associated state which can change during program execution&lt;br&gt;
Context will &lt;strong&gt;delegate behaviour to state implementation&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Example: TV remote can be on or off&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Staet interface 
public interface State {
    public void doAction();
}

// State implementations
public class TVStartState implements State {

    @Override
    public void doAction() {
        System.out.println("TV is turned ON");
    }

}

public class TVStopState implements State {

    @Override
    public void doAction() {
        System.out.println("TV is turned OFF");
    }

}

public class TVContext implements State {

    private State tvState;

    public void setState(State state){
        this.tvState=state;
    }

    public State getState() {
        return this.tvState;
    }

    @Override
    public void doAction() {
        this.tvState.doAction();
    }

}


TVContext context = new TVContext();
State tvStartState = new TVStartState();
State tvStopState = new TVStopState();
            context.setState(tvStartState);
context.doAction(); // TV is turned on  
        context.setState(tvStopState);
context.doAction(); // TV is turned off
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fe01sylybgj4wy7zyrsmf.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%2Fe01sylybgj4wy7zyrsmf.png" alt="alt text"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;small&gt;Reference: &lt;a href="https://www.baeldung.com/java-state-design-pattern" rel="noopener noreferrer"&gt;Baeldung&lt;/a&gt; &amp;amp; &lt;a href="https://www.tutorialspoint.com/design_pattern/state_pattern.htm" rel="noopener noreferrer"&gt;tutorialspoint&lt;/a&gt; &amp;amp; &lt;a href="https://www.journaldev.com/1751/state-design-pattern-java" rel="noopener noreferrer"&gt;JournalDev&lt;/a&gt; &amp;amp; &lt;a href="https://dzone.com/articles/state-design-pattern-in-java" rel="noopener noreferrer"&gt;DZone&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>RDBMS Theory</title>
      <dc:creator>limjy</dc:creator>
      <pubDate>Wed, 12 May 2021 18:48:19 +0000</pubDate>
      <link>https://dev.to/jing/rdbms-theory-3fkf</link>
      <guid>https://dev.to/jing/rdbms-theory-3fkf</guid>
      <description>&lt;h2&gt;
  
  
  TOC
&lt;/h2&gt;

&lt;p&gt;&lt;u&gt; Basic &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Features&lt;/li&gt;
&lt;li&gt;E-R &amp;amp; OO model&lt;/li&gt;
&lt;li&gt;levels of data abstraction&lt;/li&gt;
&lt;li&gt;Types&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Keys &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keys-function&lt;/li&gt;
&lt;li&gt;Different Types of keys&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Transactions &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Transactions&lt;/li&gt;
&lt;li&gt;Operations&lt;/li&gt;
&lt;li&gt;ACID properties&lt;/li&gt;
&lt;li&gt;Schedule&lt;/li&gt;
&lt;li&gt;Isolation Levels&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Others &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DB Recovery&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://www.educba.com/rdbms-interview-questions/" rel="noopener noreferrer"&gt;https://www.educba.com/rdbms-interview-questions/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.educba.com/dbms-keys/?source=leftnav" rel="noopener noreferrer"&gt;https://www.educba.com/dbms-keys/?source=leftnav&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.guru99.com/dbms-keys.html" rel="noopener noreferrer"&gt;https://www.guru99.com/dbms-keys.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.studytonight.com/dbms/database-key.php" rel="noopener noreferrer"&gt;https://www.studytonight.com/dbms/database-key.php&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/types-of-keys-in-relational-model-candidate-super-primary-alternate-and-foreign/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/types-of-keys-in-relational-model-candidate-super-primary-alternate-and-foreign/&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Features&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Name

&lt;ul&gt;
&lt;li&gt;name of table&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;attribute

&lt;ul&gt;
&lt;li&gt;column&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;tuple

&lt;ul&gt;
&lt;li&gt;row in the table&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;E-R &amp;amp; OO  Model&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Entity-Relationship model &amp;amp; Object oriented model&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;E-R

&lt;ul&gt;
&lt;li&gt;top-down approach&lt;/li&gt;
&lt;li&gt;real life scenarios are entityes&lt;/li&gt;
&lt;li&gt;properties &amp;amp; attributes in ER diagram &amp;amp; connections &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Object oriented

&lt;ul&gt;
&lt;li&gt;scenarios are objects&lt;/li&gt;
&lt;li&gt;objects with similar functionalities are grouped together &amp;amp; linked to different other objects
&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%2Fo3sthyn5m4iie6ibduy7.png" alt="alt text"&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%2Fh1hhlex1ts00l3216vm2.png" alt="alt text"&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;small&gt;&lt;a href="https://www.tutorialspoint.com/Comparison-between-E-R-Model-and-Object-Oriented-Model" rel="noopener noreferrer"&gt;reference&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Levels of Data Abstraction&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Physical Level

&lt;ul&gt;
&lt;li&gt;how data is stored&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Logical Level

&lt;ul&gt;
&lt;li&gt;what type of data stored &amp;amp;&lt;/li&gt;
&lt;li&gt;relationship between data&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;View Level

&lt;ul&gt;
&lt;li&gt;entire DB&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Types&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;In memory

&lt;ul&gt;
&lt;li&gt;redis&lt;/li&gt;
&lt;li&gt;memcache&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;in-memory DB can be made persistent with transaction log&lt;br&gt;
&lt;a href="https://medium.com/@denisanikin/what-an-in-memory-database-is-and-how-it-persists-data-efficiently-f43868cff4c1" rel="noopener noreferrer"&gt;https://medium.com/@denisanikin/what-an-in-memory-database-is-and-how-it-persists-data-efficiently-f43868cff4c1&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Keys Function&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;help uniquely rows of data in table&lt;/li&gt;
&lt;li&gt;establish relationship between tables&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Types of Keys&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Super key

&lt;ul&gt;
&lt;li&gt;group of single OR multiple keys which identifies rows in table&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Candidate key

&lt;ul&gt;
&lt;li&gt;super key but without attributes not important for uniquely identifying tuples/  rows.&lt;/li&gt;
&lt;li&gt;subset of super key&lt;/li&gt;
&lt;li&gt;can be &amp;gt;1 candidate key for a table&lt;/li&gt;
&lt;li&gt;cannot be NULL or empty. &lt;/li&gt;
&lt;li&gt;can be a combination of &amp;gt;1 attributes&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Primary key

&lt;ul&gt;
&lt;li&gt;uniquely identify each record in a table&lt;/li&gt;
&lt;li&gt;cannot be NULL&lt;/li&gt;
&lt;li&gt;cannot have duplicate values&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Composite Key

&lt;ul&gt;
&lt;li&gt;consists of &amp;gt;=2 attributes that uniquely identify any record in a table &lt;/li&gt;
&lt;li&gt;attributes forming composite key &lt;strong&gt;are not a key individually&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;individual key cannot be foreign key&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Foreign key

&lt;ul&gt;
&lt;li&gt;column creating relationship between 2 tables&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Alternate key

&lt;ul&gt;
&lt;li&gt;candidate keys other than primary key&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Compound key

&lt;ul&gt;
&lt;li&gt;&amp;gt;=2 attributes that can uniquely identiy records. &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;any part can be foreign key&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Surrogate key

&lt;ul&gt;
&lt;li&gt;artificial key which aims to uniquely identify each record&lt;/li&gt;
&lt;li&gt;its only purpose is to be unique identifier (eg. incremental key, &lt;/li&gt;
&lt;li&gt;it has no actual meaning&lt;/li&gt;
&lt;li&gt;eg. incremental key, time stamp&lt;/li&gt;
&lt;li&gt;used when: &lt;/li&gt;
&lt;li&gt;no property has the parameter of primary key&lt;/li&gt;
&lt;li&gt;primary key is too big or complicate&lt;/li&gt;
&lt;/ul&gt;


&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7fw35dgnpn1ff6bo749z.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%2F7fw35dgnpn1ff6bo749z.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Further reading&lt;br&gt;
&lt;a href="https://www.tutorialspoint.com/Surrogate-Key-in-RDBMS" rel="noopener noreferrer"&gt;https://www.tutorialspoint.com/Surrogate-Key-in-RDBMS&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.hackertrail.com/talent/database/sql-interview-questions-answers/" rel="noopener noreferrer"&gt;https://www.hackertrail.com/talent/database/sql-interview-questions-answers/&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Transactions&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;logical unit of processing &lt;br&gt;
entails one or more database access operation.&lt;/p&gt;
&lt;/blockquote&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%2Frih2vb1kxcog3tpxn1mi.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%2Frih2vb1kxcog3tpxn1mi.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;successful transaction can change database from one consistent state of anther&lt;/li&gt;
&lt;li&gt;if DB is in inconsistent state before transaction it will be in inconsistent state after
&lt;small&gt;&lt;a href="https://www.guru99.com/dbms-transaction-management.html" rel="noopener noreferrer"&gt;reference&lt;/a&gt;&lt;/small&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Transaction Operations&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Transactions access data in 2 ways&lt;br&gt;
&lt;strong&gt;READ&lt;/strong&gt;: read value from DB store in a buffer in main memory&lt;br&gt;
&lt;strong&gt;WRITE&lt;/strong&gt;: write value back to database from buffer&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;However transaction may fail before all operations in it are finished (due to hardware / software / power failure).&lt;/p&gt;

&lt;p&gt;So there are two operators&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Commit&lt;/strong&gt;: save work done permanently&lt;br&gt;
&lt;strong&gt;Rollback&lt;/strong&gt;: undo work done&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;small&gt;&lt;a href="https://www.javatpoint.com/dbms-transaction-processing-concept" rel="noopener noreferrer"&gt;reference&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Transaction Operations&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;To maintain consistency in database before &amp;amp; after transaction ACID properties are followed&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Atomicity

&lt;ul&gt;
&lt;li&gt;transaction takes place at once or not at all&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Consistency

&lt;ul&gt;
&lt;li&gt;DB must be consistent before and after transaction&lt;/li&gt;
&lt;li&gt;eg. if operations of add &amp;amp; subtract are executed concurrently, DB may be inconsistent (transactions may read different values)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Isolation

&lt;ul&gt;
&lt;li&gt;result of transaction should not be visible to others before transaction is committed&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Durable

&lt;ul&gt;
&lt;li&gt;once database committed transaction, changes made by transaction should be permanent &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Inconsistency Example &lt;/u&gt;&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%2Fuploads%2Farticles%2Fo888r6vg29tfge6jtkx2.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%2Fo888r6vg29tfge6jtkx2.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/concurrency-control-in-dbms/?ref=lbp" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/concurrency-control-in-dbms/?ref=lbp&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/acid-" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/acid-&lt;/a&gt;&lt;br&gt;
properties-in-dbms/&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Transaction Schedule&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;series of operations from 1 or more transactions&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Serial

&lt;ul&gt;
&lt;li&gt;1 transaction completely executes before starting another&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Concurrent

&lt;ul&gt;
&lt;li&gt;operations of transaction are interleaved with operations of other transactions of a schedule&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Transaction Isolation Levels&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;part of ACID properties&lt;br&gt;
Isolation Level define degree to which transaction must be isolated from data modification made by any other transaction in database system&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Isolation levels determine by following phenomena&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dirty Read

&lt;ul&gt;
&lt;li&gt;transaction reads data not yet commited&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Non Repeatable read

&lt;ul&gt;
&lt;li&gt;transaction reads same row twice gets different value each time&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Phantom Read

&lt;ul&gt;
&lt;li&gt;2 same queries executed but rows retrieved by two are different. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;There are 4 isolation levles&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Read Uncommitted

&lt;ul&gt;
&lt;li&gt;lowest isolation level&lt;/li&gt;
&lt;li&gt;allow dirty reads (1 transaction can read uncommitted changes made by other transactions) &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Read Committed

&lt;ul&gt;
&lt;li&gt;no dirty read&lt;/li&gt;
&lt;li&gt;any data read is committed the moment it is read&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Repeatable Read

&lt;ul&gt;
&lt;li&gt;most restrictive&lt;/li&gt;
&lt;li&gt;holds read locks on all rows it references and write locks on al rows it inserts / updates / deletes&lt;/li&gt;
&lt;li&gt;other transactions cannot read update or delete rows -&amp;gt; avoid non-repeatable read. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Serializable

&lt;ul&gt;
&lt;li&gt;highest isolation level&lt;/li&gt;
&lt;li&gt;transaction will be serially executed &lt;/li&gt;
&lt;/ul&gt;


&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffedbsvei0wng2j1d1gac.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%2Ffedbsvei0wng2j1d1gac.png" alt="alt text"&gt;&lt;/a&gt;&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%2Fhczac77vguej2f7a1yc1.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%2Fhczac77vguej2f7a1yc1.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;DB recovery&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;recovery techniques are heavily dependent on existence of &lt;strong&gt;system log&lt;/strong&gt;&lt;br&gt;
System log keeps track of all transaction operations that affect DB value&lt;br&gt;
information is needed to recover from transaction failure. &lt;/p&gt;
&lt;/blockquote&gt;

</description>
    </item>
    <item>
      <title>Operating System</title>
      <dc:creator>limjy</dc:creator>
      <pubDate>Sun, 09 May 2021 18:08:23 +0000</pubDate>
      <link>https://dev.to/jing/operating-system-240e</link>
      <guid>https://dev.to/jing/operating-system-240e</guid>
      <description>&lt;p&gt;My summary of Operating system self study&lt;/p&gt;

&lt;h2&gt;
  
  
  TOC
&lt;/h2&gt;

&lt;p&gt;&lt;u&gt; Memory &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Operating System&lt;/li&gt;
&lt;li&gt;Basics&lt;/li&gt;
&lt;li&gt;Memory Hierarchy Design&lt;/li&gt;
&lt;li&gt;RAM memory&lt;/li&gt;
&lt;li&gt;Logical VS Physical Address in OS&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;Memory&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CPU-virtualization&lt;/li&gt;
&lt;li&gt;Time Sharing&lt;/li&gt;
&lt;li&gt;Address Space&lt;/li&gt;
&lt;li&gt;
Stack VS heap Memory &lt;/li&gt;
&lt;li&gt;Virtualization&lt;/li&gt;
&lt;li&gt;Address Translation: MMU&lt;/li&gt;
&lt;li&gt;Segmentation&lt;/li&gt;
&lt;li&gt;Fragmentation&lt;/li&gt;
&lt;li&gt;Paging-Intro&lt;/li&gt;
&lt;li&gt;Page Table&lt;/li&gt;
&lt;li&gt;Page Table contents&lt;/li&gt;
&lt;li&gt;TLB&lt;/li&gt;
&lt;li&gt;Virtual Memory: Secondary memory&lt;/li&gt;
&lt;li&gt;Swap Space&lt;/li&gt;
&lt;li&gt;Page Fault&lt;/li&gt;
&lt;li&gt;Page Replacement + Caching&lt;/li&gt;
&lt;li&gt;Paging: conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Processes &amp;amp; threads &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Process&lt;/li&gt;
&lt;li&gt;Context Switching&lt;/li&gt;
&lt;li&gt;Thread&lt;/li&gt;
&lt;li&gt;User level VS kernel level thread&lt;/li&gt;
&lt;li&gt;MultiThreading&lt;/li&gt;
&lt;li&gt;MultiThreading models&lt;/li&gt;
&lt;li&gt;Process VS Threads&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Caching &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[cache-memory]&lt;/li&gt;
&lt;li&gt;caching&lt;/li&gt;
&lt;li&gt;LRU&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Concurrency &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deadlock&lt;/li&gt;
&lt;li&gt;
Semaphore 
### &lt;a&gt;Memory Basics&lt;/a&gt;
&lt;a href="https://www.geeksforgeeks.org/introduction-to-memory-and-memory-units/"&gt;https://www.geeksforgeeks.org/introduction-to-memory-and-memory-units/&lt;/a&gt;
Memories made up of registers. Each register in memory is 1 storage / memory location. Memory location identified using &lt;strong&gt;Address&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;word = group of bits where memory unit store binary information&lt;br&gt;
byte = word with group of 8 bits. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Operating System&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;An operating system is a program that controls the execution of application programs and acts as an interface between the user of a computer and the computer hardware.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Memory Hierarchy Design&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;small&gt; this section is taken from &lt;a href="https://www.geeksforgeeks.org/memory-hierarchy-design-and-its-characteristics/"&gt;geeksforgeeks&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Memory Hierarchy is an enhancement to organize memory so that it can minimize access time&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tKmRkeor--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/etkwwh2oq1i3gdhqq0bn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tKmRkeor--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/etkwwh2oq1i3gdhqq0bn.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are 2 main types of memory&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;External / Secondary memory&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;magnetic / optical disk. magnetic tape. accessible by processor via I/O module&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;Internal / Primary Memory&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;main / cache memory &amp;amp; CPU register. directyl accessible by processor. &lt;/li&gt;
&lt;/ul&gt;


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

&lt;h3&gt;
  
  
  &lt;a&gt;RAM Memory&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;RAM is part of computer's main memory, directly accessible by CPU.&lt;br&gt;
RAM is &lt;strong&gt;volatile&lt;/strong&gt;, so it power is off, stored information is lost. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;RAM used to store data that is currently processed by CPU. &lt;br&gt;
2 forms&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Static RAM (SRAM)

&lt;ul&gt;
&lt;li&gt;used to build cache memory&lt;/li&gt;
&lt;li&gt;memories that consist of circuits capable of retaining state as long as power is long &lt;/li&gt;
&lt;li&gt;fast&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Dynamic RAM (DRAM) 

&lt;ul&gt;
&lt;li&gt;used for main memory (were currently opened programs / processes reside) vairable &amp;amp; state data / OS all are in DRAM&lt;/li&gt;
&lt;li&gt;stored information tends to loose over period of time. capacitor must be periodically recharged to retain usage. &lt;/li&gt;
&lt;li&gt;less expensive than SRAM &lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;Further reading&lt;br&gt;
&lt;a href="https://www.quora.com/What-is-the-difference-between-DRAM-cache-memory"&gt;https://www.quora.com/What-is-the-difference-between-DRAM-cache-memory&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;OS: Logical VS Physical Address&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;logical address&lt;/strong&gt;: generated by CPU when program is running. It does not exist physically. Used as reference to access physical memory location by CPU&lt;br&gt;
&lt;strong&gt;physical address&lt;/strong&gt;: physical location of required data in memory. User never directly deals with physical address but can access it by logical address.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Logical address is mapped to physical address by MMU (memory management unit)&lt;/p&gt;

&lt;p&gt;&lt;u&gt;WHY&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;isolaiont &amp;amp; protection 

&lt;ul&gt;
&lt;li&gt;Logical / Virutal address are needed to ensure secure memory management. If processes can directly modify physical memory they can potentially disrupt other processes. (see &lt;a href="https://stackoverflow.com/a/44525136"&gt;SO answer&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;ease of use

&lt;ul&gt;
&lt;li&gt;OS give each program the view that it has large contiguous address space to put code and data in, programmers need not worry about memory space / addresses. &lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3XwWdFSJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s7acsdduaobstfll2hfr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3XwWdFSJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s7acsdduaobstfll2hfr.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt; taken from &lt;a href="https://www.geeksforgeeks.org/logical-and-physical-address-in-operating-system/"&gt;geeksforgeeks&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;CPU Virtualization&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Each process access its own private virtual address space which the OS maps to the physical memory of the machine.&lt;br&gt;
As far as the running program is concerned it has physical memory all to itself. however, in reality the physical memory is shared amongst all processes and managed by the OS. &lt;/p&gt;

&lt;p&gt;User often runs &amp;gt;1 program at once. User is never concerned with whether CPU is available, only with running programs. --&amp;gt; illusion of many CPUs.&lt;/p&gt;

&lt;p&gt;OS creates illusion by virtualizing CPU. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Time sharing

&lt;ul&gt;
&lt;li&gt;run 1 process, stop it &amp;amp; run another (implemented via context-switching)&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;OS also has policies&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scheduling policy

&lt;ul&gt;
&lt;li&gt;given number of possible programs to run on CPU, policy decides which program OS should run. &lt;/li&gt;
&lt;/ul&gt;


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

&lt;h3&gt;
  
  
  &lt;a&gt;Time Sharing&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;In &lt;strong&gt;multiprogramming&lt;/strong&gt; multiple processes are ready to run at given time, OS will switch between them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Time-sharing&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;run 1 process for a short while

&lt;ul&gt;
&lt;li&gt;give it full access to all memory then stop it, save all state to some kind of disk load other process's state, run it fr a while&lt;/li&gt;
&lt;li&gt;very slo&lt;/li&gt;
&lt;li&gt;saving entire contents to disk is very slow&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;leave process in memory while switching between them

&lt;ul&gt;
&lt;li&gt;OS can implement time sharing efficiently &lt;/li&gt;
&lt;li&gt;with multiple programs residing in memory concurrently, &lt;strong&gt;protection&lt;/strong&gt; is important, process should not be able to read or write other process's memory.&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xK0kXXRk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/amhshz3gx0whhjvcp303.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xK0kXXRk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/amhshz3gx0whhjvcp303.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Address Space &lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;address space&lt;/strong&gt; is OS abstraction of physical memory that is &lt;strong&gt;easy to use&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Address space of process contains all memory state of running program&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BVHiux7W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/815b9uxltwq9v7i2mzmc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BVHiux7W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/815b9uxltwq9v7i2mzmc.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;code

&lt;ul&gt;
&lt;li&gt;instructions for program will be in memory&lt;/li&gt;
&lt;/ul&gt;


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

&lt;ul&gt;
&lt;li&gt;keep track of where program is in the function &lt;/li&gt;
&lt;li&gt;allocate local variables&lt;/li&gt;
&lt;li&gt;pass parameters&lt;/li&gt;
&lt;/ul&gt;


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

&lt;ul&gt;
&lt;li&gt;dynamically-allocated / user-managed memory&lt;/li&gt;
&lt;li&gt;eg. creating new object in Java&lt;/li&gt;
&lt;/ul&gt;


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

&lt;h3&gt;
  
  
  &lt;a&gt;Stack VS heap memory&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;u&gt;Stack&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;stores temporary values created by function&lt;/li&gt;
&lt;li&gt;when task completed memory is automatically erased&lt;/li&gt;
&lt;li&gt;contains methods/ local variables reference variables
&lt;u&gt; Heap &lt;/u&gt;
&lt;/li&gt;
&lt;li&gt;store global variables / static variables &lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Heap has nothing to do with data structure&lt;/p&gt;

&lt;p&gt;Stack&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;only access from top (push and pop top one)&lt;/li&gt;
&lt;li&gt;quick access speed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Heap&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;can take data out from anywhere --&amp;gt; fragmentation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://icarus.cs.weber.edu/%7Edab/cs1410/textbook/4.Pointers/memory.html"&gt;https://icarus.cs.weber.edu/~dab/cs1410/textbook/4.Pointers/memory.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.guru99.com/stack-vs-heap.html"&gt;https://www.guru99.com/stack-vs-heap.html&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Virtualization&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;virtualizing memory&lt;/strong&gt; is when OS provides layer of &lt;strong&gt;abstraction&lt;/strong&gt; to running program.&lt;br&gt;
The running program thinks it is loaded into memory at particular address and has potentially very large address space but the reality if quite different. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Address Traslation: MMU&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Address tarnslation: converting hardware address to virtual address to program is done by *&lt;em&gt;memory management unit&lt;/em&gt; (MMU)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Technique is &lt;strong&gt;dynamic relocation&lt;/strong&gt; There are two hardware registers. one &lt;strong&gt;base&lt;/strong&gt; &amp;amp; one &lt;strong&gt;bounds / limits&lt;/strong&gt;.&lt;br&gt;
The base-and-bounds register will allow OS to place address space anywhere in physical memory. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P4UC5J5E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fgbzhw9u3dxcnvh21zu8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P4UC5J5E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fgbzhw9u3dxcnvh21zu8.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
 &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Kcv26gsD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dhqpc8vu48alycp5jtwp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Kcv26gsD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dhqpc8vu48alycp5jtwp.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
In virutal memory there is 0-16KB memory. base and bounds register will put it in 32KB-48KB of physical address. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Segmentation: Generalized Base / bounds&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;instead of having 1 base/bounds pair. Have a base/bounds pair per logical &lt;strong&gt;segment&lt;/strong&gt; of address space. (code, stack &amp;amp; heap)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Must keep track of each segment + direction it grows (stack grows backwards)&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HmKUkT3C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h0seblq2m2ex7rwolquf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HmKUkT3C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h0seblq2m2ex7rwolquf.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1jtqImn0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k8r76hfxrtn2fvg0at49.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1jtqImn0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k8r76hfxrtn2fvg0at49.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Fragmentation&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;physcial memory becomes &lt;strong&gt;full of little holes of free space&lt;/strong&gt; making it difficult to allocate new segments or grow existing ones&lt;br&gt;
Problem because of segmentation&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;In simple MMU, each address space is same size so physical memory is just a bunch of slots where processes fit in&lt;/li&gt;
&lt;li&gt;In segmentation, there are many segments / process and each segment is different size&lt;/li&gt;
&lt;li&gt;Physical memory can become full of little holes 
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--leMinMBA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mtzk31wztnac6n3szyta.png" alt="alt text"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Solutions &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Compact physical memory

&lt;ul&gt;
&lt;li&gt;compact physical meory by rearranging exisiting segment&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Management algorithm 

&lt;ul&gt;
&lt;li&gt;algo that tries to keep large extents of memory available for allocation&lt;/li&gt;
&lt;li&gt;eg. best-fit / worst-fit / buddy algorithm&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;&lt;em&gt;external fragmentation will always exists&lt;/em&gt; algos will just minimize it. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Paging&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Virtual memory: address space  is divided into &lt;em&gt;fixed-sized&lt;/em&gt; pieces. &lt;br&gt;
&lt;small&gt; as opposed to diving it into some number of variable-sized logical segments &lt;/small&gt;&lt;br&gt;
Physical Memory: physical memory is now viewed as fixed-sized slots called &lt;strong&gt;page frames&lt;/strong&gt; each frame contains a single virtual-memory page. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This helps prevent fragmentation which occurs when dividing space into different-size chunks (as in segmentation)&lt;/p&gt;

&lt;p&gt;Pages in virtual address space will be places at different locations throughout physical memory&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lMZQb5-d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6rgt4xyijvdsfxqrbg22.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lMZQb5-d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6rgt4xyijvdsfxqrbg22.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z3MOo9mU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xudbz5kyor6q4s53t4rt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z3MOo9mU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xudbz5kyor6q4s53t4rt.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt; Advantages &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;flexibility

&lt;ul&gt;
&lt;li&gt;can effectively support abstraction of address space. no need to make assumption about direction of heap / stack&lt;/li&gt;
&lt;/ul&gt;


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

&lt;ul&gt;
&lt;li&gt;OS needs to place 4 page of address space in eight page of physical memory, It just find 4 free pages.&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;&lt;u&gt;Disadvantages&lt;/u&gt;&lt;br&gt;
can be slow&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;hardware must know where page table for currently running process is&lt;/li&gt;
&lt;li&gt;fetch proper page table entry from process's page table&lt;/li&gt;
&lt;li&gt;perform translation of virtual memory to physical memory&lt;/li&gt;
&lt;li&gt;load data from physical memory&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Page Table&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Used for &lt;strong&gt;address translations&lt;/strong&gt;&lt;br&gt;
It is a &lt;strong&gt;per process&lt;/strong&gt; data stricture that records where each virtual page of address space is places in physical memory&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Its &lt;strong&gt;per-process&lt;/strong&gt;. If another process were to run OS will have to manage different page table for it since virtual pages will map to different physical page (isolation --&amp;gt; no sharing of memory)&lt;/p&gt;

&lt;p&gt;&lt;u&gt; Virtual Address -&amp;gt; Physical Address&lt;/u&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--33cq7NlB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zwsxc2nwv09z45usdjhb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--33cq7NlB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zwsxc2nwv09z45usdjhb.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;address split into 2 parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;VPN: Virtual Page Number&lt;/li&gt;
&lt;li&gt;offset: offset within the page (which byte within the page)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In converting.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;VPN. converted to PFN (physical fram / page number)&lt;/li&gt;
&lt;li&gt;offset: not changed. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Page Table Contents&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;page table is just data structure mapping virtual address to physical address. simplest one can be linear page table (array)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8r3xConM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lb2tm4ji2wwzz5hykn0e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8r3xConM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lb2tm4ji2wwzz5hykn0e.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each page table entry (PTE) can include&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;protection bit

&lt;ul&gt;
&lt;li&gt;page can be read / written / exeucted&lt;/li&gt;
&lt;/ul&gt;


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

&lt;ul&gt;
&lt;li&gt;page is in physical memory or on disk (i.e. it's swapped out)&lt;/li&gt;
&lt;/ul&gt;


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

&lt;ul&gt;
&lt;li&gt;page modified since it was brought into memory&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;reference bit

&lt;ul&gt;
&lt;li&gt;track if page was accessed, determine which pages are popular and should be kept in memory --&amp;gt; useful for page replacement&lt;/li&gt;
&lt;/ul&gt;


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

&lt;h3&gt;
  
  
  &lt;a&gt;TLB&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;translation lookaside buffer&lt;/strong&gt;(TLB) is part of chip's MMU. It is a &lt;strong&gt;address-translation cache&lt;/strong&gt;.&lt;br&gt;
It's a hardware cache for popular virtual-to physical address translations&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;will speed up address translations &amp;amp; paging&lt;/p&gt;

&lt;p&gt;&lt;u&gt; Context Switch &lt;/u&gt;&lt;br&gt;
address translation only valid per process. to handle this,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OS &lt;strong&gt;flush&lt;/strong&gt; TLB on context switch&lt;/li&gt;
&lt;li&gt;hardware support

&lt;ul&gt;
&lt;li&gt;provide address space identifier (something like process identifier (PID)) in TLB&lt;/li&gt;
&lt;/ul&gt;


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

&lt;h3&gt;
  
  
  &lt;a&gt;Virtual Memory: Secondary memory&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/virtual-memory-in-operating-system/"&gt;https://www.geeksforgeeks.org/virtual-memory-in-operating-system/&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Virtual Memory is a storage allocation scheme in which secondary memory can be addressed as though it were part of main memory&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To support many concurrently-tuning large address spaces, we can use secondary memory (hard disk). OS can make use of this larger, slower device to provide the illusion of large virtual address sapce. &lt;/p&gt;

&lt;p&gt;Further Reading:&lt;br&gt;
&lt;a href="https://www.guru99.com/virtual-memory-in-operating-system.html"&gt;https://www.guru99.com/virtual-memory-in-operating-system.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/virtual-memory-in-operating-system/"&gt;https://www.geeksforgeeks.org/virtual-memory-in-operating-system/&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Swap Space&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Swap Space&lt;/strong&gt; is space reserved on the disk for moving pages back and forth &lt;br&gt;
OS will need to remember &lt;strong&gt;disk address&lt;/strong&gt; of given page&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_1jLbhSd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5mw4ehfn9at0jryra7z4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_1jLbhSd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5mw4ehfn9at0jryra7z4.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;proc 0-2 are actively sharing physical memory only some of their valid pages are in memory others are in swap space on disk.&lt;br&gt;
Proc 4 has all ages swapped out to disk and isn't currently running. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Page Fault&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;process accesses a memory page that is mapped to virtual address space but not loaded in physical memory.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Remember that in Page table Entry (PTE) there is a present bit, which represents if page table is present in physical memory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OS handles page fault (page-fault handler)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If page is not present and has been swapped to disk, OS will need to swap page into memory to service the page fault.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Page Replacement&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/page-replacement-algorithms-in-operating-systems/"&gt;https://www.geeksforgeeks.org/page-replacement-algorithms-in-operating-systems/&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Page Replacement Policy&lt;/strong&gt; When physical memory is full, OS must pick a page to kick out/ replace to make room to page in a page from swap space&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;FIFO&lt;/li&gt;
&lt;li&gt;Optimal Page Replacement

&lt;ul&gt;
&lt;li&gt;kick out page that would not be used for the longest duration of time in the future. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;LRU (least recently used) 

&lt;ul&gt;
&lt;li&gt;kick out page that has been least recently used&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Paging: Putting it all together&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;what happens when program fetches some data from memory?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Find VPN from virtual address&lt;/li&gt;
&lt;li&gt;Check TLB (cache) to translate VPN to PPN

&lt;ul&gt;
&lt;li&gt;TLB Hit (cache hit)&lt;/li&gt;
&lt;li&gt;physical address = PPN + offset&lt;/li&gt;
&lt;li&gt;TLB miss&lt;/li&gt;
&lt;li&gt;check page table entry(PTE) in page table &lt;/li&gt;
&lt;li&gt;PTE.present

&lt;ul&gt;
&lt;li&gt;grab PPN from PTE and retry&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;PTE is absent (page fault)

&lt;ul&gt;
&lt;li&gt;OS page fault handler&lt;/li&gt;
&lt;li&gt;find physical frame for page to be in&lt;/li&gt;
&lt;li&gt;No page&lt;/li&gt;
&lt;li&gt;Wait for replacement algorithm to kick out page&lt;/li&gt;
&lt;li&gt;Read page in from swap space&lt;/li&gt;
&lt;/ul&gt;


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

&lt;h3&gt;
  
  
  &lt;a&gt;Process&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Process is a program in execution.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When write program in java &amp;amp; compile. Compiler creates binary code. Original code &amp;amp; binary code -&amp;gt; program. When u run the binary code -&amp;gt; process. &lt;/p&gt;

&lt;p&gt;Process is 'active' program is 'passive'&lt;/p&gt;

&lt;p&gt;&lt;u&gt; In Memory &lt;/u&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bqYw2-D_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ig55l025aughy0ru5zft.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bqYw2-D_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ig55l025aughy0ru5zft.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt; States &lt;/u&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3RfeW1j3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nqdfwczulf79nooxs7ne.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3RfeW1j3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nqdfwczulf79nooxs7ne.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Context Switching&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;process of saving context of 1 process &amp;amp; loading context of another process&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;loading &amp;amp; unloading process form running state to the ready state&lt;/p&gt;

&lt;p&gt;occurs when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;process with higher priority then running process comes to ready state&lt;/li&gt;
&lt;li&gt;interrupt occurs&lt;/li&gt;
&lt;li&gt;CPU scheduling &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Thread&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;unit of execution within a process.&lt;br&gt;
Threads are executed &lt;strong&gt;one after another&lt;/strong&gt; but &lt;strong&gt;gives the illusion&lt;/strong&gt; as if they are executing in parallel. &lt;br&gt;
Threads are &lt;strong&gt;not independent&lt;/strong&gt; of each other. they share code data OS resources.&lt;br&gt;
&lt;strong&gt;Lightweight&lt;/strong&gt;: have own stack space but can access shared data&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Each thread has:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a program counter&lt;/li&gt;
&lt;li&gt;a register set&lt;/li&gt;
&lt;li&gt;a stack space &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Two types of thread:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User level thread&lt;/li&gt;
&lt;li&gt;Kernel level thread
&lt;a href="https://www.geeksforgeeks.org/threads-and-its-types-in-operating-system/"&gt;https://www.geeksforgeeks.org/threads-and-its-types-in-operating-system/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;Multithreading&lt;/u&gt;&lt;br&gt;
thread is known as a lightweight process.&lt;br&gt;
Achieve parallelism by dividing a process into multiple threads. &lt;/p&gt;

&lt;p&gt;2 types of threads&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User level thread&lt;/li&gt;
&lt;li&gt;kernal level thread&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;User VS Kernel level thread&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;user level&lt;/strong&gt; - user managed threads&lt;br&gt;
&lt;strong&gt;kernel level&lt;/strong&gt; - OS managed threads acting on kernel on OS core.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://www.tutorialspoint.com/operating_system/os_multi_threading.htm"&gt;https://www.tutorialspoint.com/operating_system/os_multi_threading.htm&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;MultiThreading&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;concurrency&lt;/strong&gt;&lt;br&gt;
&lt;u&gt;Multithreaded process on single processor&lt;/u&gt;&lt;br&gt;
processor switches execution resources between threads resulting in cocurrent execution&lt;br&gt;
concurrency means more than 1 thread is making progress but threads are not actually running simultaneously. switching happens quick enough that threads might appear to run simultaneously. &lt;/p&gt;

&lt;p&gt;&lt;u&gt;Multithreaded process in shared-memory multiprocessor environment&lt;/u&gt;&lt;br&gt;
Each thread in process can run concurrently on separate processor resulting in parallel execution. (when number of threads in process &amp;lt;= number of processors available)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;concurrency&lt;/strong&gt;: interleaving threads in time to give appearance of simultaneous execution&lt;br&gt;
&lt;strong&gt;parallelism&lt;/strong&gt;: genuine simultaneous execution&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://docs.oracle.com/cd/E19253-01/816-5137/mtintro-25092/index.html"&gt;https://docs.oracle.com/cd/E19253-01/816-5137/mtintro-25092/index.html&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;MultiThreading models&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;system to support kernal and user thread in combined way&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;many to many model

&lt;ul&gt;
&lt;li&gt;multiple user threads -&amp;gt; same / lesser kernel threads&lt;/li&gt;
&lt;li&gt;user thread blocked can schedule other user thread to other kernel thread&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;many to one model&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;multiple user thread -&amp;gt; one kernel thread&lt;/li&gt;
&lt;li&gt;user makes blocking system call, entire process blocks&lt;/li&gt;
&lt;li&gt;one kernel thread &amp;amp; only 1 use can access kernel at a time -&amp;gt; multiple threads cannot access multiprocessor at same time&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;one to one model&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1-1 relationship for user and kernel thread&lt;/li&gt;
&lt;li&gt;multiple thread &lt;strong&gt;can run on multiple processor&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;creating user thread requires corresponding kernel thread.&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rHKwxgwf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/09wi9yjcdsju874yszan.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rHKwxgwf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/09wi9yjcdsju874yszan.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Process VS Threads&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Threads within same process run in shared memory space.&lt;br&gt;
Process run in separate memory space&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Threads are not independent of one another like processes, threads share with other threads OS resources&lt;br&gt;
Like process, threads have their own program counter (PC), register set &amp;amp; stack space. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VsjyLXyV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ssq80tmkp4ucjih3gyp1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VsjyLXyV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ssq80tmkp4ucjih3gyp1.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
 &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uZyzx1QW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2i2lco1x33fzg0i30jgz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uZyzx1QW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2i2lco1x33fzg0i30jgz.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;&lt;a href="https://www.geeksforgeeks.org/thread-in-operating-system/"&gt;reference&lt;/a&gt; &lt;/small&gt;&lt;br&gt;
&lt;a href="https://www.backblaze.com/blog/whats-the-diff-programs-processes-and-threads/"&gt;blackblaze&lt;/a&gt; has a really comprehensive read and is where the pictures in this section are from &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Computer Networks</title>
      <dc:creator>limjy</dc:creator>
      <pubDate>Wed, 05 May 2021 15:52:53 +0000</pubDate>
      <link>https://dev.to/jing/computer-networks-4jpe</link>
      <guid>https://dev.to/jing/computer-networks-4jpe</guid>
      <description>&lt;p&gt;Should be a short summary / quick cramming guide for Computer networks since i forgot everything from my networks course&lt;/p&gt;

&lt;p&gt;only doing PART of application &amp;amp; network layer from TCP/IP model.&lt;/p&gt;

&lt;p&gt;references:&lt;br&gt;
&lt;a href="https://www.homenethowto.com/" rel="noopener noreferrer"&gt;https://www.homenethowto.com/&lt;/a&gt; &lt;br&gt;
^ This provides a really good, &lt;em&gt;simple&lt;/em&gt; concise introduction.&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/computer-network-tutorials/#basics" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/computer-network-tutorials/#basics&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/commonly-asked-computer-networks-interview-questions-set-1/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/commonly-asked-computer-networks-interview-questions-set-1/&lt;/a&gt;&lt;br&gt;
&lt;a href="http://www2.ic.uff.br/%7Emichael/kr1999/0_0-Contents.htm" rel="noopener noreferrer"&gt;http://www2.ic.uff.br/~michael/kr1999/0_0-Contents.htm&lt;/a&gt;&lt;br&gt;
Book: Computer Networking A Top-down Approach&lt;/p&gt;

&lt;p&gt;Network: two or more devices connected through a link&lt;br&gt;
link: communication pathway that transfer data from one device to another&lt;/p&gt;

&lt;h2&gt;
  
  
  TOC
&lt;/h2&gt;

&lt;p&gt;&lt;u&gt;Basics&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basics&lt;/li&gt;
&lt;li&gt;protocol&lt;/li&gt;
&lt;li&gt;Network Topology&lt;/li&gt;
&lt;li&gt;Types of area networks&lt;/li&gt;
&lt;li&gt;Line Configuration&lt;/li&gt;
&lt;li&gt;Transmission Modes&lt;/li&gt;
&lt;li&gt;Delay, loss, throughput&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Application Layer &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Relation between application layer &amp;amp; transport layer
network application consists of pairs of processes that send messages to each
other over a network.&lt;/li&gt;
&lt;li&gt;Socket&lt;/li&gt;
&lt;li&gt;HTTP&lt;/li&gt;
&lt;li&gt;HTTP Persistent VS non-persistent connection &amp;amp; pipelining&lt;/li&gt;
&lt;li&gt;Cookies to keep state&lt;/li&gt;
&lt;li&gt;HTTP VS HTTPS&lt;/li&gt;
&lt;li&gt;HTTPS&lt;/li&gt;
&lt;li&gt;DNS&lt;/li&gt;
&lt;li&gt;How DNS works&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Transport Layer &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Overview: TCP &amp;amp; UDP&lt;/li&gt;
&lt;li&gt;Relation between transport &amp;amp; network layer&lt;/li&gt;
&lt;li&gt;Multiplexing &amp;amp; demultiplexing&lt;/li&gt;
&lt;li&gt;UDP: Connectionless Transport&lt;/li&gt;
&lt;li&gt;UDP: Checksum&lt;/li&gt;
&lt;li&gt;TCP: Connection Oriented Transport&lt;/li&gt;
&lt;li&gt;TCP Connection: 3-way handshake&lt;/li&gt;
&lt;li&gt;Principles for Reliable Data Transfer&lt;/li&gt;
&lt;li&gt;TCP: Reliable Data Transfer&lt;/li&gt;
&lt;li&gt;TCP: Connection Termination&lt;/li&gt;
&lt;li&gt;TCP VS UDP&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Internet Layer &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IP&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Network Layer &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ethernet???&lt;/li&gt;
&lt;li&gt;idk other stuff????&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Security stuff &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to store passwords&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Putting it to practice / in summary / interview questions &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What happens when u put URL in browser&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Basics&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;TCP/IP Model&lt;/u&gt;&lt;br&gt;
There are two models TCP / IP model (4 layers) and OSI model (7 layers). I'm lazy so I'll just go through the TCP/IP model.&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%2Fuploads%2Farticles%2Fyxb4kks68peirmpxvrby.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%2Fyxb4kks68peirmpxvrby.png" alt="alt text"&gt;&lt;/a&gt;&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%2Fuploads%2Farticles%2Fkblmv2ybr2et2h2gfzad.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%2Fkblmv2ybr2et2h2gfzad.png" alt="alt text"&gt;&lt;/a&gt;&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%2Fuploads%2Farticles%2Fwj2asd4w874avqngm31d.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%2Fwj2asd4w874avqngm31d.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt; &lt;a href="https://www.tutorialspoint.com/OSI-vs-TCP-IP-Reference-Model" rel="noopener noreferrer"&gt;reference&lt;/a&gt;&lt;/small&gt;&lt;br&gt;
&lt;small&gt;&lt;a href="https://www.guru99.com/tcp-ip-model.html" rel="noopener noreferrer"&gt;reference&lt;/a&gt;&lt;/small&gt;&lt;br&gt;
&lt;small&gt;&lt;a href="https://fiberbit.com.tw/tcpip-model-vs-osi-model/" rel="noopener noreferrer"&gt;reference&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;:&lt;br&gt;
separation of responsibility / decoupled.&lt;br&gt;
each layer handles different responsibility, top layer does not need tp worry about bottom layer stuff. &lt;/p&gt;

&lt;p&gt;&lt;u&gt;Host name&lt;/u&gt;&lt;br&gt;
each device in network is associate with a unique device name called hostname&lt;br&gt;
&lt;u&gt;IP Address &lt;/u&gt;&lt;br&gt;
Internet Protocol address. &lt;br&gt;
network address of the device across the network. to identify each device in www assigns IPV4 address as unique identifier to each device on internet&lt;br&gt;
IPV4 - 32 bits&lt;br&gt;
IPv6 - 128 bits&lt;br&gt;
&lt;u&gt;MAC Address &lt;/u&gt;&lt;br&gt;
Media Access Control address / physical address assigned to Network Interface Controller / Card. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MAC address assigned by manufacturer of hardware interface IP address assigned by network administrator / ISP&lt;/li&gt;
&lt;li&gt;MAC address defines device identity, IP describes how devices are connecte to internet&lt;/li&gt;
&lt;li&gt;MAC: broadcasting. IP: broadcasting / multicasting&lt;/li&gt;
&lt;li&gt;MAC: implement in data-link layer. IP: implemented in Netwrok layer
&lt;small&gt; &lt;a href="https://www.guru99.com/difference-between-mac-address-and-ip-address.html" rel="noopener noreferrer"&gt;reference&lt;/a&gt; &lt;/small&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;Port&lt;/u&gt;&lt;br&gt;
logical channel through which data can be sent/received to an application&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Protocol&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;format and the order of messages exchanged between entities, &amp;amp; actions taken on the transmission&lt;br&gt;
and/or receipt of a message or other event.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;set of rules defining how entities communicate&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Network Topology&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Network Topology is the arrangement with which computer systems or network devices are connected to each other.&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%2Fuploads%2Farticles%2Fui7yu0q8plq6r56gyysx.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%2Fui7yu0q8plq6r56gyysx.png" alt="alt text"&gt;&lt;/a&gt; &lt;br&gt;
&lt;small&gt;See &lt;a href="https://beginnersbook.com/2019/03/computer-network-topology-mesh-star-bus-ring-and-hybrid/" rel="noopener noreferrer"&gt;reference&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Types of Networks&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;LAN -- local area network. covers smallest area&lt;/li&gt;
&lt;li&gt;MAN -- Metropolitan are network. cover larger area than LAN smaller area then WAN&lt;/li&gt;
&lt;li&gt;WAN -- Wide Area network. covers largest area. any network whose communications link cross metropolitan, regional or national boundaries. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;media for data tranmission&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;LAN: Wifi/ Ehternet cables&lt;/li&gt;
&lt;li&gt;MAN: modem &amp;amp; wire / cable&lt;/li&gt;
&lt;li&gt;WAN: leased telephone lines / satellite links&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Examples&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;LAN: usually group of computer / network devices connecte together usually within same building&lt;/li&gt;
&lt;li&gt;MAN: spans several buildings&lt;/li&gt;
&lt;li&gt;WAN: internet&lt;/li&gt;
&lt;/ol&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%2Fvdqguwror0xteunb0c85.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%2Fvdqguwror0xteunb0c85.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;See &lt;a href="https://community.fs.com/blog/lan-vs-man-vs-wan-whats-the-difference.html" rel="noopener noreferrer"&gt;reference&lt;/a&gt; &amp;amp; &lt;a href="https://www.router-switch.com/faq/wide-area-network-examples-of-wan.html" rel="noopener noreferrer"&gt;examples&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Line Configuration&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;For communication to occur, two deivces must be connected in some way to same link at same time. There are two possible types of connections:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;point-to-point connection&lt;/li&gt;
&lt;li&gt;multipoint connection&lt;/li&gt;
&lt;/ol&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%2F7aj4f26vm0daycsgyh13.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%2F7aj4f26vm0daycsgyh13.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;small&gt;&lt;a href="https://www.slideshare.net/dee_rosal/computer-networks-112702195" rel="noopener noreferrer"&gt;source&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;b&gt; point-to-point connection &lt;/b&gt;&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;dedicated link between two devices&lt;/li&gt;
&lt;li&gt;entire capacity is reserved for transmission between 2 devices&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;&lt;b&gt; multipoint / multidrop connection &lt;/b&gt;&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;also called "Broadcast network"&lt;/li&gt;
&lt;li&gt;packet transmitted by sender is received and processed by every device on link. But by address field in packet receiver determines whether the packet belongs to it or not. &lt;/li&gt;
&lt;li&gt;2 or more devices share single link&lt;/li&gt;
&lt;li&gt;capacity is shared spatially or temporal&lt;/li&gt;
&lt;li&gt;spatial sharing - devices share link simultaneously&lt;/li&gt;
&lt;li&gt;temporal sharing - users take turns using the link&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Transmission Modes&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;transferring of data between two devices also known as communication mode&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;Simplex&lt;/li&gt;
&lt;li&gt;half-duplex&lt;/li&gt;
&lt;li&gt;full duplex&lt;/li&gt;
&lt;/ol&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%2Fmyc7dmekg662lagbs9b4.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%2Fmyc7dmekg662lagbs9b4.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;u&gt;Simplex&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;communication is unidirectional&lt;/li&gt;
&lt;li&gt;only one of two devices on link can transmit, other can receive&lt;/li&gt;
&lt;li&gt;uses entire capacity of channel to send data in 1 direction&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;eg. keybord &amp;amp; monitor. keyboard only introduce input, monitor only give output&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;u&gt;Half-Duplex&lt;/u&gt;&lt;/b&gt;&lt;br&gt;
each station can transmit and receive but not at same time. When 1 send, other canon only receive. &lt;br&gt;
Entire capacity of channel utilized for each direction&lt;br&gt;
eg. walkie talkie. must say "over" so other person can speak&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;u&gt;Full Duplex&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;both can transmit and receive &lt;em&gt;simultaneously&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;signals going in 1 direction share capacity of signals going in other direction&lt;/li&gt;
&lt;li&gt;link contains 2 physically separate transmission paths (one for sending other receiving)&lt;/li&gt;
&lt;li&gt;capacity divided between signals&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;e.g. landline. both can talk and hear and talk over each other lmao.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Delay, Loss &amp;amp; Throughput&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;This &lt;a href="https://cs460.byu.edu/static/lectures/winter-2014/delay-loss-and-throughput.pdf" rel="noopener noreferrer"&gt;slides&lt;/a&gt; provides a really great concise overview.&lt;/p&gt;

&lt;h6&gt;
  
  
  Delay
&lt;/h6&gt;

&lt;blockquote&gt;
&lt;p&gt;how long will it take for packet to travel from point A to point B&lt;/p&gt;
&lt;/blockquote&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%2F4y849d5x1nqts3n22akk.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%2F4y849d5x1nqts3n22akk.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;b&gt;Processing Delay&lt;/b&gt; - time to examine packet's header and determine where to direct packet&lt;/li&gt;
&lt;li&gt;
&lt;b&gt;Queuing delay&lt;/b&gt; - packet waits to be transmitted onto link&lt;/li&gt;
&lt;li&gt;
&lt;b&gt;transmission delay&lt;/b&gt; - amount of time required to push / transmit all of packet's bits into link
eg. if Ethernet link rate is R=10Mbps &amp;amp; length of packet is L bits. &lt;em&gt;transmission delay is L(lenght of packet)/R (rate)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;b&gt;propagation delay&lt;/b&gt; - time required to propagate from beginning to link to router B.
&lt;em&gt;depends on physical medium of link&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;transmission VS propagation delay&lt;/u&gt;&lt;br&gt;
transmission: amount of time required for router to push out packet. (function of packet's length &amp;amp; transmission rate of link, nothing to do with distance between routers)&lt;br&gt;
propagation: time taken to propagate from one router to next&lt;br&gt;
(function of distance between routers, nothing to do with packet's length / transmission rate of link)&lt;/p&gt;

&lt;h6&gt;
  
  
  Packet Loss
&lt;/h6&gt;

&lt;p&gt;If packet arrives to a full queue, the router will drop it since there is no place to store packet&lt;/p&gt;

&lt;h6&gt;
  
  
  Throughput
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;b&gt;Instantaneous Throughput&lt;/b&gt; - rate (in bits/sec) at which Host B is receiving file / packet&lt;/li&gt;
&lt;li&gt;
&lt;b&gt; average throughput&lt;/b&gt; amount of bits recevied (F) / time taken for Host B to receive all bits (T) = F/T&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; bottleneck link &lt;/u&gt;&lt;br&gt;
for two link network, throughput is limited by the minimum throughput of both links. Otherwise known as bottleneck link&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%2Fuploads%2Farticles%2Fldebg2oqv2vj25t0jl27.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%2Fldebg2oqv2vj25t0jl27.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
throughut is min{Rs,Rc}. min is the bottleneck link&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Socket&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flw8gsv91arbrsngwvgyq.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%2Flw8gsv91arbrsngwvgyq.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
Interface between application layer and transport layer&lt;br&gt;
eg. When process wants to send a message to another process on another host, it&lt;br&gt;
shoves the message out its door (socket). Other process received message through door (socket) and acts on it. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;HTTP&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;HyperText Transfer Protocol. is a &lt;strong&gt;stateless&lt;/strong&gt; protocol&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;b&gt; client program &lt;/b&gt; - browser, browser implement client side of Web&lt;/li&gt;
&lt;li&gt;
&lt;b&gt; server program &lt;/b&gt; - Web server implement server side of HTTP, house Web objects each addressable by URL. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;client and server program executed on different end systems talk to each other by exchanging HTTP messages. &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%2Fuploads%2Farticles%2Fmakqolsctc7kp5rdidlp.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%2Fmakqolsctc7kp5rdidlp.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;HTTP uses TCP as underlying transport protocol&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;client initiate TCP connect with server&lt;/li&gt;
&lt;li&gt;Browser &amp;amp; server processes access TCP via socket interface &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;TCP provides reliable data transfer service to HTTP, so each HTTP request response message sent by server eventually arrives intact at client. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;layered architecture&lt;/strong&gt;&lt;br&gt;
HTTP need not worry about lost data or the details of how TCP recovers from loss or reordering of data within the network. That is the job of TCP and the protocols in the lower layers of the protocol stack&lt;/p&gt;

&lt;p&gt;&lt;u&gt; stateless &lt;/u&gt;&lt;br&gt;
HTTP server maintains no information about client. if client asks for same object, server will server it will not response saying it just served object to client. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Persistent (long) VS non-persistent (short) connection&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;HTTP client &amp;amp; server will communicate for extended amount of time. must decide send each request/response over &lt;strong&gt;separate (non-persistent)&lt;/strong&gt; OR &lt;strong&gt;same (persistent)&lt;/strong&gt; TCP connection&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt; pipelining &lt;/u&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;requests for objects can be made back-to-back without waiting for replies to pending requests&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;default HTTP mode uses HTTP with pipelining &amp;amp; connection closes when not used for certain time&lt;/p&gt;

&lt;p&gt;&lt;u&gt; persistent VS non-persistent &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;brand new connection established and maintained for each requested object. TCP buffers allocated TCP variable allocated in both server &amp;amp; client --&amp;gt; burden&lt;/li&gt;
&lt;li&gt;each object suffer delivery delay of 2 RTT - 1 RTT to establish TCP connected 1 RTT to request &amp;amp; receive object. &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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F72l2qurb5p3el9rhma10.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%2F72l2qurb5p3el9rhma10.png" alt="alt text"&gt;&lt;/a&gt; &lt;br&gt;
&lt;small&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Connection_management_in_HTTP_1.x?retiredLocale=ar" rel="noopener noreferrer"&gt;reference&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Cookies&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Website needs to identify users &amp;amp; serve content as function of user identity.&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%2F5lu33fak4kcoi8vlthnn.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%2F5lu33fak4kcoi8vlthnn.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;HTTP VS HTTPS&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuhx4hp31uy0lyrz02dj6.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%2Fuhx4hp31uy0lyrz02dj6.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTTPS (or rather SSL) is a transport layer protocol, HTTP is a application layer protocol&lt;/li&gt;
&lt;li&gt;HTTP transfer data in plain text HTTPS transfer data encrypted. hacker can read sensitive data or modify data, entities communicating will be none the wiser&lt;/li&gt;
&lt;li&gt;HTTPS is slower since it consumes computation power to encrypt communication channel&lt;/li&gt;
&lt;li&gt;independent authority (certificate authority, CA) verifies identity of certificate owner. over HTTPS, one cannot impersonate. &lt;/li&gt;
&lt;li&gt;HTTPS &lt;strong&gt;can't stop stealing confidential information from pages cached in browser&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;small&gt;&lt;a href="https://www.guru99.com/difference-http-vs-https.html" rel="noopener noreferrer"&gt;reference&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;HTTPS&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Details in this section taken from &lt;a href="https://www.cloudflare.com/learning/ssl/what-happens-in-a-tls-handshake/" rel="noopener noreferrer"&gt;cloudflare&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;TLS is an encryption protocol designed to secure Internet communication. During TLS both parties exchange messages to acknolwedge eahc other, verify each toehr &amp;amp; establish encryption algos &amp;amp; agree on session keys&lt;br&gt;
TLS handshakes are a foundational part of how HTTPS work.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt; Process &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Client Hello

&lt;ul&gt;
&lt;li&gt;client initiates by senidng "hello" along with:&lt;/li&gt;
&lt;li&gt;TLS version client supports&lt;/li&gt;
&lt;li&gt;ciper suite supported &amp;amp;&lt;/li&gt;
&lt;li&gt;client random (string of random bytes)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Server Hello

&lt;ul&gt;
&lt;li&gt;Server's SSL cert&lt;/li&gt;
&lt;li&gt;Server's chosen cipher suite&lt;/li&gt;
&lt;li&gt;server random&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Authenticaion

&lt;ul&gt;
&lt;li&gt;client verfies server SSL cert with cert authority (CA)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;premaster secret

&lt;ul&gt;
&lt;li&gt;client sends &lt;em&gt;premaster key&lt;/em&gt; (random string of bytes)&lt;/li&gt;
&lt;li&gt;premaster key is encrypted with server public key (can only be seen by server)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Session keys created

&lt;ul&gt;
&lt;li&gt;BOTH client &amp;amp; server generate session keys from&lt;/li&gt;
&lt;li&gt;client random&lt;/li&gt;
&lt;li&gt;server random&lt;/li&gt;
&lt;li&gt;premaster key&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Client ready

&lt;ul&gt;
&lt;li&gt;client sends "finished" encrypted with session key&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Server ready

&lt;ul&gt;
&lt;li&gt;server send "finished" encrypted with session key&lt;/li&gt;
&lt;/ul&gt;


&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F806jmiwcducnbzyv2c95.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%2F806jmiwcducnbzyv2c95.png" alt="alt text"&gt;&lt;/a&gt;&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%2Fuploads%2Farticles%2Fg761ua8prtv55zzxfxgc.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%2Fg761ua8prtv55zzxfxgc.png" alt="alt text"&gt;&lt;/a&gt;&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%2Fuploads%2Farticles%2Fejentpinfvgvz7l9lztw.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%2Fejentpinfvgvz7l9lztw.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;General phases&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Negotiation

&lt;ul&gt;
&lt;li&gt;server &amp;amp; client agree on cipher suite &lt;/li&gt;
&lt;li&gt;server sends SSL cert&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Authentication

&lt;ul&gt;
&lt;li&gt;client check that server cert is authentic / can be trusted&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Key Exchange

&lt;ul&gt;
&lt;li&gt;server &amp;amp; client create session key (symmetric keys)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Trusting certificates &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CA

&lt;ul&gt;
&lt;li&gt;certificate is issued by a Certificate Authority that browser trusts (usually pre-installed on browser, can add &amp;amp; remove)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Digital Signature

&lt;ul&gt;
&lt;li&gt;verify that person presenting cert is also person controlling the domain&lt;/li&gt;
&lt;li&gt;certificate is "signed" by another authority to declare person controlling cert controls domain&lt;/li&gt;
&lt;li&gt;Authority uses "private key" (basically a unique key only authority can produce, much like a signature) to encrypt contents of cert. cipher text is attached to cert as digital signature&lt;/li&gt;
&lt;li&gt;anyone can use public key to decrypt and match contents. only authority can produce the signature. &lt;/li&gt;
&lt;li&gt;browser can use CA public key to check if signature is valid. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;man in middle can technically replay info from client to server. but information is encrypted and attacker will not have server's private key to decrypt and read information. &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%2Fpmli43mw98b8d6ec2zp4.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%2Fpmli43mw98b8d6ec2zp4.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Further reading:&lt;br&gt;
&lt;a href="https://robertheaton.com/2014/03/27/how-does-https-actually-work/" rel="noopener noreferrer"&gt;https://robertheaton.com/2014/03/27/how-does-https-actually-work/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://medium.com/@vanrijn/an-overview-of-the-ssl-handshake-3885c37c3e0f" rel="noopener noreferrer"&gt;https://medium.com/@vanrijn/an-overview-of-the-ssl-handshake-3885c37c3e0f&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.thesslstore.com/blog/explaining-ssl-handshake/" rel="noopener noreferrer"&gt;https://www.thesslstore.com/blog/explaining-ssl-handshake/&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Transmission Media&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;physical path between transmitter and receiver (i.e. channel through which data is sent from one palce to another) &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;DNS&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Domain Name system. translates hostname (human friendly names) to IP addresses.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;distributed database&lt;/strong&gt; implemented in hierarchy of &lt;strong&gt;DNS servers&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;application-layer protocol that allows hosts to query distributed database. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;when browser extracts hostname, DNS client sends query for hostname to DNS server. DNS server will reply with IP address.&lt;/p&gt;

&lt;p&gt;DNS adds delay but delay is circumvented as &lt;strong&gt;IP address usually cached in "nearby" DNS server&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;How DNS works&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;DNS reply &amp;amp; query sent in UDP datagrams to port 53. DNS is a distributed hierarchical Database&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt; Overview &lt;/u&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;browser invoke client side of DNS with hostname to be translated&lt;/li&gt;
&lt;li&gt;DNS sends query message to network. &lt;em&gt;All DNS reply &amp;amp; query are sent within UDP datagrams to port 53&lt;/em&gt; &lt;/li&gt;
&lt;li&gt;DNS in user host receive DNS reply message with desired mapping&lt;/li&gt;
&lt;li&gt;mapping passed to invoking application (browser) &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;u&gt; distributed hierarchical Database &lt;/u&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;DNS uses a large number of servers,&lt;br&gt;
organized in a hierarchical fashion and distributed around the world. mappings&lt;br&gt;
are distributed across the DNS servers&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;root DNS server (at top) &lt;/li&gt;
&lt;li&gt;top level domain (TLD) DNS server&lt;/li&gt;
&lt;li&gt;&lt;p&gt;authoritative DNS server (at bottom) &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%2Fuploads%2Farticles%2Flt2405c4ht43vh3mtxri.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%2Flt2405c4ht43vh3mtxri.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
e.g. &lt;code&gt;amazon.com&lt;/code&gt; -&amp;gt; client contact root server --&amp;gt; root server return IP address for TLD server (the com DNS server) -&amp;gt; client contact TLD server -&amp;gt; TLD server returns IP addrss for authoritative server for &lt;code&gt;amazon.com&lt;/code&gt; -&amp;gt; authoritative server returns IP address&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Local DNS server&lt;br&gt;
not in hierachy. Each ISP will have local DNS server, when host connect to ISP, ISP provides host with IP address of DNS server (typically via DHCP) &lt;br&gt;
host makes DNS query, query sent to local DNS server which acts as proxy forwarding query to DNS server hierarchy.&lt;br&gt;
DNS queries can be iterative or recursive&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%2Fuploads%2Farticles%2F5b4lidux9arananbq6l5.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%2F5b4lidux9arananbq6l5.png" alt="alt text"&gt;&lt;/a&gt; &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%2Fuploads%2Farticles%2Fhuqrkx55i35svgko1laf.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%2Fhuqrkx55i35svgko1laf.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Caching &lt;/u&gt;&lt;br&gt;
in query chain, DNS servers do caching so results can be returned more quickly &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Overview: TCP &amp;amp; UDP&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;TCP/IP network makes 2 distinct transport-layer protocols to application layer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;TCP&lt;/strong&gt; (Transmission Control Protocol)   &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;provides reliable, connection-oriented service to the invoking application&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;UDP&lt;/strong&gt; (User Datagram Protocol) &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;provides unreliable connection-less service to invoking application&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Relation between transport &amp;amp; network layer&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;extend host-to-host delivery service provided by network layer to process-to-process delivery service for applications running on hosts.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;At destination host, transport layer receives segments from network layer below, transport layer responsible for delivering data in segments to appropriate application process running in host. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;eg. in your computer u run 4 processes (FTP session, webpage HTTP session + 2 telnet sessions) transport layer on receiving data from network layer must direct it to 1 of these 4 processes&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%2Fovr6pldcm66fkesfa014.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%2Fovr6pldcm66fkesfa014.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
Process can have 1 or more sockets (door through which data passes from network to process) transport layer in receiving host delivers data to an intermediary socket. &lt;/p&gt;

&lt;p&gt;Example.&lt;br&gt;
transport layer: TCP / UDP&lt;br&gt;
network layer: IP &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Multiplexing &amp;amp; demultiplexing&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;demultiplexing&lt;/strong&gt;: at receiving end, transport layer examine segment fields to identify receiving socket &amp;amp; deliver it to correct socket &lt;br&gt;
&lt;strong&gt;multiplexing&lt;/strong&gt;: at source host, gather data chunks from different socket, encapsulate each data chunk with header info to create segment and pass them to network&lt;/p&gt;
&lt;/blockquote&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%2F1aye1h4yzk8d2oy6rq2t.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%2F1aye1h4yzk8d2oy6rq2t.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;small&gt;&lt;a href="https://www.geeksforgeeks.org/multiplexing-and-demultiplexing-in-transport-layer/" rel="noopener noreferrer"&gt;reference&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;TCP and UDP perform demultiplexing &amp;amp; multiplexing by including 2 fiels in segment headers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;source port&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;destination port&lt;/strong&gt;&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff3c6r2vw8lziz0ewo249.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%2Ff3c6r2vw8lziz0ewo249.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
port numbers are 16 bit&lt;br&gt;
both fields &lt;em&gt;together&lt;/em&gt; uniquely identity application process running on destination host&lt;/p&gt;

&lt;p&gt;Each socket assigned port umber when segment arrives at host tarnsport layer examines destination port number and directs segment to corresponding socket. Segment's data passes through socket to attached process.&lt;/p&gt;

&lt;p&gt;Refernce:&lt;br&gt;
&lt;a href="http://www2.ic.uff.br/%7Emichael/kr1999/3-transport/3_02-fund.html" rel="noopener noreferrer"&gt;http://www2.ic.uff.br/~michael/kr1999/3-transport/3_02-fund.html&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;UDP: connectionless tarnsport&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;connectionless&lt;/em&gt; because there is no handshaking between sending &amp;amp; receiving transport-layer entities before sending segment.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;takes messages from application process&lt;/li&gt;
&lt;li&gt;attaches source and destination port number (for multiplexing &amp;amp; demultiplexing)&lt;/li&gt;
&lt;li&gt;adds 2 other small fields&lt;/li&gt;
&lt;li&gt;pass resulting segment to network layer&lt;/li&gt;
&lt;li&gt;network layer encapsulate transport-layer segment into an IP datagram &amp;amp; make best-effort attempt to deliver segment to receiving host&lt;/li&gt;
&lt;li&gt;If segment arrives at receiving host, UDP use destination port number to deliver segment data to correct application process.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;u&gt;In Practice&lt;/u&gt;&lt;br&gt;
DNS is an applicatio-layer protocol that uses UDP&lt;br&gt;
when DNS application in host wants to make query&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;application constructs DNS query message &amp;amp; passes it to UDP&lt;/li&gt;
&lt;li&gt;host-side UDP adds header fiels to message&lt;/li&gt;
&lt;li&gt;host-side UDP passes resulting segment to network layer&lt;/li&gt;
&lt;li&gt;netowrk layer encapsulates UDP segment to datagram &amp;amp; sends datagram to name server&lt;/li&gt;
&lt;li&gt;DNS application at querying host waits for reply to query&lt;/li&gt;
&lt;li&gt;If no reply (becuase underlying network lost query / reply), it tries sending query to another name server / inform invoking application that it can;t get reply &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;u&gt; Why UDP &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lesser delays&lt;/strong&gt;: No handshake = no delay to establish connection&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Small packer header overhead&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Support more clients&lt;/strong&gt;: No connection state  = server devoted to particular application can support more active client when application runs over UDP rather than TCP&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;UDP: Checksum&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;provides error detection: ensure bits in UDP segment have not been altered &lt;/p&gt;
&lt;/blockquote&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%2Fzi2pbj0wnwjm7kqzom99.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%2Fzi2pbj0wnwjm7kqzom99.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sender

&lt;ul&gt;
&lt;li&gt;sender performs 1s complement of sum of all words in segment (any overflow is wrapped around) &lt;/li&gt;
&lt;li&gt;result is put in checksum field&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Receiver

&lt;ul&gt;
&lt;li&gt;if segment arrives&lt;/li&gt;
&lt;li&gt;all 4 16-bit words are added together with cehcksum&lt;/li&gt;
&lt;li&gt;sum = 1111111111111111&lt;/li&gt;
&lt;li&gt;segment has no errors. If there is &amp;gt;=one 0 there are errors.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Why checksum? &lt;/u&gt;-layer protocols) between source &amp;amp; destination provide error checking. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;TCP: Connection-Oriented Transport&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;TCP(&lt;em&gt;Transmission Control Protocol&lt;/em&gt;)Internet's transport-layer connection-oriented reliable transport protocol&lt;br&gt;
TCP connection provides a &lt;strong&gt;full-duplex service&lt;/strong&gt;.&lt;br&gt;
TCP connection is always &lt;strong&gt;point-to-point&lt;/strong&gt; (between single sender &amp;amp; single receiver)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;b&gt;&lt;u&gt;Connection-Oriented&lt;/u&gt;&lt;/b&gt;&lt;br&gt;
before 1 application process sends data to another, 2 processes must first "handshake" with each other&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;u&gt;Reliable Data Transfer&lt;/u&gt;&lt;/b&gt;&lt;br&gt;
TCP relies on principles of reliable data transmission&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;error detection&lt;/li&gt;
&lt;li&gt;retransmission&lt;/li&gt;
&lt;li&gt;cumulative acknowledgement&lt;/li&gt;
&lt;li&gt;timers &lt;/li&gt;
&lt;li&gt;header fields for sequence &amp;amp; acknowledgement numbers&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;TCP Connection: 3 way handshake&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;3-way handshake&lt;/strong&gt; process to establish a fully-duplex communication&lt;/p&gt;
&lt;/blockquote&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%2Fctrzrrv9heu6anmvn8jv.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%2Fctrzrrv9heu6anmvn8jv.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SYN&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;client wants to establish connection with server.&lt;/li&gt;
&lt;li&gt;client send segment with SYN (synchronize Sequence Number) that informs server that client is likely to start communication with with what sequence number it starts segment with&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;SYN+ACK&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;server responds to client request with SYN + ACK signal bits set.&lt;/li&gt;
&lt;li&gt;ACK: signifies response of segment it received&lt;/li&gt;
&lt;li&gt;SYN: signifies with what sequence number it is likely to start segments with&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;ACK&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;client acknowledges response of server &amp;amp; both establish reliable connection with which they will start the actual data transfer&lt;/li&gt;
&lt;/ul&gt;


&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdts9h1v77j1met2iei1e.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%2Fdts9h1v77j1met2iei1e.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;SYN &amp;amp; SYN+ACK establish connection parameter (sequence number) for one direction &amp;amp; it is acknowledged&lt;br&gt;
SYN+ACK &amp;amp; ACK establish the connection parameter (sequence number) for other direction &amp;amp; it is acknowledged. &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%2Fazl3l29n2u1rpfsoaxkk.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%2Fazl3l29n2u1rpfsoaxkk.png" alt="alt text"&gt;&lt;/a&gt;&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%2F4fzoeuo49e3pns5fxmvn.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%2F4fzoeuo49e3pns5fxmvn.png" alt="alt text"&gt;&lt;/a&gt;&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%2Fm8jthtwvzbgavshnzlff.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%2Fm8jthtwvzbgavshnzlff.png" alt="alt text"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/courses/grokking-computer-networking/xlMyzABwL33" rel="noopener noreferrer"&gt;educative&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Reliable Data Transfer - Concepts + Introduction&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Information in this section is all taken from this &lt;a href="https://zackofwest.medium.com/reliable-data-transfer-protocols-rdt-the-reliability-guarantee-that-keeps-the-internet-running-e555a4fb375d" rel="noopener noreferrer"&gt;medium article&lt;/a&gt; by Zack West.&lt;br&gt;
I *&lt;em&gt;HIGHLY RECOMMEND&lt;/em&gt; reading it. It introduces concepts for reliable data transfer in a really simple and concise way. In summary.&lt;/p&gt;

&lt;p&gt;Reliable data transfer has 2 key components:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;data loss&lt;/li&gt;
&lt;li&gt;data corruption&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are a few components that address this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ACK

&lt;ul&gt;
&lt;li&gt;acknowledgement from receiver to let sender know data is received.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Timeout

&lt;ul&gt;
&lt;li&gt;timeout in case sender never receives ACK/NACK response&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Mapping ACK/NACK to data segment sent &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;stop and wait

&lt;ul&gt;
&lt;li&gt;sender sends single data segment and waits for response&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;SEQ (send multiple data segments)

&lt;ul&gt;
&lt;li&gt;SEQ (sequence numbers). When sender sends multiple data segments. SEQ lets the sender know which ACK / NACK message is for which data segment&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Pipelined protocols &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go back N

&lt;ul&gt;
&lt;li&gt;sliding window&lt;/li&gt;
&lt;li&gt;sender transmit packets waits on ACKs from receiver.&lt;/li&gt;
&lt;li&gt;as sender receives ACKs base value (representing window minimum) slides forward "quthorixing" incremented SEQ numbered-segments&lt;/li&gt;
&lt;li&gt;receiver: packets received out of order are discarded&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;selective repeat

&lt;ul&gt;
&lt;li&gt;receiver can accept packets out of order.&lt;/li&gt;
&lt;li&gt;receiver can accept &amp;amp; buffer frames following a damaged or lost one&lt;/li&gt;
&lt;li&gt;retransmission of packets happen when:&lt;/li&gt;
&lt;li&gt;implicit: packets are not ACKed nefore time out&lt;/li&gt;
&lt;li&gt;explicit: explicit NACK&lt;/li&gt;
&lt;/ul&gt;


&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F42s3labtk57baedmeodg.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%2F42s3labtk57baedmeodg.png" alt="alt text"&gt;&lt;/a&gt;&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%2Fuploads%2Farticles%2Facu73rd4o8d4vgz43z79.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%2Facu73rd4o8d4vgz43z79.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;GBN &amp;amp; SR further reading:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.geeksforgeeks.org/sliding-window-protocol-set-3-selective-repeat/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/sliding-window-protocol-set-3-selective-repeat/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.studytonight.com/post/flow-control-gobackn-arq-protocol" rel="noopener noreferrer"&gt;https://www.studytonight.com/post/flow-control-gobackn-arq-protocol&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.studytonight.com/post/flow-control-selective-repeat-protocol" rel="noopener noreferrer"&gt;https://www.studytonight.com/post/flow-control-selective-repeat-protocol&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;TCP Is a mix of GBN &amp;amp; SR (&lt;a href="https://networkengineering.stackexchange.com/a/29478" rel="noopener noreferrer"&gt;https://networkengineering.stackexchange.com/a/29478&lt;/a&gt;)&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;TCP Connection: Reliable Data Transfer&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;TCP creates &lt;strong&gt;reliable data transfer&lt;/strong&gt; service on top of IP's unreliable best-effort service.&lt;br&gt;
TCP reliable data transfer service ensures data stream that a process reads out of its TCP receive buffer is uncorrupted &lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;data received from application

&lt;ul&gt;
&lt;li&gt;TCP receive data, encapsulate data in segment, pass segment to IP (each segment includes a sequence number - byte-stream number of first data byte in segment)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;timer timeout

&lt;ul&gt;
&lt;li&gt;TCP re transmits segment that caused timeout&lt;/li&gt;
&lt;li&gt;TCP restarts timer&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;ACK receipt

&lt;ul&gt;
&lt;li&gt;sener TCP determine whether ACK is &lt;em&gt;first time ACK&lt;/em&gt; for segment sender has yet to receive or a &lt;em&gt;duplicate ACK&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;first-time ACK: sender knows all data up to byte being acknowledge has been received correctly. It can update its TCP state variable.
&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%2Fnrae7r59otykx9n7kae1.png" alt="alt text"&gt;
ACK from Host B to Host A is lost. Host A re transmits segment after timeout. Host B receives the retransmission and observers from sequence number that the segment contains data that has already be received. Host B will discard bytes in retransmitted segment. 
&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%2Fgfzfq68hsu21alpb5oca.png" alt="alt text"&gt;
if second ACK segment arrives before the new timeout ends, the second segment (seq=100 sender segment) will not be sent.
&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%2F6g0ztfuj9ccmz326zfvc.png" alt="alt text"&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%2F6beptavczoe84n19d75l.png" alt="alt text"&gt;
Host A sends 2 segments but ACK of first is lost.
Host A gets ACK of 120. so it knows B has received both segments.
Host A will not resend second segment. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;TCP Connection Termination&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;4 step process&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%2Fuploads%2Farticles%2Fsu58a2aae3xwnnxr52jq.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%2Fsu58a2aae3xwnnxr52jq.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;TCP VS UDP&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Information from this sectio is taken from &lt;a href="https://www.guru99.com/tcp-vs-udp-understanding-the-difference.html" rel="noopener noreferrer"&gt;Guru99&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TCP

&lt;ul&gt;
&lt;li&gt;use when both client &amp;amp; server independently send packets at same time &amp;amp; occasional delay is acceptable (eg. Online Poker)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;UDP

&lt;ul&gt;
&lt;li&gt;both client and server may separately send packets &amp;amp; occasional delay is not acceptable (multiplayer games)&lt;/li&gt;
&lt;li&gt;multimedia&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Applications / Advantages&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TCP 

&lt;ul&gt;
&lt;li&gt;establish connection between 2 computers&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;UDP

&lt;ul&gt;
&lt;li&gt;can be use for servers that answer small queries from larger client base (eg.DNS)&lt;/li&gt;
&lt;li&gt;used by time-sensitive applications &lt;/li&gt;
&lt;li&gt;multicasting sending&lt;/li&gt;
&lt;/ul&gt;


&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frzx1m8a3zw16kh5no6zi.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%2Frzx1m8a3zw16kh5no6zi.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;What happens when u put URL in browser&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;I &lt;strong&gt;HIGHLY RECOMMEND&lt;/strong&gt; this &lt;a href="https://medium.com/@maneesha.wijesinghe1/what-happens-when-you-type-an-url-in-the-browser-and-press-enter-bb0aa2449c1a" rel="noopener noreferrer"&gt;medium article&lt;/a&gt; by maneesha wijesinghe1&lt;/p&gt;

&lt;p&gt;It is super detailed and if you are short on time, the headers provide a really good brief.&lt;br&gt;
basically,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;type in URL&lt;/li&gt;
&lt;li&gt;cache check for DNS record with IP address of URL. browser cache, OS cache, router cache, ISP cache&lt;/li&gt;
&lt;li&gt;not in cache, ISP DNS server do DNS lookup of URL (to get IP address)&lt;/li&gt;
&lt;li&gt;browser initiate TCP connection with server (of the website). SYN/ACK stuff&lt;/li&gt;
&lt;li&gt;TCP connection initiated, browser send HTTP request to server&lt;/li&gt;
&lt;li&gt;server contains web server (apache, nginx) server handles request sends back resposne&lt;/li&gt;
&lt;li&gt;server send HTTP response (usually for SPA, the page loads coz browsers sends HTTP GET and webserver returns index.html)&lt;/li&gt;
&lt;li&gt;browser displays HTML content&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Store password in DB&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.vaadata.com/blog/how-to-securely-store-passwords-in-database/" rel="noopener noreferrer"&gt;https://www.vaadata.com/blog/how-to-securely-store-passwords-in-database/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/store-password-database/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/store-password-database/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://auth0.com/blog/adding-salt-to-hashing-a-better-way-to-store-passwords/" rel="noopener noreferrer"&gt;https://auth0.com/blog/adding-salt-to-hashing-a-better-way-to-store-passwords/&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Dont store plain text&lt;/li&gt;
&lt;li&gt;Hash passwords&lt;/li&gt;
&lt;li&gt;Add salt (random phrase) to password&lt;/li&gt;
&lt;li&gt;Add dynamic salt (random phrase that changes for every user). each user will have to store hashed password + dynamic salt.&lt;/li&gt;
&lt;li&gt;use BCrypt VS md5. (BCrypt does salt)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;never tell someone their selected password is not unique&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;md5&lt;/u&gt;&lt;br&gt;
very quick hashing function -&amp;gt; faster calculation - faster brute force attacks&lt;/p&gt;

&lt;p&gt;&lt;u&gt;BCrypt&lt;/u&gt;&lt;br&gt;
&lt;a href="https://javascript.plainenglish.io/how-bcryptjs-works-90ef4cb85bf4" rel="noopener noreferrer"&gt;more info&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;generate salt&lt;/li&gt;
&lt;li&gt;hash password with generated salt&lt;/li&gt;
&lt;li&gt;can choose value of salt Rounds (increase time to compute hash &amp;amp; reduce brute force attacks) 
however time to compute hash must not be too long so users will not run out of patience&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;u&gt;bcrypt VS md5&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;slower =&amp;gt; brute force attacks are less effective&lt;/li&gt;
&lt;li&gt;can increase the number of iterations to match computing power. (if computing power increases)&lt;a href="https://javascript.plainenglish.io/how-bcryptjs-works-90ef4cb85bf4" rel="noopener noreferrer"&gt;info&lt;/a&gt;
&lt;a href="https://auth0.com/blog/hashing-in-action-understanding-bcrypt/" rel="noopener noreferrer"&gt;Auth0&lt;/a&gt; article explains why bcrypt (salt generation) is preferred&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>SQL</title>
      <dc:creator>limjy</dc:creator>
      <pubDate>Wed, 05 May 2021 08:17:18 +0000</pubDate>
      <link>https://dev.to/jing/sql-2jh7</link>
      <guid>https://dev.to/jing/sql-2jh7</guid>
      <description>&lt;p&gt;Should be a quick cramming / revision guide for SQL stuff. &lt;br&gt;
Tis is for Oracle SQL (some basics)&lt;/p&gt;
&lt;h2&gt;
  
  
  TOC
&lt;/h2&gt;

&lt;p&gt;&lt;u&gt;basics&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Oracle DUAL table&lt;/li&gt;
&lt;li&gt;constant&lt;/li&gt;
&lt;li&gt;concat&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;select&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Even Number / remainder&lt;/li&gt;
&lt;li&gt;Distinct / no duplicates&lt;/li&gt;
&lt;li&gt;Count&lt;/li&gt;
&lt;li&gt;Top / first X rows&lt;/li&gt;
&lt;li&gt;Pattern matching&lt;/li&gt;
&lt;li&gt;SubString&lt;/li&gt;
&lt;li&gt;Order by&lt;/li&gt;
&lt;li&gt;If else&lt;/li&gt;
&lt;li&gt;group&lt;/li&gt;
&lt;li&gt;null&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;aggregate&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;sum&lt;/li&gt;
&lt;li&gt;average&lt;/li&gt;
&lt;li&gt;round&lt;/li&gt;
&lt;li&gt;floor&lt;/li&gt;
&lt;li&gt;ceil&lt;/li&gt;
&lt;li&gt;max&lt;/li&gt;
&lt;li&gt;
min
&lt;u&gt; manipulation &lt;/u&gt;
&lt;/li&gt;
&lt;li&gt;replace&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; joins &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;types of joins&lt;/li&gt;
&lt;li&gt;select from join&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Oracle Dual Table&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;A special table, accessible to all users, used for evaluating expressions or calling functions.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT
  (10 + 5)/2
FROM
  dual;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt;Taken from &lt;a href="https://www.oracletutorial.com/oracle-basics/oracle-dual-table/"&gt;source&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Constant&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;To output a String / nice result just select string&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT 'There are ' || COUNT(ID) || ' participants'
FROM PARTICIPANTS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;a&gt;Concatenate&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Concatenate strings in oracle SQL.&lt;br&gt;
You can use the &lt;code&gt;||&lt;/code&gt; operator instead of nested &lt;code&gt;CONCAT&lt;/code&gt; functions&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'Tech on' || ' the Net'
Result: 'Tech on the Net'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt;&lt;a href="https://www.techonthenet.com/oracle/functions/concat2.php"&gt;reference&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Even Number&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;mod(&amp;lt;&amp;gt;,2) = 0&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT DISTINCT(CITY)
FROM STATION
WHERE MOD(ID,2) =0;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;a&gt;No Duplicates&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;SELECT DISTINCT(COLUMN)&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT DISTINCT(CITY)
FROM STATION
WHERE MOD(ID,2) =0;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;a&gt;count&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;COUNT(ROW)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;to count distinct rows:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;COUNT(DISTINCT(ROWS))&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;First X rows&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Oracle 12c (see &lt;a href="https://blogs.oracle.com/optimizer/fetch-first-rows-just-got-faster"&gt;here&lt;/a&gt;)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Fetch First X Rows only&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select   *
from     the_table
order by object_id
fetch first 10 rows only;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Otherwise,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;ROWNUM &amp;lt;= X&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT *
  FROM (SELECT * FROM MyTbl ORDER BY Fname )
 WHERE ROWNUM = 1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt;see &lt;a href="https://stackoverflow.com/a/3451577"&gt;here&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Pattern Mathcing / LIKE&lt;/a&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;LIKE&lt;/code&gt; / &lt;code&gt;NOT LIKE&lt;/code&gt; - pattern matching&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;REGEXP_LIKE&lt;/code&gt; / &lt;code&gt;NOT REGEXP_LIKE&lt;/code&gt;- pattern matching with regular expression&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Wild card characters are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;%&lt;/code&gt; : any number of characters&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;_&lt;/code&gt; : 1 character&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ending with er
SELECT
    first_name,
    last_name,
    phone
FROM
    contacts
WHERE
    last_name LIKE '%er'

# Je 1 character and then i
# eg. Jeni/ Jedi
SELECT
    first_name,
    last_name,
    email,
    phone
FROM
    contacts
WHERE
    first_name LIKE 'Je_i'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NOT LIKE&lt;br&gt;
can you not like to find string no matching pattern&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT
  first_name, last_name, phone
FROM
  contacts
WHERE
  phone NOT LIKE '+1%'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt;&lt;a href="https://www.oracletutorial.com/oracle-basics/oracle-like/"&gt;reference&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;REGEXP_LIKE&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;REGEXP_LIKE(source_string, search_pattern [, match_parameter]);&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* starts with m or n */
SELECT
  first_name
FROM
  employees
WHERE
  REGEXP_LIKE(first_name,'^m|^n','i')

/* does not end with vowel */
SELECT DISTINCT(CITY)
FROM STATION
WHERE NOT REGEXP_LIKE(CITY,'(a|e|i|o|u)$');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt;&lt;a href="https://www.oracletutorial.com/oracle-string-functions/oracle-regexp_like/"&gt;reference&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Substring&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;extracts a substring from a string&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;SUBSTR( str, start_position [, substring_length, [, occurrence ]] );&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;start_position&lt;br&gt;
+ve / 0 -&amp;gt; count from beginning of string &lt;br&gt;
0 is first character&lt;br&gt;
1 can also be first character &lt;br&gt;
start_position can be &lt;em&gt;negative&lt;/em&gt;. will count backward from end of str to find first character of substring&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;substring_length&lt;br&gt;
if omitted gets string from start_position till end of string&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/*get last 3 characters*/
SUBSTR(NAME, -3)

SUBSTR( 'Oracle Substring', - 16, 6 ) 
SUBSTR( 'Oracle Substring', 1, 6 ) /*result is Oracle*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt;&lt;a href="https://www.oracletutorial.com/oracle-string-functions/oracle-substr/"&gt;reference&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Order By / Ordering&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Sorting results&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ORDER BY
    column_1 [ASC | DESC] [NULLS FIRST | NULLS LAST],
    column_1 [ASC | DESC] [NULLS FIRST | NULLS LAST],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to sort multiple columns just add another argument. SQL will sort by first condition first then second condition&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;If Else&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;CASE&lt;/code&gt; &amp;amp; &lt;code&gt;WHEN&lt;/code&gt; to use if else logic in sql query&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CASE [ expression ]
   WHEN condition_1 THEN result_1
   WHEN condition_2 THEN result_2
   ...
   WHEN condition_n THEN result_n

   ELSE result
END
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you can omit expression to return a constant value (eg. hackerrank binary tree question)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT 
    CASE 
      WHEN P IS NULL THEN N || ' Root'
      WHEN N IN(SELECT DISTINCT(P) FROM BST) THEN N || ' Inner'
      ELSE N || ' Leaf'
    END 
FROM BST
ORDER BY N;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT
  product_name,
  list_price,
  CASE category_id
    WHEN 1
    THEN ROUND(list_price * 0.05,2) 
    WHEN 2
    THEN ROUND(List_price * 0.1,2) 
    ELSE ROUND(list_price * 0.08,2)
  END discount
FROM
  products
ORDER BY
  product_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;a&gt;Group By&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;group rows into groups&lt;/p&gt;

&lt;p&gt;Basic example &lt;code&gt;SELECT status FROM orders GROUP BY status;&lt;/code&gt;&lt;br&gt;
This is equivalent to &lt;code&gt;SELECT DISTINCT status FROM orders;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Aggregate functions. Find count of order_id for same customer_id&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT
    customer_id,
    COUNT( order_id )
FROM
    orders
GROUP BY
    customer_id
ORDER BY
    customer_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;a&gt;Is Null&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;to check if column value is null or not null&lt;br&gt;
SELECT * FROM orders &lt;br&gt;
WHERE salesman_id IS NULL&lt;br&gt;
ORDER BY order_date DESC;&lt;br&gt;
&lt;small&gt;&lt;a href="https://www.oracletutorial.com/oracle-basics/oracle-is-null/"&gt;reference&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a&gt;Sum&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;sum of all or distinct values&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT
    product_id,
    SUM( quantity )
FROM
    order_items

SELECT
    order_id,
    SUM( quantity * unit_price ) order_total
FROM
    order_items
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;a&gt;Average&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;calculate average of a group&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT AVG( list_price ) avg_list_price
FROM products;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;a&gt;Round&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;round &lt;strong&gt;off&lt;/strong&gt; number to decimal place&lt;br&gt;
&lt;code&gt;ROUND(n, integer)&lt;/code&gt;&lt;br&gt;
if integer not given it is 0.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT ROUND(15.193,1) "Round" FROM DUAL;

     Round
----------
      15.2

## round to left of decimal place
SELECT ROUND(15.193,-1) "Round" FROM DUAL;

     Round
----------
        20 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions135.htm"&gt;https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions135.htm&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;floor&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Returns the largest integer value that is equal to or less than a number.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FLOOR(5.9)
Result: 5

FLOOR(34.29)
Result: 34

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://www.techonthenet.com/oracle/functions/floor.php"&gt;https://www.techonthenet.com/oracle/functions/floor.php&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;max&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;return maximum value of expression&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;### maximum salary per department
SELECT department, MAX(salary) AS "Highest salary"
FROM employees
GROUP BY department;

### find top earnings (salary * months) &amp;amp; number of employees with top earnings
SELECT MAX(salary*months), COUNT(*) FROM EMPLOYEE 
WHERE salary * months = (SELECT MAX(salary*months) FROM EMPLOYEE);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://www.techonthenet.com/oracle/functions/max.php"&gt;https://www.techonthenet.com/oracle/functions/max.php&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;types of joins&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M-acmiMv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/din8tn4bns4vwtwn4eh2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M-acmiMv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/din8tn4bns4vwtwn4eh2.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To exclude entries in left or right table (get right entries that DO NOT match left) try WHERE .id IS NULL&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT
    a.id id_a,
    a.color color_a,
    b.id id_b,
    b.color color_b
FROM
    palette_a a
RIGHT JOIN palette_b b ON a.color = b.color
WHERE a.id IS NULL;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://www.oracletutorial.com/oracle-basics/oracle-joins/"&gt;https://www.oracletutorial.com/oracle-basics/oracle-joins/&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;select from joins&lt;/a&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT SUM(CITY.population)
FROM CITY
FULL OUTER JOIN COUNTRY
ON CITY.CountryCode = COUNTRY.Code
WHERE COUNTRY.Continent = 'Asia';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Web Dev Theory Stuff</title>
      <dc:creator>limjy</dc:creator>
      <pubDate>Tue, 20 Apr 2021 15:49:05 +0000</pubDate>
      <link>https://dev.to/jing/web-dev-theory-stuff-1lpk</link>
      <guid>https://dev.to/jing/web-dev-theory-stuff-1lpk</guid>
      <description>&lt;p&gt;Theory stuff&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;CORS&lt;/li&gt;
&lt;li&gt;CSRF&lt;/li&gt;
&lt;li&gt;403 vs 401&lt;/li&gt;
&lt;li&gt;How to store password&lt;/li&gt;
&lt;li&gt;
HTTPS
&lt;/li&gt;
&lt;li&gt;
process-when-visit-URL
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;CORS&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Cross Origin Resource Sharing&lt;br&gt;
HTTP-header based mechanism that allows a server to indicate any other origins than its own from which a browser should permit loading of resources. &lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS"&gt;source&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;CSRF&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Cross Site Request Forgery&lt;br&gt;
web security vulnerability that allows an attacker to induce users to perform actions that they do not intend to perform.&lt;br&gt;
Attack requires:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Relevant action. 
There is a privileged action within the application that the attacker has a reason to induce. &lt;/li&gt;
&lt;li&gt;Cookie-based session handling. 
Performing the action involves issuing one or more HTTP requests, and the application relies solely on session cookies to identify the user who has made the requests. &lt;/li&gt;
&lt;li&gt;No unpredictable request parameters. 
The requests that perform the action do not contain any parameters whose values the attacker cannot determine or guess&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://portswigger.net/web-security/csrf"&gt;https://portswigger.net/web-security/csrf&lt;/a&gt;&lt;br&gt;
&lt;a href="https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html"&gt;https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;workaround:&lt;br&gt;
same-site policy&lt;br&gt;
cookies only accessible by only your domain&lt;/p&gt;

&lt;p&gt;Cookie security:&lt;br&gt;
&lt;a href="https://www.cookiepro.com/knowledge/httponly-cookie/"&gt;HttpOnly cookie&lt;/a&gt; prevents client-side scripts from accessing data. It provides a gate that prevents the specialized cookie from being accessed by anything other than the server.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;CORS&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;403: Forbidden &lt;br&gt;
401: Unauthenticated&lt;/p&gt;

&lt;p&gt;403 - can login, is authorized user of application but not enought priviledge to access functions.&lt;br&gt;
401 - cannot login, unauthorised user&lt;/p&gt;

&lt;h3&gt;
  
  
  JWT
&lt;/h3&gt;

&lt;p&gt;JSON Web token&lt;br&gt;
compact and self-contained way for securely transmitting information between parties as a JSON object.&lt;br&gt;
&lt;a href="https://auth0.com/docs/tokens/json-web-tokens"&gt;https://auth0.com/docs/tokens/json-web-tokens&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  JWT VS Cookie
&lt;/h3&gt;

&lt;p&gt;Cookie is automatically sent by browser. JWT must be attached to HTTP headers every HTTP call.&lt;br&gt;
&lt;a href="https://stackoverflow.com/a/37635977"&gt;https://stackoverflow.com/a/37635977&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Scalability&lt;br&gt;
as user base grows must store  more session data. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Seurity&lt;br&gt;
JWT if stored in web storage (local/sessino storage) is vulnerable to XSS.&lt;br&gt;
Cookies may be vulnerable to CSRF&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;to circumvent attacks JWT usually have short expiration time&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;REST ful API&lt;br&gt;
RESTful API is stateless - when request is made response with certain parameters can alwayse anticipated&lt;br&gt;
JWT is stateless, cookie it not. cookie mantain session state&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Performance&lt;br&gt;
if a lot of data encoded in JWT there will be significant overhead with every HTTP request. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://ponyfoo.com/articles/json-web-tokens-vs-session-cookies"&gt;https://ponyfoo.com/articles/json-web-tokens-vs-session-cookies&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;XSS 
Cross site scripting
inject malicious code into vulnerable web application. It doesn't directly target aplication, users of web application are the ones at risk. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://www.imperva.com/learn/application-security/cross-site-scripting-xss-attacks/"&gt;https://www.imperva.com/learn/application-security/cross-site-scripting-xss-attacks/&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;localStorage VS sessionStorage
data in sessionStorage clear when page session ends but data in localStorage doesnt expire. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;both access a session storage object for the current origin. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage"&gt;https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Store password in DB&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.vaadata.com/blog/how-to-securely-store-passwords-in-database/"&gt;https://www.vaadata.com/blog/how-to-securely-store-passwords-in-database/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/store-password-database/"&gt;https://www.geeksforgeeks.org/store-password-database/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://auth0.com/blog/adding-salt-to-hashing-a-better-way-to-store-passwords/"&gt;https://auth0.com/blog/adding-salt-to-hashing-a-better-way-to-store-passwords/&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Dont store plain text&lt;/li&gt;
&lt;li&gt;Hash passwords&lt;/li&gt;
&lt;li&gt;Add salt (random phrase) to password&lt;/li&gt;
&lt;li&gt;Add dynamic salt (random phrase that changes for every user). each user will have to store hashed password + dynamic salt.&lt;/li&gt;
&lt;li&gt;use BCrypt VS md5. (BCrypt does salt)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;never tell someone their selected password is not unique&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;md5&lt;/u&gt;&lt;br&gt;
very quick hashing function -&amp;gt; faster calculation - faster brute force attacks&lt;/p&gt;

&lt;p&gt;&lt;u&gt;BCrypt&lt;/u&gt;&lt;br&gt;
&lt;a href="https://javascript.plainenglish.io/how-bcryptjs-works-90ef4cb85bf4"&gt;more info&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;generate salt&lt;/li&gt;
&lt;li&gt;hash password with generated salt&lt;/li&gt;
&lt;li&gt;can choose value of salt Rounds (increase time to compute hash &amp;amp; reduce brute force attacks) 
however time to compute hash must not be too long so users will not run out of patience&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;u&gt;bcrypt VS md5&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;slower =&amp;gt; brute force attacks are less effective&lt;/li&gt;
&lt;li&gt;can increase the number of iterations to match computing power. (if computing power increases)&lt;a href="https://javascript.plainenglish.io/how-bcryptjs-works-90ef4cb85bf4"&gt;info&lt;/a&gt;
&lt;a href="https://auth0.com/blog/hashing-in-action-understanding-bcrypt/"&gt;Auth0&lt;/a&gt; article explains why bcrypt (salt generation) is preferred&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;HTTPS&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;previously SSL not TLS&lt;br&gt;
&lt;a href="https://robertheaton.com/2014/03/27/how-does-https-actually-work/"&gt;https://robertheaton.com/2014/03/27/how-does-https-actually-work/&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Hello&lt;/li&gt;
&lt;li&gt;Certificate exchange - server sends client its cert + public key (authentication, server is not impersonator) (SSL cert contains public key)
certificates usually come with digital signature, (signature encrypted with CA's "private" key) so you can take the CA public key decrypt and check if cert is signed by correct CA.&lt;/li&gt;
&lt;li&gt;Key Exchange - exchange symmetric key (encrypted with public key). 
All information exchanged encrypted with symmetric key since symmetric key can do encryption a lot more efficiently.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;man in middle can technically replay info from client to server. but information is encrypted and attacker will not have server's private key to decrypt and read information. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EvTtbTZ5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pmli43mw98b8d6ec2zp4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EvTtbTZ5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pmli43mw98b8d6ec2zp4.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Angular Theory</title>
      <dc:creator>limjy</dc:creator>
      <pubDate>Sat, 17 Apr 2021 10:36:11 +0000</pubDate>
      <link>https://dev.to/jing/angular-theory-553p</link>
      <guid>https://dev.to/jing/angular-theory-553p</guid>
      <description>&lt;p&gt;Summary of Angular theory stuff for myself.&lt;/p&gt;

&lt;p&gt;Some stuff to know&lt;/p&gt;

&lt;h3&gt;
  
  
  HTML DOM
&lt;/h3&gt;

&lt;p&gt;HTML Document Object Model.&lt;br&gt;
DOM is object-orientated representation of webpage which can be modified with scripting language like JS. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction" rel="noopener noreferrer"&gt;Further reading&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  TOC
&lt;/h2&gt;

&lt;p&gt;&lt;u&gt; Angular Intro &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is angular&lt;/li&gt;
&lt;li&gt;Angular VS AngularJS&lt;/li&gt;
&lt;li&gt;What is a SPA?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; npm + typescript &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NPM and node_modules folder&lt;/li&gt;
&lt;li&gt;package.json file&lt;/li&gt;
&lt;li&gt;package.json VS package.lock&lt;/li&gt;
&lt;li&gt;What is Typescript?&lt;/li&gt;
&lt;li&gt;Advantages of angular CLI&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; angular CLI questions &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ng serve VS ng build&lt;/li&gt;
&lt;li&gt;--prod flag&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;Angular Architecture questions&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is the architecture of Angular?&lt;/li&gt;
&lt;li&gt;What are directives in Angular?&lt;/li&gt;
&lt;li&gt;Component &amp;amp; Module in Angular&lt;/li&gt;
&lt;li&gt;What are decorators in angular&lt;/li&gt;
&lt;li&gt;What is a template in Angular?&lt;/li&gt;
&lt;li&gt;What is Data Binding in Angular?&lt;/li&gt;
&lt;li&gt;How is a SPA achieved in Angular?&lt;/li&gt;
&lt;li&gt;What is routing in Angular?&lt;/li&gt;
&lt;li&gt;How to implement routing in angular?&lt;/li&gt;
&lt;li&gt;What is lazy-loading?&lt;/li&gt;
&lt;li&gt;How to implement lazy loading?&lt;/li&gt;
&lt;li&gt;What are services in Angular?&lt;/li&gt;
&lt;li&gt;Service VS Component&lt;/li&gt;
&lt;li&gt;What is dependency Injection&lt;/li&gt;
&lt;li&gt;How to implement dependency injection&lt;/li&gt;
&lt;li&gt;Benefits of Dependency Injection&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;Children stuff (ViewChild, ViewChildren, ContentChild, ContentChildren)&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
ViewChild &amp;amp; ViewChildren &lt;/li&gt;
&lt;li&gt;Template reference variable&lt;/li&gt;
&lt;li&gt;What is content projection?&lt;/li&gt;
&lt;li&gt;ContentChild &amp;amp; ContentChildren&lt;/li&gt;
&lt;li&gt;Static flag&lt;/li&gt;
&lt;li&gt;ViewChild, ViewChildren VS ContentChild, ContentChildren&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;Angular Lifecycle questions&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Importance of component lifecycle?&lt;/li&gt;
&lt;li&gt;Events &amp;amp; sequence of component lifecycle?&lt;/li&gt;
&lt;li&gt;constructor VS ngOnInit?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; HTTP &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to make HTTP calls in angular?&lt;/li&gt;
&lt;li&gt;Need for subscribe function&lt;/li&gt;
&lt;li&gt;How to handle errors in HTTP calls?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Passing Data&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pass Data between components &amp;amp; routes&lt;/li&gt;
&lt;li&gt;Passing data via service?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; Pipe &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is Angular Pipe?&lt;/li&gt;
&lt;li&gt;How to make custom pipe in Angular?&lt;/li&gt;
&lt;li&gt;Change Detection in Angular pipe&lt;/li&gt;
&lt;li&gt;Pure VS impure angular pipe&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt; RxJS&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Synchronous VS Asynchronous &lt;/li&gt;
&lt;li&gt;What is RxJS?&lt;/li&gt;
&lt;li&gt;What are Observables &amp;amp; observers?&lt;/li&gt;
&lt;li&gt;Importance of subscribe in RxJS&lt;/li&gt;
&lt;li&gt;How to unsubscribe?&lt;/li&gt;
&lt;li&gt;Concept of operators&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  What is angular &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Javascript framework. &lt;br&gt;
Main help: &lt;br&gt;
Helps bind view (HTML) to model (object). this helps developer implement MVC framework. Pure JS requires lots of code.&lt;br&gt;
Main features:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;SPA. angular helps developer implement single page application with routing. (url will change but only 1 index.html)&lt;/li&gt;
&lt;li&gt;Dependency Injection. (Angular helps developer instantiate components) eg. to inject service into component just put it into constructor method.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Angular VS AngularJS &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;small&gt; tbh im not very sure about this, I try not to work with AngularJS lmao &lt;/small&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Javascript VS Typescript &lt;/li&gt;
&lt;li&gt;CLI Builder&lt;/li&gt;
&lt;li&gt;can use Angular CLI to build components &amp;amp; services&lt;/li&gt;
&lt;li&gt;lazy-loading&lt;/li&gt;
&lt;li&gt;load only certain modules when needed. loading is only done when user navigates to route of respective module &lt;a href="https://medium.com/@thiago.reis/how-to-implement-lazy-loading-in-angular-c8dcbf165561" rel="noopener noreferrer"&gt;see more&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  What are directives in Angular? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Instructions in HTML that tells angular how to transform the HTML DOM &lt;/p&gt;

&lt;p&gt;3 main directives (SAC)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;C&lt;/strong&gt;omponent Directives&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;S&lt;/strong&gt;tructural Directives&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A&lt;/strong&gt;ttribute Directives&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Take note: &lt;strong&gt;a component is technically a directive&lt;/strong&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Component Directives
&lt;/h4&gt;

&lt;p&gt;directives with templates. its like user control&lt;/p&gt;

&lt;p&gt;A component is technically a directive. &lt;code&gt;@Component&lt;/code&gt; extends the &lt;code&gt;@Directive&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;e.g. declare a custom component my-grid. component directive is then &lt;code&gt;&amp;lt;my-grid&amp;gt;&amp;lt;/my-grid&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;More information in &lt;a href="https://angular.io/guide/architecture-components#directives" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Structural Directives
&lt;/h4&gt;

&lt;p&gt;Change structure of elements (add / remove DOM) &lt;br&gt;
eg. NgIf, NgFor NgSwitch (switch case for ngif)&lt;/p&gt;
&lt;h4&gt;
  
  
  Attribute Directive
&lt;/h4&gt;

&lt;p&gt;Change behaviour &amp;amp; appearance of elements&lt;br&gt;
eg. NgStyle, NgClass&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Read more in this &lt;a href="https://blogpedia.org/blogs/28/angular-directive-vs-components#:~:text=Components%20are%20typically%20used%20to,to%20design%20re%2Dusable%20components." rel="noopener noreferrer"&gt;article&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  NPM &amp;amp; node_modules folder &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;NPM = node pacakge manager.&lt;br&gt;
Helps make installization of JS framework  libraries easy.&lt;br&gt;
node_modules = folder where all packages are installed. &lt;br&gt;
It also acts like a cache. when developer imports libraries without specific path nodeJs will look at node_modules folder&lt;br&gt;
Taken from &lt;a href="https://www.sitepoint.com/npm-guide/#:~:text=Node%20Packaged%20Modules,owned%20by%20the%20current%20user." rel="noopener noreferrer"&gt;sitepoint&lt;/a&gt; &amp;amp; &lt;a href="https://stackoverflow.com/a/63294579" rel="noopener noreferrer"&gt;SO&lt;/a&gt;&lt;br&gt;
&lt;u&gt;global VS local &lt;/u&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  package.json file &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;states all the JS references (i.e. dependencies of the project, library name). So developer can quickly install all dependencies at one shot with &lt;code&gt;npm install&lt;/code&gt;. &lt;br&gt;
node_modules can be re-created from scratch by doing &lt;code&gt;npm install&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  package.json VS package-lock.json &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;package.json record minimum version of libraries your application requires. It also defines project properties, author etc.&lt;br&gt;
package-lock only used to lock dependencies to specific version number. It records exact version of each installed package.&lt;/p&gt;
&lt;h3&gt;
  
  
  What is Typescript? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;superset of Javascript. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;adds types to JavaScript&lt;/li&gt;
&lt;li&gt;Object-oriented programming environment which compiles to JS&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This results in &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;less errors&lt;/li&gt;
&lt;li&gt;better code quality / productivity ???&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;** at the end of the day, TS will be compile to JS**&lt;/p&gt;

&lt;p&gt;more information on &lt;a href="https://www.guru99.com/typescript-vs-javascript.html#:~:text=TypeScript%20and%20JavaScript.-,KEY%20DIFFERENCE,doesn't%20need%20to%20compile." rel="noopener noreferrer"&gt;guru99&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;errors are pointed out at compile time (code needs to be compiled)&lt;/li&gt;
&lt;li&gt;TS uses concepts like types and interfaces to describe data&lt;/li&gt;
&lt;li&gt;TS needs compilation. must compile to JS. &lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Importance / Advantages of angular CLI &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Helps developer generate boiler plate code as opposed to starting from scratch&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;generate ready made project &lt;code&gt;ng new my-app&lt;/code&gt; (make src files, module file) &lt;/li&gt;
&lt;li&gt;generate ready-made schematics (eg. components / services / directives) &lt;code&gt;ng generate service/component&lt;/code&gt; &lt;a href="https://angular.io/cli/generate" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Importance of Component &amp;amp; Module  in Angular &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Components are the main building blocks in angular. Each component consists of : &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;HTML template (declares what renders on page)&lt;/li&gt;
&lt;li&gt;typescript class that defines behaviour&lt;/li&gt;
&lt;li&gt;CSS selector that defines how component is used in a template&lt;/li&gt;
&lt;li&gt;CSS styles applied to template
&lt;small&gt;From &lt;a href="https://angular.io/guide/component-overview" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;&lt;/small&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  Component VS Module
&lt;/h4&gt;

&lt;p&gt;Component:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;controls view (html) &lt;/li&gt;
&lt;li&gt;communicate with other components and services to bring functionality to applucation&lt;/li&gt;
&lt;/ol&gt;

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

&lt;ol&gt;
&lt;li&gt;logical groups of components &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;small&gt; Reference: &lt;a href="https://stackoverflow.com/a/40074319" rel="noopener noreferrer"&gt;SO answer&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  What is Decorator(Annotation / Metadata) in angular &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;tells Angular what kind of class it is.&lt;br&gt;
Above the class declaration&lt;br&gt;
eg. &lt;code&gt;@Component&lt;/code&gt; -&amp;gt; Angular Component. &lt;code&gt;@NgModule&lt;/code&gt; -&amp;gt; Angular Module&lt;br&gt;
** may also be asked how to create component and module in angular) **&lt;/p&gt;

&lt;p&gt;must be decorators when declaring components and modules in angular&lt;/p&gt;
&lt;h3&gt;
  
  
  What is a Template in Angular? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;HTML view of Angular where you can write directives&lt;/p&gt;

&lt;p&gt;There are two ways you can write templates:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;inline (define it in &lt;code&gt;@Component({template: &amp;lt;&amp;lt;here&amp;gt;&amp;gt;})&lt;/code&gt; directive)&lt;/li&gt;
&lt;li&gt;separate HTML file  (define it in component templateUrl)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Further reading &lt;a href="https://www.c-sharpcorner.com/article/template-vs-templateurl-in-angular/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  What is Data Binding in Angular? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;How component and view communicate with each other.&lt;br&gt;
&lt;a href="https://angular.io/guide/architecture-components#data-binding" rel="noopener noreferrer"&gt;Documentation&lt;/a&gt; and &lt;a href="https://angular.io/guide/binding-syntax#types-of-data-binding" rel="noopener noreferrer"&gt;more details&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Interpolation ------ &lt;code&gt;{{expression}}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;property binding-----&lt;code&gt;[target]=expression&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;event binding--------&lt;code&gt;(target)=statement&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;two-way binding-----&lt;code&gt;[(ngModel)]&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  interpolation
&lt;/h4&gt;

&lt;p&gt;one-way from component to view&lt;br&gt;
Data flows from component to view. can stick it with HTML (one-way)&lt;/p&gt;
&lt;h4&gt;
  
  
  property
&lt;/h4&gt;

&lt;p&gt;one-way biding from component. &lt;br&gt;
Data flow from component to viewsets specific element property. &lt;/p&gt;
&lt;h4&gt;
  
  
  event binding
&lt;/h4&gt;

&lt;p&gt;one-way. from event / view to component.&lt;br&gt;
event in view triggers a function in component. Listends for an element change event &lt;/p&gt;
&lt;h4&gt;
  
  
  two-way binding
&lt;/h4&gt;

&lt;p&gt;two-way. combines property binding with event binding&lt;/p&gt;

&lt;p&gt;set event in component. if some event happens in view it can trigger function in component.&lt;br&gt;
e.g. most commonly used in template forms&lt;/p&gt;

&lt;p&gt;&lt;small&gt;More details in &lt;a href="https://angular.io/guide/two-way-binding" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;For two-way binding to work, &lt;code&gt;@Output&lt;/code&gt; must use pattern &lt;code&gt;inputChange&lt;/code&gt; where &lt;code&gt;input&lt;/code&gt; is name of &lt;code&gt;@Input&lt;/code&gt; property&lt;br&gt;
e.g.&lt;br&gt;
&lt;/p&gt;

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

  @Input()  size: number | string;
  @Output() sizeChange = new EventEmitter&amp;lt;number&amp;gt;();
  resize(delta: number) {
    this.size = Math.min(40, Math.max(8, +this.size + delta));
    this.sizeChange.emit(this.size);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;using the two-way binding looks lie this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;app-sizer [(size)]="fontSizePx"&amp;gt;&amp;lt;/app-sizer&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explain architecture of Angular? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Angular consists of 7 main building blocks:&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%2Fgxx4rwcx8hzyahqa58h5.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%2Fgxx4rwcx8hzyahqa58h5.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Template (HTML view)&lt;/li&gt;
&lt;li&gt;Component (binds view an model)&lt;/li&gt;
&lt;li&gt;Binding (how component &amp;amp; template talk to each other)&lt;/li&gt;
&lt;li&gt;Module  (groups components logically)&lt;/li&gt;
&lt;li&gt;Directives (change style / behaviour of DOM)&lt;/li&gt;
&lt;li&gt;Service (share common logic across the project project)&lt;/li&gt;
&lt;li&gt;Dependency Injection (injects instances into constructor) (e.g. injecting services into component - just put into component constructor)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Further explanation in &lt;a href="https://v2.angular.io/docs/ts/latest/guide/architecture.html" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is SPA? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Single page application&lt;br&gt;
A Single page application is a web application /website taht ineracts with uer by dynamically rewriting current web page with new data from webserver. &lt;a href="https://en.wikipedia.org/wiki/Single-page_application" rel="noopener noreferrer"&gt;wiki&lt;/a&gt;&lt;br&gt;
This means the main UI gets loaded once and the other features are loaded on demand  / depending on user actions. &lt;br&gt;
In production, this means that there is just 1 index.html file with CSS bundle and JavaScript bundle. &lt;br&gt;
This is &lt;a href="https://docs.microsoft.com/en-us/dotnet/architecture/modern-web-apps-azure/choose-between-traditional-web-and-single-page-apps#:~:text=SPAs%20can%20support%20rich%20client,full%20page%20reloads%20are%20rare." rel="noopener noreferrer"&gt;advantageous&lt;/a&gt; especially when there is rich client-side functionality. SPA can load more quickly since full page reloads are rare. &lt;/p&gt;

&lt;p&gt;e.g. page with header, footer, drawer. in SPA only the stuff in between is loaded instead of the entire page. This gives performance improvements&lt;/p&gt;

&lt;p&gt;&lt;small&gt; More information about SPA on &lt;a href="https://blog.angular-university.io/why-a-single-page-application-what-are-the-benefits-what-is-a-spa/" rel="noopener noreferrer"&gt;angular university blog&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  How to implement SPA in Angular &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Routing&lt;/p&gt;

&lt;p&gt;Angular routing is a  simple collection with two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;URL &lt;/li&gt;
&lt;li&gt;Component to load when URL is called&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;helps to define navigation for angular application. It maps URL-like paths to views instead of pages. So when user moves from one screen / url to another, the application loads components not an entirely new page.  &lt;/p&gt;
&lt;h3&gt;
  
  
  What is routing in Angular &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;In Angular, routes comprise of :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;path (URL path)&lt;/li&gt;
&lt;li&gt;Component&lt;/li&gt;
&lt;li&gt;(optional) redirectTo path &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Routes map a URL path to a component. &lt;br&gt;
It helps users navigate from one view to another as users perform tasks on application&lt;br&gt;
Helps developer respect SPA since only components in page are changing, entire page is not reloaded.&lt;/p&gt;

&lt;p&gt;&lt;small&gt; Taken from: &lt;a href="https://www.pluralsight.com/guides/understanding-purpose-routing-angular" rel="noopener noreferrer"&gt;pluralsight&lt;/a&gt; &amp;amp; &lt;a href="https://www.smashingmagazine.com/2018/11/a-complete-guide-to-routing-in-angular/#:~:text=Routes%20are%20definitions%20(objects)%20comprised,be%20associated%20with%20a%20path." rel="noopener noreferrer"&gt;smashingmagazine&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  How to implement routing in angular. &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;define collection of routes in angular --&amp;gt; map url paths to components&lt;/li&gt;
&lt;li&gt;define router outlet --&amp;gt; where the component will be displayed&lt;/li&gt;
&lt;li&gt;[routerLink] in HTML OR this.router.navigate(url) in TS file --&amp;gt; allows user to navigate to different route / view &lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  What is lazy loading &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Loading on demand.&lt;br&gt;
Loading only the necessary HTML, CSS &amp;amp; JS files when needed. Loading other components only when needed (i.e. when user performs certain actions) &lt;/p&gt;
&lt;h3&gt;
  
  
  How to implement lazy loading? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Divide project into separate modules&lt;/li&gt;
&lt;li&gt;declare &lt;code&gt;loadChildren&lt;/code&gt; property in route object&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  What are services in Angular? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Service helps developer share common logic / common functionality across components&lt;/p&gt;
&lt;h3&gt;
  
  
  Service VS Component &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;small&gt; From &lt;a href="https://angular.io/guide/architecture-services" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;&lt;/small&gt;&lt;br&gt;
Components is to enable the user experience &amp;amp; &lt;strong&gt;nothing more&lt;/strong&gt;&lt;br&gt;
Component should: present properties and methods for data binding to mediate between template (&lt;em&gt;view&lt;/em&gt;) &amp;amp; application logic (&lt;em&gt;model&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;Components should delegate other tasks (o.e. fetching data from server, validating user input) to a service. &lt;br&gt;
The tasks in service can also be shared with other components vis &lt;em&gt;dependency injection&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  What is dependency Injection? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;application design pattern&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%2Fuploads%2Farticles%2Fx4s7l393wvpw6y4picq0.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%2Fx4s7l393wvpw6y4picq0.png" alt="alt text"&gt;&lt;/a&gt; &lt;br&gt;
Developer does not need to create object instances (no need to instantiate service &lt;code&gt;let service: ExampleService = new ExampleService()&lt;/code&gt; instead, Angular injects is via the constrcutr&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export class ExampleComponent{
  constructor (private service: ExampleService) {
    this.service.doSomething();
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt; taken from &lt;a href="https://angular.io/guide/architecture-services#dependency-injection-di" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How to implement dependency Injection in Angular? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;There are 3 ways to &lt;a href="https://angular.io/guide/architecture-services#providing-services" rel="noopener noreferrer"&gt;provide a service&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;root 
service is provided at root level, angular creates a &lt;em&gt;single, shared&lt;/em&gt;  (i.e. &lt;strong&gt;singleton&lt;/strong&gt;) instance of service &amp;amp; injects it into any class asking for it. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Injectable root decorator is provided in service class&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Injectable({
 providedIn: 'root',
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this is auto-generated with &lt;code&gt;ng generate service&lt;/code&gt;&lt;br&gt;
TO only provide service to certain module change &lt;code&gt;root&lt;/code&gt; to &lt;code&gt;ExampleModule&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'any',
})
export class UserService {
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;providedIn: any&lt;/code&gt; all eagerly loaded instance share singleton instance, but lazily loaded modules each get their own unique instance&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%2Fuploads%2Farticles%2Fhpp6niz67bfim5kaftx5.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%2Fhpp6niz67bfim5kaftx5.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;provide in module
register service in &lt;code&gt;providers&lt;/code&gt; array in NgModule
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@NgModule({
  providers: [
  ExampleService,
  Logger
 ],
 ...
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If NgModule is root AppModule, &lt;br&gt;
&lt;code&gt;ExampleService&lt;/code&gt; will be singleton and available throughout the app. &lt;br&gt;
&lt;a href="https://angular.io/guide/singleton-services#ngmodule-providers-array" rel="noopener noreferrer"&gt;Reference&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Importing service in &lt;code&gt;AppModule&lt;/code&gt; &lt;strong&gt;AND&lt;/strong&gt; lazily loaded module, the app can generate multiple instance of a service.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Component level
registering provider at component level, you get a &lt;strong&gt;new instance of service&lt;/strong&gt; with &lt;strong&gt;each new instance of component&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Component({
  selector:    'app-hero-list',
  templateUrl: './hero-list.component.html',
  providers:  [ HeroService ]
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;small&gt;Further reading in &lt;a href="https://angular.io/guide/singleton-services#ngmodule-providers-array" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Benefits of Dependency Injection &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Decouples class dependencies. &lt;br&gt;
can change dependencies of service class without changing code in all component classes. If instantiation of service class is in component, must change all the service instantiation code.&lt;/p&gt;

&lt;p&gt;i.e. just change arguments in service constructor. no need to change anywhere else&lt;/p&gt;
&lt;h3&gt;
  
  
  ng serve VS ng build  &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;ng serve&lt;/code&gt; - builds angular application in memory&lt;br&gt;
&lt;code&gt;ng build&lt;/code&gt; - builds application in harddisk. put all the compiled code in the &lt;code&gt;/dist&lt;/code&gt; folder&lt;/p&gt;
&lt;h3&gt;
  
  
  --prod flag? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;--prod&lt;/code&gt; flag ensures you build applciation for production. compresses JS files, removes comments. makes application ready for production.&lt;/p&gt;
&lt;h3&gt;
  
  
  Importance of component lifecycle? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;directives have lifecycle too&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;tldr;&lt;br&gt;
Developers can tap into key events of component lifecycle and write custom code by implementing &lt;em&gt;lifecycle hook&lt;/em&gt; interfaces. (eg. &lt;code&gt;ngOnInit()&lt;/code&gt;)&lt;br&gt;
&lt;small&gt; Greater details in &lt;a href="https://angular.io/guide/lifecycle-hooks" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

&lt;p&gt;Component instance has lifecycle when angular instantiates component class &amp;amp; renders component view till angular destroys component and removes rendered template from DOM.&lt;/p&gt;

&lt;p&gt;Dev can use lifecycle hook methods to tap into key events of lifecycle to init new instances / clean up before deletion of instances.&lt;/p&gt;
&lt;h3&gt;
  
  
  events &amp;amp; sequence of component life cycle? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Here is a great &lt;a href="https://nalawadeshivani98.medium.com/angular-lifecycle-d34c57bf147" rel="noopener noreferrer"&gt;medium article&lt;/a&gt; by Shivani that goes in-depth into the angular lifecycle.&lt;/p&gt;

&lt;p&gt;Angular Documentation offers list of &lt;a href="https://angular.io/guide/lifecycle-hooks#lifecycle-event-sequence" rel="noopener noreferrer"&gt;lifecycle event sequence&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Two types of events&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Events fired when component is first loaded&lt;/li&gt;
&lt;li&gt;Events fired on change detection&lt;/li&gt;
&lt;/ol&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%2F6fhai5vjf2ssnw6gmwog.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%2F6fhai5vjf2ssnw6gmwog.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;List of lifecycle events&lt;br&gt;
(events called ONCE are &lt;em&gt;italicized&lt;/em&gt;)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;constructor (more of a typescript event, not an angular event)&lt;/li&gt;
&lt;li&gt;ngOnChanges (also called when data bound input property &lt;code&gt;@Input&lt;/code&gt; changes). This event happens &lt;strong&gt;very frequently&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;ngOnInit&lt;/em&gt; (data bound properties displayed on screen / sets component's &lt;code&gt;@Input&lt;/code&gt; properties)&lt;/li&gt;
&lt;li&gt;ngDoCheck() (fires immediately after ngOnChanges() on every change detection run)&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;ngAfterContentInit&lt;/em&gt; (after Angular projects external content into component's view) related to &lt;code&gt;&amp;lt;ng-check&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;ngAfterContentCheck (check content projected)&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;ngAfterViewInit&lt;/em&gt; (after angular initializes component's views &amp;amp; child views)&lt;/li&gt;
&lt;li&gt;ngAfterViewChecked (after angular checks component's view &amp;amp; child views)&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;ngOnDestroy&lt;/em&gt; (cleanup before angular destroys component)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;u&gt; three parts &lt;/u&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;kick start event (change detection) (ngOninit, ngDoCheck)&lt;/li&gt;
&lt;li&gt;projected content event fires (ngAfterContentInit, ngAfterContentChecked)&lt;/li&gt;
&lt;li&gt;events of component view fires (ngAfterViewInit, ngAfterViewChecked)&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  constructor VS ngOnInit()? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;constructor - typescript concept, invoked by typescript&lt;/li&gt;
&lt;li&gt;ngOnInit - angular concept / event, invoked by angular framework&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Sequence:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;constructor is fire.&lt;/li&gt;
&lt;li&gt;view and component initialized, binding happens&lt;/li&gt;
&lt;li&gt;ngOnInit (after component is initializes, access to DOM elements)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;u&gt;Constructor:&lt;/u&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;initialize class variables&lt;/li&gt;
&lt;li&gt;dependency injection&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;u&gt;ngOnInit:&lt;/u&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;access to class variables&lt;/li&gt;
&lt;li&gt;access to &lt;code&gt;@Input&lt;/code&gt; variables&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Accessing, &lt;code&gt;@Input&lt;/code&gt; or from constructor will give &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;small&gt; More information in this &lt;a href="https://stackoverflow.com/a/48705981" rel="noopener noreferrer"&gt;SO answer&lt;/a&gt;&lt;/small&gt;&lt;br&gt;
&lt;small&gt; &lt;code&gt;@ViewChild&lt;/code&gt; only access in &lt;code&gt;ngAfterViewInit&lt;/code&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  ViewChild &amp;amp; ViewChildren &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;@ViewChild&lt;/code&gt; : Reference &lt;strong&gt;ONE&lt;/strong&gt; HTML element / DOM element in the component&lt;br&gt;
&lt;code&gt;@ViewChildren&lt;/code&gt;: Reference a collection of elements&lt;/p&gt;

&lt;p&gt;If multiple elements detected by &lt;code&gt;@ViewChild&lt;/code&gt;, it will only reference the first element.&lt;/p&gt;
&lt;h3&gt;
  
  
  Template Reference Variable &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Template variables help developer use data from one part of template in another part of template&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input #phone placeholder="phone number" /&amp;gt;

&amp;lt;!-- lots of other elements --&amp;gt;

&amp;lt;!-- phone refers to the input element; pass its `value` to an event handler --&amp;gt;
&amp;lt;button (click)="callPhone(phone.value)"&amp;gt;Call&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To use template reference variable with ViewChild&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div #div1&amp;gt; this div &amp;lt;/div&amp;gt;

@Viewchild('div1',{static: false}) div: ElementRef
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Further reading &lt;a href="https://angular.io/guide/template-reference-variables" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is content projection? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Projection: project HTML content / component content from parent to child. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;ng-content&amp;gt;&amp;lt;/ng-content&amp;gt;&lt;/code&gt;&lt;br&gt;
Allows you to insert a shadow DOM as Input to a component.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@Input&lt;/code&gt; only allows you to pass simple string / objects to components. &lt;code&gt;&amp;lt;ng-content&amp;gt;&lt;/code&gt; allows you to pass things HTML elements, another component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;app-component&amp;gt;
  &amp;lt;h1&amp;gt;Header&amp;lt;/h1&amp;gt;
  &amp;lt;p&amp;gt;paragraph&amp;lt;/p&amp;gt;
&amp;lt;/app-component&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt; Multi content projection: content projection slot&lt;/u&gt;&lt;br&gt;
GreetComponent&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container"&amp;gt;
  &amp;lt;ng-content&amp;gt; &amp;lt;/ng-content&amp;gt;
  &amp;lt;ng-content select="h1"&amp;gt;&amp;lt;/ng-content&amp;gt;
  &amp;lt;p&amp;gt;welcome text&amp;lt;/p&amp;gt;
  &amp;lt;ng-content select=".content"&amp;gt;&amp;lt;/ng-content&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Parent Content&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div&amp;gt;
  &amp;lt;greet&amp;gt;
    &amp;lt;h3&amp;gt; everything else &amp;lt;/h3&amp;gt;
    &amp;lt;h1&amp;gt; Header &amp;lt;/h1&amp;gt;
    &amp;lt;span class="content"&amp;gt; something &amp;lt;/span&amp;gt;
  &amp;lt;/greet&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;output after content projection is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div&amp;gt;
  &amp;lt;div class="container"&amp;gt;
    &amp;lt;h3&amp;gt; everything else &amp;lt;/h3&amp;gt;
    &amp;lt;h1&amp;gt; Header &amp;lt;/h1&amp;gt;
    &amp;lt;p&amp;gt;welcome text&amp;lt;/p&amp;gt;
    &amp;lt;span class="content"&amp;gt; something &amp;lt;/span&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://dzone.com/articles/simplifying-content-projection-in-angular#:~:text=Content%20projection%20allows%20you%20to,." rel="noopener noreferrer"&gt;reference&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Content Child &amp;amp; Content Children &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;access projected content&lt;/p&gt;

&lt;p&gt;CardComponent.html&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="card"&amp;gt;
   &amp;lt;ng-content select="header"&amp;gt;&amp;lt;/ng-content&amp;gt;
   &amp;lt;ng-content select="content"&amp;gt;&amp;lt;/ng-content&amp;gt;
   &amp;lt;ng-content select="footer"&amp;gt;&amp;lt;/ng-content&amp;gt;
&amp;lt;/div&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CardComponent.ts&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@ContentChild("header") cardContentHeader: ElementRef;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;ParentComponent.html&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;card&amp;gt;
  &amp;lt;header&amp;gt;&amp;lt;h1 #header&amp;gt;Angular&amp;lt;/h1&amp;gt;&amp;lt;/header&amp;gt;
  &amp;lt;content&amp;gt;One framework. Mobile &amp;amp; desktop.&amp;lt;/content&amp;gt;
  &amp;lt;footer&amp;gt;&amp;lt;b&amp;gt;Super-powered by Google &amp;lt;/b&amp;gt;&amp;lt;/footer&amp;gt;
&amp;lt;/card&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt;&lt;a href="https://www.tektutorialshub.com/angular/contentchild-and-contentchildren-in-angular/" rel="noopener noreferrer"&gt;tektutorialshub&lt;/a&gt; provides a concise write-up&lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Static flag &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;static is false as default behaviour.&lt;br&gt;
static is false because we would like query to be &lt;a href="https://www.tektutorialshub.com/angular/contentchild-and-contentchildren-in-angular/#static" rel="noopener noreferrer"&gt;resolved every change detection&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://angular.io/guide/static-query-migration#how-do-i-choose-which-static-flag-value-to-use-true-or-false" rel="noopener noreferrer"&gt;Angular documentation&lt;/a&gt; &amp;amp; &lt;a href="https://stackoverflow.com/a/56359612" rel="noopener noreferrer"&gt;SO&lt;/a&gt; describes the flag in greater details &lt;/p&gt;
&lt;h3&gt;
  
  
  ViewChild, ViewChildren, ContentChild, ContentChildren &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;ViewChild: access DOM elements from its &lt;strong&gt;own&lt;/strong&gt; view&lt;br&gt;
ContentChild: access DOM elements from &lt;strong&gt;another&lt;/strong&gt; view, access DOM elements projected by someone else&lt;br&gt;
(e.g. &lt;code&gt;@ContentChild&lt;/code&gt; is on CardComponent.ts, but the project content is from ParentComponent.html)&lt;/p&gt;

&lt;p&gt;ViewChildren: collection of ViewChild&lt;br&gt;
ContentChildren: collection of ContentChildren&lt;/p&gt;
&lt;h3&gt;
  
  
  Make HTTP calls in Angular &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;import HttpClient from &lt;code&gt;@angular/common/http&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;import HttpModule in Angular Module&lt;/li&gt;
&lt;li&gt;create HttpClient object via dependency injection &lt;code&gt;constructor(public http:HttpClient)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;make post / get class with HttpClient &lt;code&gt;this.http.post(URL, data).subscribe(res =&amp;gt; successfunc(res), err =&amp;gt; errfunc(err)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;subscribe to Http.post / Http.get. Subscribe takes 2 inputs: success function and error function&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Need of Subscribe function &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Provide success / error methods if HTTP calls are successful / fail. &lt;br&gt;
Also, if there is no async pipe, subscribe is needed for an observable to execute&lt;/p&gt;
&lt;h3&gt;
  
  
  Handling errors in HTTP calls &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;error callback of subscribe method&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;catchError&lt;/code&gt; function in pipe. (catchError must return a new observable or throw an error)
when throwing new error, error thrown will propate to subscriber
&lt;small&gt; More details on &lt;a href="https://www.tektutorialshub.com/angular/angular-catcherror/" rel="noopener noreferrer"&gt;tekturotials&lt;/a&gt; &lt;/small&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The second method achieves &lt;a href="https://stackoverflow.com/a/54790621" rel="noopener noreferrer"&gt;separation of concern&lt;/a&gt; in Angular&lt;br&gt;
Additionally,&lt;br&gt;
&lt;u&gt; Chaining multiple observables (one after another &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;catchError&lt;/code&gt; keeps observable alive. If inner observable has errors, outer observable will still continue (coz it received an observable)
&lt;u&gt; Combinging multiple observables (execute multiple observables) &lt;/u&gt;
&lt;/li&gt;
&lt;li&gt;allows arrays of observables to complete. Else if only 1 observable fail, all will fail, with &lt;code&gt;catchError&lt;/code&gt; it will allow observable to complete and emit something.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Pass Data between components &amp;amp; routes &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Parent Child component &lt;br&gt;
&lt;code&gt;@Input&lt;/code&gt; : Parent -&amp;gt; child&lt;br&gt;
&lt;code&gt;@Output&lt;/code&gt; : Child -&amp;gt; parent&lt;br&gt;
&lt;code&gt;@ViewChild&lt;/code&gt;: &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Data between routes -&amp;gt; Routing Query Params&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;this.route.navigate(['url'],
  {queryParams: {
    name: 'myname'
    }
   });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Services
&lt;strong&gt;more of global data / storing&lt;/strong&gt; 
more of &lt;strong&gt;sharing global data&lt;/strong&gt; via singleton service&lt;/li&gt;
&lt;li&gt;create service&lt;/li&gt;
&lt;li&gt;inject service into components&lt;/li&gt;
&lt;li&gt;&lt;p&gt;access service data &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Browser&lt;br&gt;
*&lt;em&gt;global data *&lt;/em&gt;&lt;br&gt;
Local Storage / temp storage &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Good practice to pass data using services &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Sharing data&lt;/strong&gt; VS &lt;strong&gt;passing data&lt;/strong&gt;&lt;br&gt;
If you are just passing data from one component to another, should avoid using service / global variables. &lt;br&gt;
Other components may modify global variables. Code can become quite messy.&lt;/p&gt;
&lt;h3&gt;
  
  
  What is the need for Angular Pipes? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Pipes transform data on Angular UI expressions&lt;br&gt;
Angular has some inbuilt pipes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;AsynPipe : read object from asynchronous source (impure by default)&lt;/li&gt;
&lt;li&gt;JsonPipe: convert object to json string&lt;/li&gt;
&lt;li&gt;KeyValuePipe: can use in ngFor to iterate keys and values of object&lt;/li&gt;
&lt;li&gt;DatePipe: fomat date&lt;/li&gt;
&lt;li&gt;CurrencyPipe: number -&amp;gt; currency string&lt;/li&gt;
&lt;/ol&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;p&amp;gt;The hero's birthday is {{ birthday | date:"MM/dd/yy" }} &amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also chain pipes (will implement first pipe then second pipe to the output of first pipe)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{ birthday | date | uppercase}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How to make custom pipes in Angular? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Use &lt;code&gt;@Pipe&lt;/code&gt; to mark class as a pipe&lt;/li&gt;
&lt;li&gt;Implement PipeTransform interface&lt;/li&gt;
&lt;li&gt;Implements transform method.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Pipe({name: 'uselessPipe'})
export class uselessPipe implements PipeTransform {
  transform(value: string, before: string, after: string): string {
    let newStr = `${before} ${value} ${after}`;
    return newStr;
  }
}

{{ user.name | uselessPipe:"Mr.":"the great" }}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Change detection in angular pipe. &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Data is primitive input value (string, number) OR object reference as input (Date / Array)&lt;br&gt;
Angular executes pipe whenever it detects change for the input value of reference &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Change something &lt;em&gt;inside&lt;/em&gt; a composite object (e.g. month of a date, element of array, object property)&lt;br&gt;
use &lt;code&gt;impure&lt;/code&gt; pipe&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;small&gt; Referenced from Angular &lt;a href="https://angular.io/guide/pipes#detecting-changes-with-data-binding-in-pipes" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Detecting pure changes to primitives and object references&lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Angular pipes are &lt;strong&gt;pure&lt;/strong&gt; by &lt;strong&gt;default&lt;/strong&gt;. Angular executes pipe only when it detects &lt;em&gt;pure change&lt;/em&gt; to input value. Pure change is either:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;change to pimitive input value (&lt;code&gt;string&lt;/code&gt;, &lt;code&gt;number&lt;/code&gt;, &lt;code&gt;boolean&lt;/code&gt;, &lt;code&gt;symbol&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;changed object reference (&lt;code&gt;Date&lt;/code&gt;, &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Function&lt;/code&gt;, &lt;code&gt;Object&lt;/code&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In Pure pipe, Angular ignore changes within component object (eg. new added elemtn of existing array) because object reference did not change. &lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div *ngFor="let hero of (heroes | flyingHeroes)"&amp;gt;
  {{hero.name}}
&amp;lt;/div&amp;gt;

@Pipe({ name: 'flyingHeroes' })
export class FlyingHeroesPipe implements PipeTransform {
  transform(allHeroes: Hero[]) {
    return allHeroes.filter(hero =&amp;gt; hero.canFly);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If user adds flying heroes, it will not be updated becuase &lt;em&gt;reference&lt;/em&gt; to the array has not changed so angular does not update display. there are two ways to cirucmvent this&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;change object reference
replace array with new array containing new changed elements, input new array to pipe.&lt;/li&gt;
&lt;li&gt;make pipe detect impure changes
set pure flag to false
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Pipe({
  name: 'flyingHeroesImpure',
  pure: false
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What is change detection &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Mechanism by which Angular sychronizes state of application UI with state of data&lt;/p&gt;

&lt;p&gt;When component data is updated (e.g. from user event/ application logic), values  bound to DOM properties in the view can change. The change detector is responsible for updating the view to reflect the current data model. &lt;/p&gt;

&lt;p&gt;&lt;small&gt; Reference: Angular &lt;a href="https://angular.io/guide/glossary#change-detection" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Synchronous VS Asynchronous &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Synchronous code is executed in sequence.&lt;br&gt;
When one statement is executing nothing else can happen.&lt;/p&gt;

&lt;p&gt;Asynchronous code doesn’t have to wait – your program can continue to run. &lt;br&gt;
Asynchronous code is hard to achieve in Synchronous JS, developer is unsure how long code will take to finish (how long will it take to download image from API?)&lt;br&gt;
So code 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;let response = fetch('myImage.png'); // fetch is asynchronous
let blob = response.blob();
// display your image blob in the UI somehow
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;blob may be undefined. &lt;br&gt;
Async JS has 2 main code styles:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;callbacks (old-styles)&lt;/li&gt;
&lt;li&gt;promise (new-style)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Async JS has two models: (&lt;small&gt; more details on &lt;a href="https://rxjs-dev.firebaseapp.com/guide/observable#pull-versus-push" rel="noopener noreferrer"&gt;RxJS&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Pull mode (consumer is king, consumer decides when it receives data from producer, producer is unaware when data will be delivered)&lt;/li&gt;
&lt;li&gt;Push model (producer is king, it determines when to send data to consumer)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Promises &amp;amp; observable follow the push model.&lt;br&gt;
Promise (producer) delivers resolved value to registered callbacks (consumer)&lt;/p&gt;

&lt;p&gt;&lt;small&gt; more information &lt;a href="https://rowanmanning.com/posts/javascript-for-beginners-async/#:~:text=In%20Summary,waiting%20time%20for%20the%20user." rel="noopener noreferrer"&gt;here&lt;/a&gt; and on &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Introducing" rel="noopener noreferrer"&gt;MDN&lt;/a&gt; &lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  What is RxJS? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;RxJS stands for &lt;strong&gt;Reactive Extensions for JavaScript&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is to &lt;em&gt;handle asynchronous data streams&lt;/em&gt;&lt;br&gt;
eg. async data source(HTTP data, timer) may take 1 second or 15 seconds to come. Then application should have listener&lt;br&gt;
(e.g. http response, data comes in small time intervals)&lt;/p&gt;

&lt;p&gt;RxJs helps you to handle asynchronous data streams easily.&lt;/p&gt;
&lt;h3&gt;
  
  
  What are Observables &amp;amp; observers? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Observable is a Push system for Javascript. It is a producer of multiple values "pushing" them to observers (consumers).&lt;/p&gt;

&lt;p&gt;Observable can give multiple values either synchronously or asynchronously. &lt;/p&gt;

&lt;p&gt;&lt;small&gt;this &lt;a href="https://www.freecodecamp.org/news/what-are-observables-how-they-are-different-from-promises/" rel="noopener noreferrer"&gt;freecodecamp&lt;/a&gt; article has a very comprehensive introduction &lt;/small&gt;&lt;/p&gt;

&lt;p&gt;Observable has &lt;a href="https://rxjs-dev.firebaseapp.com/guide/observable#anatomy-of-an-observable" rel="noopener noreferrer"&gt;4 main stages&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Creation&lt;/li&gt;
&lt;li&gt;Subscription&lt;/li&gt;
&lt;li&gt;Executing&lt;/li&gt;
&lt;li&gt;Disposing&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Importance of subscribe in RxJS &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Each call to &lt;code&gt;observable.subscribe&lt;/code&gt; triggers its own indepdendent set up for that given subscriber&lt;/em&gt;.&lt;br&gt;
&lt;a href="https://rxjs-dev.firebaseapp.com/guide/observable#subscribing-to-observables" rel="noopener noreferrer"&gt;RxJS&lt;/a&gt;: starts an "Observable execution" an deliver values / events to observer of execution.&lt;br&gt;
&lt;a href="https://angular.io/guide/observables#subscribing" rel="noopener noreferrer"&gt;Angular&lt;/a&gt;: Observable instance only begins publishing values when someone subscribes to it. &lt;/p&gt;
&lt;h3&gt;
  
  
  How to unsubscribe (Destroy phase of Observable) &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;small&gt; Taken from &lt;a href="https://rxjs-dev.firebaseapp.com/guide/observable#disposing-observable-executions" rel="noopener noreferrer"&gt;RxJS&lt;/a&gt; documentation &lt;/small&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const subscription = observable.subscribe(x =&amp;gt; console.log(x));
subscription.unsubscribe();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since Observable exeuctions may be infinite and its common for observer to abort execution in finitetime, we need API for cancelling execution. When execution is stopped / cancelled, we can avoid wasting computation power / memory resources. &lt;/p&gt;

&lt;h3&gt;
  
  
  Explain concept of operators with sample code &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Operators are functions.&lt;br&gt;
There are 2 types of operators:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Pipeable operator
takes in observable as input and output is also an observable.
pre-processing logic, can transform data in observable.&lt;/li&gt;
&lt;li&gt;creation operator
can be called as standalone functions to create new Observable&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;small&gt; Taken from &lt;a href="https://rxjs-dev.firebaseapp.com/guide/operators#creation-operators" rel="noopener noreferrer"&gt;RxJS&lt;/a&gt; documentation &lt;/small&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Algos - Complexity + Recursion</title>
      <dc:creator>limjy</dc:creator>
      <pubDate>Wed, 31 Mar 2021 11:54:58 +0000</pubDate>
      <link>https://dev.to/jing/algos-recursion-2db7</link>
      <guid>https://dev.to/jing/algos-recursion-2db7</guid>
      <description>&lt;p&gt;Summary for myself (from Leet Code explore card)&lt;/p&gt;

&lt;h1&gt;
  
  
  Analysis
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Asymptotic
&lt;/h2&gt;

&lt;p&gt;measure efficiency of function that dont depend on machine-specific constants&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Guess run time of function in relation to the input size &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Worst, Best, Average Case
&lt;/h2&gt;

&lt;p&gt;Average case. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;assumes all cases are uniformly distributed&lt;/li&gt;
&lt;li&gt;calculate expected value 
Eg. linear search. Average complexity ~ O(n/2) ~ O(n) &lt;a href="https://cs.stackexchange.com/a/80146"&gt;Full Explanation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;assume that input is uniformly distributed&lt;/li&gt;
&lt;li&gt;average case complexity = total number of comparisons made / number of inputs&lt;/li&gt;
&lt;li&gt;element found on index 0, index 1, index 2, ... , index n&lt;/li&gt;
&lt;li&gt;average complexity: 
= number of comparisons made / n
= 1 + 2 + 3 + ... + n / n
= (n* (n+1) /2 ) / n
= (n+1) / 2
~O(n/2)
~O(n)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Annotations
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Theta (Θ) Notation --&amp;gt; upper and lower bound. (best &amp;amp; worst case)&lt;/li&gt;
&lt;li&gt;Big O Notation --&amp;gt; upper bound (worst case)&lt;/li&gt;
&lt;li&gt;Omega (Ω) Notation --&amp;gt; lower bound (best case) &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Loops
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;O(1)&lt;/strong&gt;
no loop&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;O(n)&lt;/strong&gt;
loop, variable incremented by &lt;em&gt;constant&lt;/em&gt; amount
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (int i = 1; i &amp;lt;= n; i += c) {  
        // some O(1) expressions
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;O(n&lt;sup&gt;c&lt;/sup&gt;)&lt;/strong&gt;
nested loops. c being the layers of nesting.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (int i = n; i &amp;gt; 0; i -= c) {
       for (int j = i+1; j &amp;lt;=n; j += c) {
          // some O(1) expressions
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;O(log(n))&lt;/strong&gt; 
loop variables is divided / multiplied by a constant amount.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (int i = n; i &amp;gt; 0; i /= c) {
       // some O(1) expressions
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;O(log(log(n)))&lt;/strong&gt;
loop variables is reduced / increased exponentially by a constant amount.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (int i = 2; i &amp;lt;=n; i = pow(i, c)) { 
       // some O(1) expressions
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;**O(2&lt;sup&gt;2&lt;/sup&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;growth doubles with each addition to input data&lt;br&gt;
often recursive algorithms by solving two smaller sub problems of N-1  &lt;a href="https://stackoverflow.com/a/34916117"&gt;SO answer&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;O(n!)&lt;/strong&gt;
adding loop for every element
&lt;a href="https://stackoverflow.com/a/3953257"&gt;SO answer&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Recursion
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Recurrence Tree&lt;/li&gt;
&lt;li&gt;draw recurrence tree&lt;/li&gt;
&lt;li&gt;calculate time taken by every level of tree.&lt;/li&gt;
&lt;li&gt;Master Method
&lt;a href="https://towardsdatascience.com/the-detailed-guide-to-master-method-to-find-the-time-complexity-of-any-recursive-algorithm-b40c8250ed67"&gt;more details&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h1&gt;
  
  
  Recursion
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;function calls itself&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To &lt;strong&gt;avoid an infinite loop&lt;/strong&gt;: rmb to have base case&lt;/p&gt;

&lt;p&gt;Recursion functions usually consist of 3 parts&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;base case&lt;/code&gt; — terminating scenario that does not use recursion to produce an answer.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;recurrence relation&lt;/code&gt; — set of rules that reduces all other cases towards the base case.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;return&lt;/code&gt; - rmb to return things. usually there are two return statements one for base case and one for the recurrence relation.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In recursion, functions will get closer and closer to base case. When base case, function returns, and previous function calls are popped off the stack. If recurrence relation is not "returned" nothing is "returned" return type is void.&lt;/p&gt;
&lt;h1&gt;
  
  
  Complexity
&lt;/h1&gt;

&lt;p&gt;This &lt;a href="https://stackoverflow.com/a/13467808"&gt;SO answer&lt;/a&gt; provides a quick analysis of time complexities of different recursion functions &lt;/p&gt;
&lt;h1&gt;
  
  
  Dyanmic Programming
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;Basically caching. Break problems down into sub problems.&lt;br&gt;
Solve sub-problems only once and store their solution&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;can be divided into subproblems?&lt;/li&gt;
&lt;li&gt;recursive solution&lt;/li&gt;
&lt;li&gt;repetitive subproblems (like fibionacci, subproblems done over an over again) (use caching -&amp;gt; DP)&lt;/li&gt;
&lt;li&gt;memoize subproblem&lt;/li&gt;
&lt;/ol&gt;
&lt;h1&gt;
  
  
  Memoization / Opti (Dynamic Programming)
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;optimize recursion problems by storing / caching previous functions. Preventing duplicate calls.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Eg. Fibionacci  &lt;code&gt;f(n)  = f(n-1) + f(n-2)&lt;/code&gt;&lt;br&gt;
In Fibionacci there can be multiple duplicate calls. (see below, duplicate calls are coloured same colour)&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hREwy7aH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j62de1r7oyddj9v30es8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hREwy7aH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j62de1r7oyddj9v30es8.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Complexity
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.ideserve.co.in/learn/time-and-space-complexity-of-recursive-algorithms"&gt;Article&lt;/a&gt; provides more explanation&lt;/p&gt;
&lt;h2&gt;
  
  
  Time Complexity
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Linear
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Time Complexity = number of recursion invocations (&lt;code&gt;R&lt;/code&gt;) and time complexity of 1 recursion call (&lt;code&gt;O(s)&lt;/code&gt;)&lt;br&gt;
Time Complexity = &lt;code&gt;R&lt;/code&gt; * &lt;code&gt;O(s)&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt;Example: Reverse String&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;printReverse(str) = printReverse(str[1...n]) + print(str[0])&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Number of invocations = &lt;code&gt;N&lt;/code&gt; (length of string)&lt;br&gt;
Complexity of 1 invocation = &lt;code&gt;O(1)&lt;/code&gt;&lt;br&gt;
Therefore, time complexity = &lt;code&gt;N * O(1)&lt;/code&gt; = &lt;code&gt;O(N)&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Execution Tree
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Node = invocation of function. Therefore, number of invocations = number of nodes in tree (Ntree)&lt;br&gt;
Time Complexity = number of nodes in tree (Ntree) * complexity of 1 invocation (O(s))&lt;br&gt;
Time Complexity = &lt;em&gt;Ntree&lt;/em&gt; * &lt;code&gt;O(s)&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This can also be used for linear. In linear, all nodes have 1 child and the number of nodes is the height of the tree.&lt;/p&gt;

&lt;p&gt;The execution tree of recursion function will form an &lt;strong&gt;n-aray&lt;/strong&gt; tree where &lt;em&gt;n&lt;/em&gt; is the number of times recursion function appears in recursion relation&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Example: Fibonacci&lt;/u&gt;&lt;br&gt;
&lt;code&gt;f(n) = f(n-1) + f(n-2)&lt;/code&gt;&lt;br&gt;
recursion function appears twice in recursion relation. Therefore, execution tree is a binary tree.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hWceXqe2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ska3sh785zomeyq14x6y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hWceXqe2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ska3sh785zomeyq14x6y.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
Height of binary tree is N.&lt;br&gt;
Number of nodes  = number of nodes in binary tree of height N&lt;br&gt;
= 2&lt;sup&gt;0&lt;/sup&gt; + 2&lt;sup&gt;1&lt;/sup&gt; + 2&lt;sup&gt;2&lt;/sup&gt; + ... + 2&lt;sup&gt;N-1&lt;/sup&gt;&lt;br&gt;
 = 2 &lt;sup&gt;N&lt;/sup&gt; -1&lt;br&gt;
~ O(2&lt;sup&gt;N&lt;/sup&gt;)&lt;/p&gt;

&lt;p&gt;Therefore, time complexity &lt;br&gt;
= nodes in execution tree * complexity of 1 invocation&lt;br&gt;
 = O(2&lt;sup&gt;N&lt;/sup&gt;) * 1&lt;br&gt;
= O(2&lt;sup&gt;N&lt;/sup&gt;)&lt;/p&gt;
&lt;h3&gt;
  
  
  After Memoization
&lt;/h3&gt;

&lt;p&gt;As mentioned previously, memoization optimizes complexity of recursion by minimizing duplicate calls. (i.e. &lt;strong&gt;reducing the number of children in the execution tree&lt;/strong&gt;)&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Example: Fibonacci&lt;/u&gt;&lt;br&gt;
After memoization, duplicate calls are reduced. So&lt;br&gt;
&lt;code&gt;f(n) = f(n-1) + f(n-2)&lt;/code&gt; would now become &lt;br&gt;
&lt;code&gt;f(n) = f(n-1) + cache(n-2)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;This is because result of &lt;code&gt;f(n-2)&lt;/code&gt; would have been calculated in the previous invocation call &lt;code&gt;f(n-1)&lt;/code&gt; where &lt;code&gt;f(n-1) = f(n-2) + cache(n-3)&lt;/code&gt;&lt;br&gt;
In optimized fibonacci, only &lt;code&gt;f(n-1)&lt;/code&gt; must be calculated for calculation of &lt;code&gt;f(n)&lt;/code&gt;. &lt;code&gt;f(n-2)&lt;/code&gt; is stored in cache. retrieving it from cache (hashmap) is constant operation. &lt;/small&gt;&lt;/p&gt;

&lt;p&gt;Fibonacci = &lt;code&gt;f(n) = f(n-1) + cache(n-2)&lt;/code&gt;&lt;br&gt;
Recursion function only calls itself once. Nodes in Execution tree has 1 child. Recursion to calculate &lt;code&gt;f(n)&lt;/code&gt; will be invoked &lt;code&gt;f(n-1)&lt;/code&gt; times. &lt;/p&gt;

&lt;p&gt;Time complexity&lt;br&gt;
= Number of nodes in execution tree * complexity of 1 function call&lt;br&gt;
= Height of execution tree * Complexity of 1 function call&lt;br&gt;
= &lt;code&gt;O(N)&lt;/code&gt; + &lt;code&gt;O(1)&lt;/code&gt;&lt;br&gt;
= &lt;code&gt;O(N)&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Space Complexity
&lt;/h2&gt;

&lt;p&gt;Space complexity of recursion has 2 main components.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;recursion related&lt;/li&gt;
&lt;li&gt;non-recursion related&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Recursion related
&lt;/h3&gt;

&lt;p&gt;For normal function calls, space on stack is freed when function is returned. However in recursive functions, function (f2) calls another function (f1), so both functions are stored in stack. In recursive functions, functions will all be stored in stack until base case is base case is reached.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qclwCKOR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pge3brs2wt707toeyjln.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qclwCKOR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pge3brs2wt707toeyjln.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Space complexity = maximum depth of recursion tree&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4&gt;
  
  
  Stack Overflow
&lt;/h4&gt;

&lt;p&gt;If stack allocated for program reaches maximum limit, program crashes. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Space complexity of recursion = Height of execution tree.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  Non-recursion related
&lt;/h3&gt;

&lt;p&gt;Space not directly relation to recursion. Eg.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;storing global variables&lt;/li&gt;
&lt;li&gt;saving intermediate result from recursion calls. (e.g. menoization: space complexity of hashmap from storing function call results)&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Tail Recursion
&lt;/h3&gt;

&lt;p&gt;** Java &lt;a href="https://stackoverflow.com/a/22866602"&gt;does not&lt;/a&gt; support tail recursion / tail call optimization&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;function is tail recursive if recursive call is last thing executed by function&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This &lt;a href="https://stackoverflow.com/a/37010"&gt;stackoverflow answer&lt;/a&gt; provides better details.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// non-tail recursive
function recsum(x) {
    if (x === 1) {
        return x;
    } else {
// non-tail because it does computation + recursive call
        return x + recsum(x - 1);
    }
}
// output
recsum(3)
3 + recsum(2)
3 + (2 + recsum(1))
3 + (2 + 1)
6

function tailrecsum(x, running_total = 0) {
    if (x === 0) {
        return running_total;
    } else {
// tail. only calls recursive function
        return tailrecsum(x - 1, running_total + x);
    }
}
// output
tailrecsum(3,0)
tailrecsum(2,3)
tailrecsum(1,5)
tailrecsum(0,6)
6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In tail recursive call, space is saved because, stack does not have to save space for every function call. Space is just "reused"&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0MeAI9zQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zwujlvbaht6kutm6s0yo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0MeAI9zQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zwujlvbaht6kutm6s0yo.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
Stack allocated space for f(x1) to call f(x2). Then f(x2) will call f(x3). however stack wont have to allocate new space for f(x2) it will just "reuse" the space if allocated for f(x1).&lt;br&gt;
 &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--o_MsdSam--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q4fx1f5qx9929oo7ll7v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--o_MsdSam--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q4fx1f5qx9929oo7ll7v.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;** Tail recursion calls can be executed as non-tail recursive functions** i.e. un-optimized stack space is used. This depends on programming language. Java and Python DO NOT support tail call optimization &lt;br&gt;
Javascript ???&lt;/p&gt;

&lt;h2&gt;
  
  
  Recursive VS Iterative
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Readable&lt;/strong&gt;: don't really have to repeat yourself.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Large Stack&lt;/strong&gt;: large stack call. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;useful for traversal.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to use recursion
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;using a tree / convergin something into a tree&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Can Divide &amp;amp; conquer using recursion &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Divided into number of sub problems that are smaller instances of same problem&lt;/li&gt;
&lt;li&gt;each instance of sub problem is identical in nature&lt;/li&gt;
&lt;li&gt;solution of each sub problem can be combined to solve problem at hand. &lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Sorting
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Bubble Sort&lt;/li&gt;
&lt;li&gt;Insertion Sort&lt;/li&gt;
&lt;li&gt;Selection Sort&lt;/li&gt;
&lt;li&gt;Merge Sort&lt;/li&gt;
&lt;li&gt;Quick Sort&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  sort()
&lt;/h2&gt;

&lt;p&gt;JS: under the hood, JS sorts list of numbers like string.&lt;br&gt;
[1,2,35,67,7,8]&lt;br&gt;
[1,34,65,7,2,8] -- &amp;gt; [1,2,34,65,7,8]&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Data Structure - Binary Tree</title>
      <dc:creator>limjy</dc:creator>
      <pubDate>Fri, 26 Mar 2021 16:53:41 +0000</pubDate>
      <link>https://dev.to/jing/data-structure-tree-1gjn</link>
      <guid>https://dev.to/jing/data-structure-tree-1gjn</guid>
      <description>&lt;p&gt;My summary of Leet Code [Binary Tree explore card](&lt;a href="https://leetcode.com/explore/learn/card/data-structure-tree" rel="noopener noreferrer"&gt;https://leetcode.com/explore/learn/card/data-structure-tree&lt;/a&gt; Also using GeeksforGeeks &lt;a href="https://www.geeksforgeeks.org/binary-tree-data-structure/" rel="noopener noreferrer"&gt;Binary Tree articles&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Tree
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;Each node of tree has root value and list of references to other nodes (called child nodes)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;From a graph point of view&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;directed acyclic graph which has N nodes and N-1 edges.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Binary Tree
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;tree structure where each node has at most two children. (left child &amp;amp; right child)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Traversing a Tree
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Pre-order (root, left, right)&lt;/li&gt;
&lt;li&gt;In-order (left, root, right)&lt;/li&gt;
&lt;li&gt;Post-order (left, right, root)&lt;/li&gt;
&lt;li&gt;level-order traversal&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This &lt;a href="https://towardsdatascience.com/4-types-of-tree-traversal-algorithms-d56328450846" rel="noopener noreferrer"&gt;article&lt;/a&gt; provides a great overview of tree traversals and how they relate to BFS / DFS&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Pre-Order Traversal
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;visit root&lt;/li&gt;
&lt;li&gt;visit left sub tree&lt;/li&gt;
&lt;li&gt;visit right sub tree&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;(root first, then left right children)&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%2Fuploads%2Farticles%2Fsnem2prtcyx7wlh0nevq.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%2Fsnem2prtcyx7wlh0nevq.png" alt="alt text"&gt;&lt;/a&gt;&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%2Fuploads%2Farticles%2Fhcgixpwtwvwcbtub18py.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%2Fhcgixpwtwvwcbtub18py.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Applications
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;used to create copy of a tree. &lt;/li&gt;
&lt;li&gt;get prefix expression of an expression tree. (e.g. Polish notation)
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution{
    ArrayList&amp;lt;Integer&amp;gt; result = new ArrayList&amp;lt;&amp;gt;();
    ArrayList&amp;lt;Integer&amp;gt; preorder(Node root) {
        if (root != null) {
            result.add(root.data);
        }
        if (root != null &amp;amp;&amp;amp; root.left != null) {
            result.add(root.left);
        }
        if (root != null &amp;amp;&amp;amp; root.right != null) {
            result.add(root.right);
        }
        return result;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  2. Post-order Traversal
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;visit left sub tree&lt;/li&gt;
&lt;li&gt;visit right sub tree&lt;/li&gt;
&lt;li&gt;visit root&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;(children left,right first, then root) &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%2Fuploads%2Farticles%2F5pviogethigi7egs78bm.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%2F5pviogethigi7egs78bm.png" alt="alt text"&gt;&lt;/a&gt;&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%2Fuploads%2Farticles%2F4kax0ul8c0otw3vqaxvb.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%2F4kax0ul8c0otw3vqaxvb.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Applications
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;delete tree&lt;/li&gt;
&lt;li&gt;get postfix expressions (e.g. reverse polish notation)
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Tree {   
    ArrayList&amp;lt;Integer&amp;gt; result = new ArrayList&amp;lt;&amp;gt;();
    ArrayList&amp;lt;Integer&amp;gt; postOrder(Node root) {
       if (root != null &amp;amp;&amp;amp; root.left!=null) {
            postOrder(root.left);
        }
        if (root != null &amp;amp;&amp;amp; root.right!= null) {
            postOrder(root.right);
        }
        if (root != null) {
            result.add(root.data);
        }
        return result;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  3. In-order Traversal
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;visit left subtree&lt;/li&gt;
&lt;li&gt;visit root&lt;/li&gt;
&lt;li&gt;visit right subtree&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;(left -&amp;gt; right, left root right)&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%2F61l8z23tpdtu49grie1e.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%2F61l8z23tpdtu49grie1e.png" alt="alt text"&gt;&lt;/a&gt;&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%2Fuploads%2Farticles%2F3tiu3t86ckykanktvxqs.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%2F3tiu3t86ckykanktvxqs.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Applications
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;in BST, inorder traversal gives nodes in non-decreasing order.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
    ArrayList&amp;lt;Integer&amp;gt; result = new ArrayList&amp;lt;&amp;gt;();
    ArrayList&amp;lt;Integer&amp;gt; inOrder(Node root)
    {
        if (root != null &amp;amp;&amp;amp; root.left!= null) {
            inOrder(root.left);
        }
        if (root != null) {
            result.add(root.data);
        }
        if (root != null &amp;amp;&amp;amp; root.right!=null) {
            inOrder(root.right);
        }
        return result;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  4. Level order tarversal
&lt;/h3&gt;

&lt;p&gt;traverse tree by level&lt;/p&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;visit root node&lt;/li&gt;
&lt;li&gt;visit children of root node&lt;/li&gt;
&lt;li&gt;visit children of children of root node&lt;/li&gt;
&lt;li&gt;continue till leaf nodes &lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&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%2Fxw20fj57l8urf7harrvo.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%2Fxw20fj57l8urf7harrvo.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Applications
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;BFS&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Traversal - Complexity
&lt;/h3&gt;

&lt;p&gt;Time complexity: &lt;code&gt;O(1)&lt;/code&gt;&lt;br&gt;
Space Complexity: (consider size of stack for function calls)&lt;br&gt;
Worst: &lt;code&gt;O(N)&lt;/code&gt; (skewed tree)&lt;br&gt;
Best: &lt;code&gt;O(log(n))&lt;/code&gt; (balanced tree)&lt;/p&gt;
&lt;h1&gt;
  
  
  Properties
&lt;/h1&gt;
&lt;h4&gt;
  
  
  1. maximum number of nodes at height  &lt;em&gt;h&lt;/em&gt; is 2&lt;sup&gt;h&lt;/sup&gt;
&lt;/h4&gt;

&lt;p&gt;level of root = 0&lt;br&gt;
For root, h=0 and number of nodes is 2&lt;sup&gt;0&lt;/sup&gt; = 1&lt;br&gt;
Therefore number of nodes when h = &lt;em&gt;h&lt;/em&gt; is 2&lt;sup&gt;h&lt;/sup&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  2. Maximum number of nodes in a BINARY tree of height &lt;em&gt;h&lt;/em&gt; is 2&lt;sup&gt;h&lt;/sup&gt; – 1.
&lt;/h4&gt;

&lt;p&gt;In binary tree node can only have at most two children.&lt;br&gt;
keep in mind that height index of root is 0. But height &lt;em&gt;h&lt;/em&gt; refers to the number of nodes from root to leaf. Therefore leaf nodes have height index of &lt;em&gt;h-1&lt;/em&gt;. (something like array indexes VS array length)&lt;br&gt;
So total number of nodes in tree is &lt;br&gt;
= 2&lt;sup&gt;0&lt;/sup&gt; + 2&lt;sup&gt;1&lt;/sup&gt; + 2&lt;sup&gt;2&lt;/sup&gt; + ... + 2&lt;sup&gt;h-1&lt;/sup&gt;&lt;br&gt;
 = 1 + 2 + 4 + ... + 2&lt;sup&gt;h-1&lt;/sup&gt;&lt;br&gt;
 = 2 &lt;sup&gt;h&lt;/sup&gt; - 1 (geometric series)&lt;/p&gt;

&lt;p&gt;Mathematical proof for last line:&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%2Fuploads%2Farticles%2Fjhwmy2ri3mp676gspuvt.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%2Fjhwmy2ri3mp676gspuvt.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  3. In BINARY tree with N nodes, minimum possible height is log2(N+1).
&lt;/h4&gt;

&lt;p&gt;Using point above we know that &lt;br&gt;
2&lt;sup&gt;h&lt;/sup&gt; - 1 = N&lt;br&gt;
2&lt;sup&gt;h&lt;/sup&gt; = N + 1&lt;br&gt;
h = log2(N+1)&lt;/p&gt;

&lt;p&gt;In Big O notation this is usually expressed as &lt;strong&gt;O(log(n))&lt;/strong&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  4. BINARY Tree with L leaves has at least |log2L|+ 1 levels
&lt;/h4&gt;

&lt;p&gt;From point 1 we know that the number of leaf nodes are 2&lt;sup&gt;h-1&lt;/sup&gt;.&lt;br&gt;
2&lt;sup&gt;h-1&lt;/sup&gt; = L&lt;br&gt;
log2L = h - 1 &lt;br&gt;
h = log2(L) + 1 &lt;/p&gt;
&lt;h4&gt;
  
  
  5. In a full binary tree, the number of leaf nodes is always one more than nodes with two children.
&lt;/h4&gt;

&lt;p&gt;more &lt;a href="https://www.geeksforgeeks.org/handshaking-lemma-and-interesting-tree-properties/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Binary Tree Types
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Full Binary Tree&lt;/li&gt;
&lt;li&gt;Complete Binary Tree&lt;/li&gt;
&lt;li&gt;Perfect Binary Tree&lt;/li&gt;
&lt;li&gt;Balanced Binary Tree&lt;/li&gt;
&lt;li&gt;Degenerate / pathological tree&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This &lt;a href="https://www.upgrad.com/blog/5-types-of-binary-tree/" rel="noopener noreferrer"&gt;article&lt;/a&gt; gives a good description of each type of binary trees. and this &lt;a href="https://towardsdatascience.com/5-types-of-binary-tree-with-cool-illustrations-9b335c430254" rel="noopener noreferrer"&gt;article&lt;/a&gt; gives good illustrations of valid/ invalid types of binary treees. &lt;/p&gt;
&lt;h3&gt;
  
  
  1. Full Binary Tree
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;every node has either 0 or 2 children &lt;/p&gt;
&lt;/blockquote&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%2Fhnhxtma1t2w8u6ycm5ky.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%2Fhnhxtma1t2w8u6ycm5ky.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
Here the number of leaf nodes (no children)  = number of internal nodes (2 children) + 1 &lt;/p&gt;
&lt;h3&gt;
  
  
  2. Complete Binary Tree
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;All the levels are completely filled except the last level (level of height &lt;em&gt;h&lt;/em&gt;) &amp;amp; last level has all keys as left as possible &lt;/p&gt;
&lt;/blockquote&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%2Fcztu1d1vj90dooqhe0xg.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%2Fcztu1d1vj90dooqhe0xg.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Perfect Binary Tree
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;all the internal nodes have two children and all leaf nodes are at the same level. &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%2Fuploads%2Farticles%2F0c9a0yf84dobkuzsxtvi.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%2F0c9a0yf84dobkuzsxtvi.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here, number of leaf nodes  = number of internal nodes + 1.&lt;br&gt;
In perfect binary tree, number of nodes is maximum number of nodes 2&lt;sup&gt;h&lt;/sup&gt; +1 &lt;/p&gt;
&lt;h3&gt;
  
  
  4. Balanced Binary Tree
&lt;/h3&gt;

&lt;p&gt;Binary tree that is height balanced&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;left and right subtrees of &lt;strong&gt;every&lt;/strong&gt; node differ in height by no more than 1.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;left and right subtrees' heights differ by at most one, AND&lt;/li&gt;
&lt;li&gt;The left subtree is balanced, AND&lt;/li&gt;
&lt;li&gt;The right subtree is balanced&lt;/li&gt;
&lt;/ol&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%2F5gx8qypnknr3oah8h731.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%2F5gx8qypnknr3oah8h731.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
In balanced tree, height is O(log(n))&lt;/p&gt;
&lt;h3&gt;
  
  
  5. Degenerate / pathological tree
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;every parent node has 1 child&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;behaves like linked list&lt;/li&gt;
&lt;li&gt;height is n&lt;/li&gt;
&lt;li&gt;worst case complexity basically super cursed 
&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%2Fzo0d2jwq1ozxegnistqo.png" alt="alt text"&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
  
  
  Binary Search Tree
&lt;/h1&gt;

&lt;p&gt;Summary from LeetCode &lt;a href="https://leetcode.com/explore/learn/card/introduction-to-data-structure-binary-search-tree/" rel="noopener noreferrer"&gt;Explore Card&lt;/a&gt;&lt;br&gt;
Its a binary tree satisfying binary search property&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;special form of binary tree where: value in is node must be&lt;br&gt;
greater than (or equal to) any values in its left subtree &lt;strong&gt;AND&lt;/strong&gt; &lt;br&gt;
less than (or equal to) any values in its right subtree.&lt;/p&gt;
&lt;/blockquote&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%2Fophyioerlb6lu3feuxew.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%2Fophyioerlb6lu3feuxew.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Traversal
&lt;/h2&gt;

&lt;p&gt;same as binary tree only that:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;inorder traversal = ascending order &lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Search
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;For each node:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;if target value == node vale return the node &lt;/li&gt;
&lt;li&gt;if target value &amp;lt; node value search in left subtree&lt;/li&gt;
&lt;li&gt;if target value &amp;gt; node value search in right subtree&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&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%2F2da0ecg54n47uag4dlzu.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%2F2da0ecg54n47uag4dlzu.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Search - Recursive
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public TreeNode searchBST(TreeNode root, int val) {
        if (root == null) {
            return null;
        } else {
            if (root.val == val) {
                return root;
            } else if ( root.val &amp;gt; val ) {
                return searchBST(root.left, val);
            } else {
                // root.val &amp;lt; val
                return searchBST(root.right, val);
            }
        }              
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;u&gt;Time Complexity &lt;/u&gt;&lt;br&gt;
time complexity is O(h) where h is height of binary tree&lt;br&gt;
Height Balanced: &lt;code&gt;O(log(n))&lt;/code&gt; &lt;br&gt;
Height Skewed: &lt;code&gt;O(n)&lt;/code&gt; (n is the number of nodes in tree)&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Space Complexity&lt;/u&gt;&lt;br&gt;
More details in stack &lt;a href="https://stackoverflow.com/a/62604136" rel="noopener noreferrer"&gt;overflow answer&lt;/a&gt;&lt;br&gt;
Space complexity of tree: &lt;code&gt;O(n)&lt;/code&gt;&lt;br&gt;
Space complexity of recursive function is the height of the stack which would be the height of the binary tree.&lt;br&gt;
Height Balanced: &lt;code&gt;O(log(n))&lt;/code&gt;&lt;br&gt;
Height Skewed: &lt;code&gt;O(n)&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Search - Iterative
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public TreeNode searchBST(TreeNode root, int val) {
    TreeNode init = root;
    while (init != null) {
        if (init.val == val) {
            return init;
        } else if (init.val &amp;gt; val) {
            init = init.left;
        } else {
            init = init.right;
        }
    }
    return init;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;u&gt; Time Complexity &lt;u&gt;&lt;/u&gt;&lt;br&gt;
Height Balanced: &lt;code&gt;O(log(n))&lt;/code&gt;&lt;br&gt;
Height Skewed: &lt;code&gt;O(n)&lt;/code&gt;&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Space Complexity&lt;u&gt;&lt;/u&gt;&lt;br&gt;
space complexity of tree: &lt;code&gt;O(n)&lt;/code&gt;&lt;br&gt;
Auxillary space complexity: &lt;code&gt;O(1)&lt;/code&gt;&lt;/u&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Insert
&lt;/h2&gt;

&lt;p&gt;Find proper leaf position for target node and insert node as a leaf.&lt;/p&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;search left or right subtrees (if node.value &amp;gt; target or node.value &amp;lt; target)&lt;/li&gt;
&lt;li&gt;repeat step1 until reach a leaf node&lt;/li&gt;
&lt;li&gt;add new node as its left / right child &lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&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%2Fc1gu025p8x0yga1modxs.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%2Fc1gu025p8x0yga1modxs.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Insert - Recursive
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public TreeNode insertIntoBST(TreeNode root, int val) {
        if (root == null) {
            return new TreeNode(val);
        } else {
            return insert(root, root, val);
        }

    }

    public TreeNode insert(TreeNode root, TreeNode current, int val) {
        if (current.val &amp;lt; val &amp;amp;&amp;amp; current.right != null) {
            return insert(root, current.right, val);
        } else if (current.val &amp;lt; val &amp;amp;&amp;amp; current.right == null) {
            current.right = new TreeNode(val);
            return root;
        } else if (current.val &amp;gt; val &amp;amp;&amp;amp; current.left !=null) {
            return insert(root, current.left, val);
        } else { // root.val &amp;gt; vall &amp;amp;&amp;amp; root.left==null
            current.left = new TreeNode(val);
            return root;
        }

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

&lt;/div&gt;


&lt;p&gt;&lt;u&gt;Time Complexity &lt;u&gt;&lt;/u&gt;&lt;br&gt;
Time complexity will be proportional to height.&lt;br&gt;
Height Balanced: &lt;code&gt;O(log(n))&lt;/code&gt;&lt;br&gt;
Height Skewed: &lt;code&gt;O(n)&lt;/code&gt;&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Auxillary Space Complexity&lt;/u&gt;&lt;br&gt;
Height of recursion stack ~ height of BST&lt;br&gt;
Height balanced: &lt;code&gt;O(log(n))&lt;/code&gt;&lt;br&gt;
Height Skewed: &lt;code&gt;O(n)&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Insert - Iterative
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Node insert(Node root, int Key) {
    Node init = root;
    while (true) {
        if (init.data == Key) {
            break;
        } else {
            if (init.data &amp;lt; Key) {
                if (init.right != null) {
                    init = init.right;
                } else {
                    // init.right == null
                    init.right = new Node(Key);
                    break;
                }
            } else {
                // init.val &amp;gt; Key
                if (init.left != null) {
                    init = init.left;
                } else {
                    init.left = new Node(Key);
                    break;
                }
            }
        }
    }
    return root;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;u&gt; Time Complexity &lt;/u&gt;&lt;br&gt;
Traversing BST. proportional to height of BST&lt;br&gt;
Height Balanced: &lt;code&gt;O(log(n))&lt;/code&gt;&lt;br&gt;
Height Skewed: &lt;code&gt;O(n)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Auxillary Space Complexity&lt;/u&gt;&lt;br&gt;
Store current node. constant space&lt;br&gt;
Complexity: &lt;code&gt;O(1)&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Deletion
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;target node has &lt;strong&gt;no child&lt;/strong&gt;: remove the node.&lt;/li&gt;
&lt;li&gt;target node has &lt;strong&gt;one child&lt;/strong&gt;: use child to replace itself.&lt;/li&gt;
&lt;li&gt;target node has &lt;strong&gt;two children&lt;/strong&gt;: replace the node with its in-order successor  / predecessor &amp;amp; and delete target node.&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;In-order successor: smallest node in right subtree&lt;br&gt;
In-Order predecessor: biggest node in left subtree&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%2Fk2xz5v7oj00xf0yjqhhq.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%2Fk2xz5v7oj00xf0yjqhhq.png" alt="alt text"&gt;&lt;/a&gt;&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%2Fvdia9mbhr3j6m861959p.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%2Fvdia9mbhr3j6m861959p.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Tree {
    // Return the root of the modified BST after deleting the node with value X
    public static Node deleteNode(Node root, int X){
        // code here.
        Node pre = null;
        Node toDelete = root;
        while (toDelete != null &amp;amp;&amp;amp; toDelete.data != X) {
            pre = toDelete;
            if (toDelete.data &amp;lt; X) {
                toDelete = toDelete.right;
            } else {
                toDelete = toDelete.left;
            }
        }
        if (toDelete == null) {
            // node not found
            return root;
        } else {
           // delete node
           if (toDelete.left == null &amp;amp;&amp;amp; toDelete.right ==null) {
               // no children
               if (pre == null) {
                   return null;
               } else {
                   if (pre.left == toDelete) {
                       pre.left = null;
                   } else {
                       pre.right = null;
                   }
               }

           } else if (toDelete.left != null &amp;amp;&amp;amp; toDelete.right != null) {
               // two children
               // inorder successor (smallest number in right subtree)
               Node preSucc = toDelete;
               Node successor = toDelete.right;
               while (successor.left != null) {
                   preSucc = successor;
                   successor = successor.left;
               }
               toDelete.data = successor.data;
               if (preSucc.left == successor) {
                   preSucc.left = null;
               } else {
                   preSucc.right = null;
               }
           } else {
               // onyl 1 child
               Node child = null;
               if (toDelete.left == null) {
                   child = toDelete.right;
               } else {
                   child = toDelete.left;
               }
               if (pre.left == toDelete) {
                   pre.left = child;
               } else {
                   pre.right = child;
               }
           }
        }
        return root;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Self-balancing Binary tree
&lt;/h1&gt;

&lt;h2&gt;
  
  
  1. AVL Tree
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;left subtree &amp;amp; right subtree height diff &amp;lt;= 1&lt;br&gt;
After insert, if height difference &amp;gt; 1, rotations are performed to balance tree&lt;/p&gt;
&lt;/blockquote&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%2Fnhujkh068miwnmt2yffk.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%2Fnhujkh068miwnmt2yffk.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Red-Black Tree
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;each node painted red or black. &lt;/li&gt;
&lt;li&gt;root of tree is always black&lt;/li&gt;
&lt;li&gt;red node cannot have red parent or red child&lt;/li&gt;
&lt;li&gt;every path from node (incl. root) to any of the NULL nodes have same number of black nodes&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;balances by ensuring that a chai of 3 nodes never gets to form. &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%2Fuploads%2Farticles%2Fjtmgqixlv9jwhfv3n060.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%2Fjtmgqixlv9jwhfv3n060.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Info from: &lt;a href="https://stackoverflow.com/a/23277366" rel="noopener noreferrer"&gt;SO&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AVL more rigidly balanced -&amp;gt; provide faster look ups&lt;/li&gt;
&lt;li&gt;Insert intensive tasks -&amp;gt; red-black&lt;/li&gt;
&lt;li&gt;AVL may take more space. AVL store balance factor at each node (O(n)) space. for red-black if data stored in all nodes is &amp;gt;0. sign bit store colour information&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Red-black is used for Java TreeMap &amp;amp; TreeSet&lt;/p&gt;

&lt;h1&gt;
  
  
  Heap
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Binary Heap
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;min-heap&lt;/li&gt;
&lt;li&gt;max-heap&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;min / max -heap is complete binary tree where value of root node is &amp;lt;= / &amp;gt;= either of its children. Same property must be recursively true for &lt;strong&gt;all&lt;/strong&gt; subtrees in binary tree.&lt;/p&gt;
&lt;/blockquote&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%2Fg4j33m4lnnxrmsnvgxfl.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%2Fg4j33m4lnnxrmsnvgxfl.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Analysis
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;use when &lt;strong&gt;ordering is important&lt;/strong&gt; (e.g. priority queue)&lt;/li&gt;
&lt;li&gt;good at doing comparative operations
e.g. if you want values above x. just grab all parents of node X. no need to do any traversals all the down to leaf nodes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Lookup
&lt;/h4&gt;

&lt;p&gt;unlike BST, left and right subtree has no meaning. you can't divide the tree to search it.&lt;br&gt;
Must go through all nodes&lt;br&gt;
Complexity: &lt;code&gt;O(n)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;deletion&lt;u&gt;&lt;/u&gt;: O(log(n))&lt;/u&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Insertion:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;increase heap size by 1&lt;/li&gt;
&lt;li&gt;insert new element at end of heap &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Heapify&lt;/strong&gt;. let last node "bubbles up" (swaps with parents)
Complexity: &lt;code&gt;O(log(n))&lt;/code&gt;
unlike BST, left and right subtree has no meaning. you can't divide the tree to search it.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  deletion
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;replace root / element by last element&lt;/li&gt;
&lt;li&gt;delete last element from Heap&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;heapify&lt;/strong&gt; to ensure last node is in correct position&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Analysis
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;insertion is better tha O(n)&lt;/li&gt;
&lt;li&gt;priority&lt;/li&gt;
&lt;li&gt;flexible size&lt;/li&gt;
&lt;li&gt;slow lookup. (fast if its finding max or min)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Priority Queue
&lt;/h2&gt;

&lt;p&gt;Queue is FIFO. Objects with higher priority that enter later and get out first.&lt;/p&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;every element has priority associated with it&lt;/li&gt;
&lt;li&gt;element with high priority is dequeued befor an element with low priority&lt;/li&gt;
&lt;li&gt;2 elements have same priority they are served according to order in queue. 
&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%2Fwkzqte7syyoihujl65ru.png" alt="alt text"&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;e.g. emergency room&lt;/p&gt;

&lt;p&gt;Heap can be represented in the form of an array. In binary heap priority queue, objects with higher priority would be higher up. &lt;br&gt;
Then look at binary heap as an array and dequeue objects.&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%2F5ik5gfaq0olb0uxoqbnt.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%2F5ik5gfaq0olb0uxoqbnt.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Trie / Prefix tree
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;specialized tree for searching text. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;can have &amp;gt;2 children. use to search if character in word exists / subword in word exists.&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%2Fvu4foiwjxnythtwta0bx.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%2Fvu4foiwjxnythtwta0bx.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Space advantage: since its a prefix tree, if words share same prefix, dont have to store it twice. &lt;/p&gt;

&lt;h3&gt;
  
  
  Search
&lt;/h3&gt;

&lt;p&gt;Lookup for word. Look up for first character. then search children to see if other characters match.&lt;br&gt;
Complexity is the height of the tree. &lt;/p&gt;

&lt;p&gt;Complexity: &lt;code&gt;O(log(n))&lt;/code&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Insertion
&lt;/h3&gt;

&lt;p&gt;if character doesnt exist need to create new children. If character exists, mark end of word for last node. &lt;/p&gt;

&lt;p&gt;insertion requires one to go down depth of trie. &lt;/p&gt;

&lt;p&gt;Complexity: &lt;code&gt;O(log(n))&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Reasons for using Trees
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Store information that naturally forms hierarchy. Eg. the file system on a computer. &lt;/li&gt;
&lt;li&gt;Trees (e.g. BST) may provide moderately quick access/search.
Quicker than Linked List, slower than arrays. &lt;/li&gt;
&lt;li&gt;Trees provide moderate insertion/deletion,
Quicker than arrays, slower than unordered linked lists. &lt;/li&gt;
&lt;li&gt;No limit on number of nodes since nodes are linked using pointers (like linked list, unlike arrays) &lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Data Structure - Queue &amp; Stack</title>
      <dc:creator>limjy</dc:creator>
      <pubDate>Mon, 22 Mar 2021 16:20:17 +0000</pubDate>
      <link>https://dev.to/jing/data-structure-queue-stack-4dbm</link>
      <guid>https://dev.to/jing/data-structure-queue-stack-4dbm</guid>
      <description>&lt;p&gt;Summary sheet for myself for Queue &amp;amp; Stack DS.&lt;br&gt;
Resources from LeetCode &amp;amp; GeeksforGeeks&lt;/p&gt;

&lt;p&gt;Queues &amp;amp; Stack can &lt;code&gt;restrict processing order&lt;/code&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;LIFO&lt;/code&gt; - Last In First Out&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;FIFO&lt;/code&gt; - First In Last Out&lt;/li&gt;
&lt;/ol&gt;
&lt;h1&gt;
  
  
  FIFO
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0VFAU5Y---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m1xav1ughfzwx4cz1uhy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0VFAU5Y---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m1xav1ughfzwx4cz1uhy.png" alt="alt text"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;First element added to the queue will be processed first&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt;Operations&lt;/u&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;insert (enqueue) - item added to end of queue&lt;/li&gt;
&lt;li&gt;delete (dequeue) - remove first element&lt;/li&gt;
&lt;li&gt;rear - end of queue&lt;/li&gt;
&lt;li&gt;front - front of queue&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Queue - Implementation
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Array implementation
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3mDxY9gM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0s1kv71dyl2gku0h8738.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3mDxY9gM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0s1kv71dyl2gku0h8738.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;ArrayList / dynamic array &amp;amp; an index pointing to head of the queue&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

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

    private List&amp;lt;Integer&amp;gt; data; //queue
    private int p_start; // head of queue 

    public MyQueue() {
        data = new ArrayList&amp;lt;Integer&amp;gt;();
        p_start = 0;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;easy to implement&lt;/p&gt;

&lt;h4&gt;
  
  
  Limitations
&lt;/h4&gt;

&lt;p&gt;Space wasted. when item is dequeued, head 'moves' forward and there is empty space at front of arraylist that is wasted.&lt;/p&gt;

&lt;h3&gt;
  
  
  Linked List Implementation
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K4FtZdag--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/26oare7vw6kb3pub3unj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K4FtZdag--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/26oare7vw6kb3pub3unj.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;maintain two pointers front &amp;amp; rear (nodes of Linked List)&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MyQueue {
    QueueNode front, rear;

    // This function should add an item at
    // rear
    void push(int a)
    {
        // Your code here
        if (this.front == null) {
            this.front = new QueueNode(a);
            this.rear = front;

        } else {

            QueueNode addedItem = new QueueNode(a);
            this.rear.next = addedItem;
            this.rear = addedItem;
        }
    }

    // This function should remove front
    // item from queue and should return
    // the removed item.
    int pop()
    {
        // queue is empty
        if (this.front == null) {
            return -1;
        } else {
            int result = this.front.data;
            this.front = this.front.next;
            return result;
        } 

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

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Complexity&lt;/u&gt;&lt;br&gt;
Time complexity for all operations: &lt;code&gt;O(1)&lt;/code&gt; (no loops)&lt;br&gt;
Space Complexity: &lt;code&gt;O(N)&lt;/code&gt; for the linked list&lt;br&gt;
Auxillary Space complexity: &lt;code&gt;O(1)&lt;/code&gt; (extra space needed for operations)&lt;/p&gt;
&lt;h2&gt;
  
  
  Circular Queue / Ring Buffer
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Array Implementation
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6nm3XyBM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k8qag9oa1z04btrkiijx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6nm3XyBM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k8qag9oa1z04btrkiijx.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;resuses wasted storage space from array implementation&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;fixed size array&lt;/li&gt;
&lt;li&gt;pointer - start position&lt;/li&gt;
&lt;li&gt;point - end position
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MyCircularQueue {

    private int[] data;
    private int head;
    private int tail;
    private int size;

    /** Initialize your data structure here. Set the size of the queue to be k. */
    public MyCircularQueue(int k) {
        data = new int[k];
        head = -1;
        tail = -1;
        size = k;
    }   
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;initial head &amp;amp; tail is null / -1. cannot be 0. because when queue has 1 element head == tail.&lt;/li&gt;
&lt;li&gt;queue is empty if head || tail is initial value (null / -1)&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Complexity
&lt;/h4&gt;

&lt;p&gt;&lt;u&gt; Time Complexity &lt;/u&gt;&lt;br&gt;
Enqueue &lt;code&gt;O(1)&lt;/code&gt;&lt;br&gt;
Dequeue &lt;code&gt;O(1)&lt;/code&gt;&lt;br&gt;
Front &lt;code&gt;O(1)&lt;/code&gt;&lt;br&gt;
Rear &lt;code&gt;O(1)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt; Space Complexity &lt;/u&gt;&lt;br&gt;
Space complexity: &lt;code&gt;O(N)&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Linked List Implementation
&lt;/h3&gt;
&lt;h2&gt;
  
  
  Queue in Java
&lt;/h2&gt;

&lt;p&gt;In Java, Queue is an &lt;a href="https://www.geeksforgeeks.org/queue-interface-java/"&gt;interface&lt;/a&gt;, concrete classes are Priority Queue or Linked list. &lt;/p&gt;
&lt;h3&gt;
  
  
  Priority Queues
&lt;/h3&gt;

&lt;p&gt;allows users to process items based on priority&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Creating empty priority queue 
Queue&amp;lt;Integer&amp;gt; pQueue = new PriorityQueue&amp;lt;Integer&amp;gt;(); 

// Adding items to the pQueue 
// using add() 
pQueue.add(10); 
pQueue.add(20); 
pQueue.add(15); 

// Printing the top element of 
// the PriorityQueue 
System.out.println(pQueue.peek());

        // Printing the top element and removing it 
        // from the PriorityQueue container 
        System.out.println(pQueue.poll()); 

        // Printing the top element again 
        System.out.println(pQueue.peek()); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Linked List
&lt;/h3&gt;

&lt;p&gt;implements linked list data structure. Easier insertions / deletions make linked list preferred over arrays&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Creating empty LinkedList 
        Queue&amp;lt;Integer&amp;gt; ll 
            = new LinkedList&amp;lt;Integer&amp;gt;(); 

        // Adding items to the ll 
        // using add() 
        ll.add(10); 
        ll.add(20); 
        ll.add(15); 

        // Printing the top element of 
        // the LinkedList 
        System.out.println(ll.peek()); 

        // Printing the top element and removing it 
        // from the LinkedList container 
        System.out.println(ll.poll()); 

        // Printing the top element again 
        System.out.println(ll.peek())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Priority Blocking Queue
&lt;/h3&gt;

&lt;p&gt;Priority Queue and Linked list are not thread safe. Priority Blocking Queue is thread safe.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Creating empty priority 
        // blocking queue 
        Queue&amp;lt;Integer&amp;gt; pbq 
            = new PriorityBlockingQueue&amp;lt;Integer&amp;gt;(); 

        // Adding items to the pbq 
        // using add() 
        pbq.add(10); 
        pbq.add(20); 
        pbq.add(15); 

        // Printing the top element of 
        // the PriorityBlockingQueue 
        System.out.println(pbq.peek()); 

        // Printing the top element and 
        // removing it from the 
        // PriorityBlockingQueue 
        System.out.println(pbq.poll()); 

        // Printing the top element again 
        System.out.println(pbq.peek()); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Applications
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;items need not be processed immediately&lt;/li&gt;
&lt;li&gt;items processed in FIFO order (e.g. BFS)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Scenarios:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Resource shared among multiple consumers (CPU / Disk Scheduling)&lt;/li&gt;
&lt;li&gt;data transferred asynchronously between two processes (response not receive at same rate as sent) (e.g. IO buffers, file IO, pipes etc.)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Queue &amp;amp; BFS
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;instantiate queue with length N (number of nodes)&lt;/li&gt;
&lt;li&gt;start from root.&lt;/li&gt;
&lt;li&gt;visit node and enqueue (add) it to queue &lt;/li&gt;
&lt;li&gt;dequeue (pop) node from end of queue
5.1 visit all &lt;strong&gt;non-visited&lt;/strong&gt; children nodes of popped node in 4 and enqueue them
5.2 if all child nodes are visited, delete node &lt;/li&gt;
&lt;li&gt;repeat till 4-5 till queue is empty&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;process explained in more detail &lt;a href="http://www.btechsmartclass.com/data_structures/graph-traversal-bfs.html"&gt;here&lt;/a&gt;&lt;br&gt;
newly-added nodes are not processed immediately, they are processed in the next round (exact same process as queue)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NEVER&lt;/strong&gt; visit a node twice, else one can get stuck in tree with loop (e.g. graph with cycle) &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WUdZom72--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x1c97s5qvtgx2wq41w9s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WUdZom72--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x1c97s5qvtgx2wq41w9s.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
    //Function to return the level order traversal of a tree.
    Queue&amp;lt;Node&amp;gt; queue = new LinkedList&amp;lt;&amp;gt;();
    ArrayList&amp;lt;Integer&amp;gt; result = new ArrayList&amp;lt;&amp;gt;();
    ArrayList&amp;lt;Integer&amp;gt; levelOrder(Node node) {
        // Your code here
        queue.add(node);
        while (queue.size()&amp;gt;0) {
            Node top = queue.remove();
            result.add(top.data);
            if (top.left != null) {
                queue.add(top.left);
            }
            if (top.right != null) {
                queue.add(top.right);
            }
        }
        return result;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Applications of BFS
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Traversal&lt;/li&gt;
&lt;li&gt;Find the shortest path&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  LIFO
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iJTAGTnM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tdvwofqmno5y24d37o0i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iJTAGTnM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tdvwofqmno5y24d37o0i.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;newest element added to queue is processed first&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt;Operations&lt;/u&gt; &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;push - add element to top of stack, if full then overflow&lt;/li&gt;
&lt;li&gt;pop - remove element from top of stack, if empty its undeflow&lt;/li&gt;
&lt;li&gt;peek / top - get top element of stack&lt;/li&gt;
&lt;li&gt;isEmpty - check if stack is empty&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Stack - Implementation
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ArrayList Implementation
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;mantain top (for top of stack) &amp;amp; array &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Linkedlist Implementation
&lt;/h3&gt;

&lt;h2&gt;
  
  
  Stack in Java
&lt;/h2&gt;

&lt;p&gt;Java has a Stack class&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 1. Initialize a stack.
Stack&amp;lt;Integer&amp;gt; s = new Stack&amp;lt;&amp;gt;();
// 2. Push new element.
s.push(5);
s.push(13);
s.push(8);
s.push(6);
// 3. Check if stack is empty.
if (s.empty() == true) {
  System.out.println("Stack is empty!");
  return;
}
// 4. Pop an element.
s.pop();
// 5. Get the top element.
System.out.println("The top element is: " + s.peek());
// 6. Get the size of the stack.
System.out.println("The size is: " + s.size());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Stack and DFS
&lt;/h3&gt;

&lt;p&gt;More details &lt;a href="http://www.btechsmartclass.com/data_structures/graph-traversal-dfs.html"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;produces spanning tree (no loops)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;1 Create an empty stack S.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Initialize current node as root&lt;/li&gt;
&lt;li&gt;Push the current node to S and set current = current-&amp;gt;left until current is NULL&lt;/li&gt;
&lt;li&gt;If current is NULL and stack is not empty then 
 4.1. Pop the top item from stack.
 4.2. Print the popped item, set current = popped_item-&amp;gt;right 
 4.3. Go to step 3.&lt;/li&gt;
&lt;li&gt;If current is NULL and stack is empty then we are done.&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3Z40eD1s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5jxl5mzat7lwu3pa6pm8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3Z40eD1s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5jxl5mzat7lwu3pa6pm8.png" alt="alt text"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;More details on the algorithm &lt;a href="https://www.geeksforgeeks.org/inorder-tree-traversal-without-recursion/"&gt;here&lt;/a&gt; &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Algos - Searching &amp; Sorting</title>
      <dc:creator>limjy</dc:creator>
      <pubDate>Thu, 18 Mar 2021 15:58:17 +0000</pubDate>
      <link>https://dev.to/jing/algos-e4h</link>
      <guid>https://dev.to/jing/algos-e4h</guid>
      <description>&lt;p&gt;algos stuff. summary sheet. Information here is all a combination from LeetCode &amp;amp; GeeksforGeeks&lt;/p&gt;

&lt;p&gt;Summary: &lt;a href="https://www.bigocheatsheet.com/"&gt;Big O Cheat Sheet&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Searching
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Linear Search&lt;/li&gt;
&lt;li&gt;Binary Search&lt;/li&gt;
&lt;li&gt;Jump Search&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Linear Search
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;iterate through entire array, to search for intended item&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CT_VYHmv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6lczl50ad7cm7eb08715.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CT_VYHmv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6lczl50ad7cm7eb08715.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Time Complexity: &lt;code&gt;O(N)&lt;/code&gt; &lt;/p&gt;

&lt;h1&gt;
  
  
  Binary Search
&lt;/h1&gt;

&lt;p&gt;searching for specific value in an &lt;strong&gt;ordered&lt;/strong&gt; collection&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Target - value to search for&lt;/li&gt;
&lt;li&gt;Index - current location&lt;/li&gt;
&lt;li&gt;Left, Right - indices from to maintain search space&lt;/li&gt;
&lt;li&gt;Mid - index to apply condition to decide if search left or right&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xzBxwTx6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhp5x7al66tnoeki6xmc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xzBxwTx6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhp5x7al66tnoeki6xmc.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Get middle index of sequence, apply search condition to middle index&lt;/li&gt;
&lt;li&gt;if unsatisfied / values unequal, half of sequence is eliminated &lt;/li&gt;
&lt;li&gt;Continue search in remaining half until target is found&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Complexity
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Recursion&lt;/u&gt;&lt;br&gt;
Time Complexity: &lt;code&gt;O(log(n))&lt;/code&gt;&lt;br&gt;
Space Complexity: &lt;code&gt;O(log(n))&lt;/code&gt; (height of stack call, ~ height of binary tree)&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Iterative&lt;/u&gt;&lt;br&gt;
Time Complexity: &lt;code&gt;O(log(n))&lt;/code&gt;&lt;br&gt;
Space Complexity: &lt;code&gt;O(1)&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public int search(int[] nums, int target) {
    int left = 0;
    int right = nums.length -1;
    int midIdx = ((right - left) / 2 ) + left;

    while (left &amp;lt;= right) {
        if (nums[midIdx] &amp;lt; target) {
            // search in right half 
            left = midIdx +1;
            midIdx = ((right-left) / 2) + left;
        } else if (nums[midIdx] &amp;gt; target) {
            // search in left half
            right = midIdx - 1;
            midIdx = ((right - left) / 2) + left;
        } else {
            // nums[midIdx] == target
            return midIdx;
        }
    }
    return -1;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Jump Search
&lt;/h1&gt;

&lt;p&gt;Check fewer items then linear search ( in &lt;strong&gt;sorted array&lt;/strong&gt;) by jumping / skipping elements.&lt;/p&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;Search elements in array by index 0,m,2m etc.&lt;/li&gt;
&lt;li&gt;find indexes where arr[&lt;em&gt;k*m] &amp;lt; target &amp;lt; arr[(*k+1&lt;/em&gt;)m]&lt;/li&gt;
&lt;li&gt;linear search from &lt;em&gt;k*m till (*k+1&lt;/em&gt;)m to find target&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pLQuOFdP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u34b6ddjcvpvi99wjqhc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pLQuOFdP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u34b6ddjcvpvi99wjqhc.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  optimal block size to skip
&lt;/h2&gt;

&lt;p&gt;Time complexity = (N/m) + m&lt;br&gt;
For minimum time complexity,&lt;br&gt;
1 = (N/m) + m&lt;br&gt;
1 - m = N / m&lt;br&gt;
m - m&lt;sup&gt;2&lt;/sup&gt; = N&lt;br&gt;
m ~ sqrt(N)&lt;br&gt;
Therefore, optional block size (m) is &lt;strong&gt;sqrt(N)&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Complexity
&lt;/h3&gt;

&lt;p&gt;Space Complexity: &lt;code&gt;O(1)&lt;/code&gt;&lt;br&gt;
Time Complexity:&lt;br&gt;
assuming optimum block size m = sqrt(N),&lt;br&gt;
Time Complexity = (N/m) + m&lt;br&gt;
= (N/sqrt(N)) + sqrt(N)&lt;br&gt;
= sqrt(N) + sqrt(N)&lt;br&gt;
~ &lt;code&gt;O(sqrt(N))&lt;/code&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Sorting
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Impt&lt;/strong&gt;: understand trade offs for each algorithm&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt; Elementary &lt;u&gt;&lt;/u&gt;: n&lt;sup&gt;2&lt;/sup&gt;&lt;/u&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Bubble Sort (stable) &lt;/li&gt;
&lt;li&gt;Insertion Sort (stable)&lt;/li&gt;
&lt;li&gt;Selection Sort (stable) &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;u&gt; More complex &lt;u&gt;&lt;/u&gt;: n*log(n), divide and conquer&lt;/u&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Merge Sort (stable)&lt;/li&gt;
&lt;li&gt;Quick Sort (unstable)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;depending on the type of input (eg. list is reversed / nearly sorted) algo will perform differently&lt;/p&gt;

&lt;p&gt;For options 4 &amp;amp; 5. merge and quick sort utilize Divide and conquer. Divide and conquer gives log(n) advantage. &lt;/p&gt;
&lt;h3&gt;
  
  
  sort()
&lt;/h3&gt;

&lt;p&gt;Java arrays.sort() uses dual pivot quick sort&lt;br&gt;
complexity: &lt;code&gt;O(n log(n))&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Stable VS Unstable sort
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Stable: objects with equal keys appear in the same order in sorted output as input. &lt;br&gt;
** if two objects are compared as equal their order is preserved**&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Taken from &lt;a href="https://stackoverflow.com/a/1517824"&gt;SO answer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt; When is stable sort required? &lt;/u&gt;&lt;br&gt;
Stable sort is needed when equal elements are distinguishable. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;e.g. multiple criterias for sort. sort by object.A THEN object.B&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;in stable sort. sort by object.B THEN object.A. &lt;/p&gt;

&lt;p&gt;Eg. Radix sort. &lt;br&gt;
sorting integers by digits that share the same significant position &amp;amp; value &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CeuJCzpZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/16wbsq4z40oq0vim14yw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CeuJCzpZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/16wbsq4z40oq0vim14yw.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Bubble Sort
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;repeatedly swap adjacent elements if they are in the wrong order&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VxusXDr---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v2y6echq7wskufirpx92.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VxusXDr---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v2y6echq7wskufirpx92.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First pass brings max value to the end of array. second pass brings 2nd max value to second last index of array. To sort all indexes in ascending order need to do N passes. therefore complexity of n&lt;sup&gt;2&lt;/sup&gt;&lt;/p&gt;

&lt;p&gt;Time Complexity: O(n&lt;sup&gt;2&lt;/sup&gt;)&lt;br&gt;
Space Complexity: O(1)&lt;br&gt;
Stable: yes&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Input: 4A 5 3 2 4B 1&lt;br&gt;
1st pass: 4A 3 2 4B 1 5&lt;br&gt;
2nd pass: &lt;br&gt;
&lt;strong&gt;3 4A&lt;/strong&gt; 2 4B 1 5&lt;br&gt;
3 &lt;strong&gt;2 4A&lt;/strong&gt; 4B 1 5&lt;br&gt;
3 2 &lt;strong&gt;4A 4B&lt;/strong&gt; 1 5&lt;br&gt;
3 2 4A &lt;strong&gt;1 4B&lt;/strong&gt; 5&lt;br&gt;
3rd pass:&lt;br&gt;
3 2 1 4A 4B 5&lt;br&gt;
output: 1 2 3 4A 4B 5&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  2. Selection Sort
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Find minimum element from unsorted part and putting it at the beginning. min element and element at beginning swap places.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LaA8Xu83--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhrpmspqtbq08btd6r8z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LaA8Xu83--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhrpmspqtbq08btd6r8z.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First pass through unsorted part to get min value. Second pass through unsorted part to get second min value. N passes are needed to sort all elements in the unsorted part.&lt;/p&gt;

&lt;p&gt;Time Complexity: O(n&lt;sup&gt;2&lt;/sup&gt;)&lt;br&gt;
Space Complexity: O(1)&lt;br&gt;
Stable: no&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Input : 4A 5 3 2 4B 1&lt;br&gt;
Output : &lt;br&gt;
1st: &lt;strong&gt;1&lt;/strong&gt; 5 3 2 4B 4A&lt;br&gt;
2nd: &lt;strong&gt;1 2&lt;/strong&gt; 5 3 4B 4A &lt;br&gt;
final: 1 2 3 4B 4A 5&lt;br&gt;
&lt;small&gt; swapping of places 4A and 1 made the selection sort unstable&lt;/small&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Code example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void sort(int arr[])
    {
        int n = arr.length;

        // One by one move boundary of unsorted subarray
        for (int i = 0; i &amp;lt; n-1; i++)
        {
            // Find the minimum element in unsorted array
            int min_idx = i;
            for (int j = i+1; j &amp;lt; n; j++)
                if (arr[j] &amp;lt; arr[min_idx])
                    min_idx = j;

            // Swap the found minimum element with the first
            // element
            int temp = arr[min_idx];
            arr[min_idx] = arr[i];
            arr[i] = temp;
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. insertion Sort
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;best for: &lt;strong&gt;small dataset &amp;amp; nearly sorted data&lt;/strong&gt;&lt;br&gt;
array is virtually split into a sorted and an unsorted part. Values from the unsorted part are picked and placed at the correct position in sorted part. (compare one by one with elements in sorted part to find correct position).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bKdN0EW6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aske19pqf2656029ayqk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bKdN0EW6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aske19pqf2656029ayqk.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

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

  static void insert(int arr[],int i) {
      int num = arr[i];
      int insertionIdx = i;
      for (int j=i-1;j&amp;gt;=0;j--) {
          if (arr[i] &amp;lt; arr[j]) {
              insertionIdx--;
              if (j==0) {
                  break;
              } 
          }else {
              break;
          }   
      }
      for (int x=i;x&amp;gt;insertionIdx;x--) {
          arr[x]=arr[x-1];
      }
      arr[insertionIdx] = num;
  }
  //Function to sort the array using insertion sort algorithm.
  public void insertionSort(int arr[], int n) {
      //code here
      for (int i=1;i&amp;lt;arr.length;i++) {
          if (arr[i] &amp;lt; arr[i-1]) {
              int index = i-1;
              insert(arr,i);
          } 
      }
  }

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

&lt;/div&gt;



&lt;p&gt;Time Complexity&lt;br&gt;
&lt;u&gt; Best Case &lt;/u&gt;: O(n)&lt;br&gt;
In best case, array already sorted, one pass, check that first element in unsorted part, is larger than last element in sorted part.&lt;br&gt;
&lt;u&gt; Worst &amp;amp; Average Case &lt;/u&gt;: O(n&lt;sup&gt;2&lt;/sup&gt;&lt;br&gt;
In worse case, array sorted in reverse order. algorithm will scan and shift through entire sorted subsection before inserting. will do this N times for all elements. so n&lt;sup&gt;2&lt;/sup&gt;&lt;/p&gt;

&lt;p&gt;Stable: Yes&lt;br&gt;
Input: 4A 5 3 2 4B 1&lt;br&gt;
Output:&lt;br&gt;
1st pass: &lt;strong&gt;1&lt;/strong&gt; 4A 5 3 2 4B&lt;br&gt;
2nd pass: &lt;strong&gt;1 2&lt;/strong&gt; 4A 5 3 4B&lt;br&gt;
3rd pass: &lt;strong&gt;1 2 3&lt;/strong&gt; 4A 5 4B&lt;br&gt;
4th pass: &lt;strong&gt;1 2 3 4A&lt;/strong&gt; 5 4B&lt;br&gt;
output: 1 2 3 4A 4B 5 &lt;/p&gt;

&lt;h2&gt;
  
  
  4. Merge Sort
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Divide and Conquer&lt;/strong&gt; algorithm &lt;br&gt;
Divides the input array into two halves, (until each subarray is only size 2) calls itself for the two halves, and then merges the two sorted halves. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UpuHrOUd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9g2nc89s5wllklazkfu9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UpuHrOUd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9g2nc89s5wllklazkfu9.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;array is recursively divided into 2 halves until size is 1. Once size is 1, merge process starts and arrays are merged till complete array is merged. &lt;/p&gt;

&lt;p&gt;Time Complexity: O(n*log(n))&lt;br&gt;
Space Complexity: O(n)&lt;br&gt;
Stable: yes&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Quick Sort
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;u&gt;best for&lt;/u&gt;: &lt;strong&gt;average complexity&lt;/strong&gt;. Avoid if you cant garuntee a good pivot &lt;br&gt;
Divide and conquer. Pick element as pivot point. Split array into two halves, lower than pivot element and higher than pivot element. Repeat process on subarrays until the halves have lenght of 1. Then combine all the elements back together to 1 array.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--k6GMjk4e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9mbgzi8s25j1qmstnpoq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k6GMjk4e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9mbgzi8s25j1qmstnpoq.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Time Complexity: &lt;br&gt;
&lt;u&gt; Best / Average &lt;/u&gt;: O (n*log(n))&lt;br&gt;
&lt;u&gt; Worst &lt;/u&gt;: O(n&lt;sup&gt;2&lt;/sup&gt;)&lt;br&gt;
worst case if the pivot point is the largest/ smallest element. List is not split into half.&lt;br&gt;
Space Complexity: O(log(n))&lt;br&gt;
Stable: no&lt;/p&gt;

&lt;h3&gt;
  
  
  Non-comparison Sort
&lt;/h3&gt;

&lt;p&gt;Sorts are hard to beat O(n*log(n)) because you have to compare each element. to beat log(n) you need non-comparison sort&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;takes advantage of the way numbers (specifically integers) are stored in memory.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;only work with numbers in a specific range&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;Radix sort&lt;/li&gt;
&lt;li&gt;Counting sort&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;could be faster than merge or quick sort&lt;/p&gt;

&lt;h1&gt;
  
  
  When to use which sorting algo?
&lt;/h1&gt;

&lt;p&gt;&lt;u&gt;Insertion&lt;u&gt;&lt;/u&gt;&lt;br&gt;
few items / items are mostly sorted.&lt;br&gt;
&lt;u&gt;Bubble&lt;u&gt;&lt;/u&gt;&lt;br&gt;
&lt;u&gt; Selection&lt;u&gt;&lt;/u&gt;&lt;br&gt;
&lt;u&gt;Merge Sort&lt;u&gt;&lt;/u&gt;&lt;/u&gt;&lt;/u&gt;&lt;/u&gt;&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;best average and worst case is always O(n*log(n)) --&amp;gt; we will always divide up the list equally. &lt;/li&gt;
&lt;li&gt;if data set is big, suitable if you have external sorting (space complexity of O(n)) (data does not fit into main memory of computer device)
&lt;u&gt;Quick Sort&lt;u&gt;&lt;/u&gt;&lt;/u&gt;
&lt;/li&gt;
&lt;li&gt;avoid if you are scared of worst case (cannot garuntee good pivot)&lt;/li&gt;
&lt;li&gt;suitable if there is no external sorting. space complexity of O(log(n))
&lt;u&gt;Radix / Counting Sort&lt;u&gt;&lt;/u&gt;&lt;/u&gt;
&lt;/li&gt;
&lt;li&gt;sorting integers&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Trees &amp;amp; Graph - Searching
&lt;/h1&gt;

&lt;h2&gt;
  
  
  BFS VS DFS
&lt;/h2&gt;

&lt;p&gt;BFS:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;node is in upper level of tree&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;shortest path / closest nodes &lt;/li&gt;
&lt;li&gt;more memory (need to keep tarck of current nodes)&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;DFS:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;node is in lower level of tree&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;less memory / does path exist?&lt;/li&gt;
&lt;li&gt;can get slow&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Eg. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;solution if not far from root of tree
BFS&lt;/li&gt;
&lt;li&gt;&lt;p&gt;tree is deep, solutions are rare&lt;br&gt;
BFS (DFS will take long time) OR &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;tree is very wide&lt;br&gt;
DFS (BFS will need too much memory)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;solutions are frequent but located deep in tree&lt;br&gt;
DFS&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;path exist between 2 nodes&lt;br&gt;
DFS&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;path exist between two nodes&lt;br&gt;
BFS&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Djisktra &amp;amp; Bellman-Ford
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;shortest path&lt;/strong&gt; between two nodes of &lt;strong&gt;weighted&lt;/strong&gt; graph&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Bellman: can accommodate for negative weights&lt;/li&gt;
&lt;li&gt;Djisktra: more efficient but cannot accommodate for negative weights (greedy algo)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Djisktra cannot accomodate negative weights because it assumes "adding" a weight can never make a path shorter. &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
