Getting Started with ASP.NET MVC 5

https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/

Getting Started with Entity Framework 6 Code First using MVC 5

https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/

Getting Started with Entity Framework 6 Database First Using MVC 5

https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/database-first-development/

Getting Started with ASP.NET Web API 2 (C#)

https://docs.microsoft.com/en-us/aspnet/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api

Using Web API 2 with Entity Framework 6

https://docs.microsoft.com/en-us/aspnet/web-api/overview/data/using-web-api-with-entity-framework/

Create a REST API with Attribute Routing in ASP.NET Web API 2

https://docs.microsoft.com/en-us/aspnet/web-api/overview/web-api-routing-and-actions/create-a-rest-api-with-attribute-routing

Enabling Cross-Origin Requests in ASP.NET Web API 2

https://docs.microsoft.com/en-us/aspnet/web-api/overview/security/enabling-cross-origin-requests-in-web-api

Algorithm Time Complexity Space Complexity
Best Average Worst Worst
Quicksort Ω(n log(n)) Θ(n log(n)) O(n^2) O(log(n))
Mergesort Ω(n log(n)) Θ(n log(n)) O(n log(n)) O(n)
Timsort Ω(n) Θ(n log(n)) O(n log(n)) O(n)
Heapsort Ω(n log(n)) Θ(n log(n)) O(n log(n)) O(1)
Bubble Sort Ω(n) Θ(n^2) O(n^2) O(1)
Insertion Sort Ω(n) Θ(n^2) O(n^2) O(1)
Selection Sort Ω(n^2) Θ(n^2) O(n^2) O(1)
Tree Sort Ω(n log(n)) Θ(n log(n)) O(n^2) O(n)
Shell Sort Ω(n log(n)) Θ(n(log(n))^2) O(n(log(n))^2) O(1)
Bucket Sort Ω(n+k) Θ(n+k) O(n^2) O(n)
Radix Sort Ω(nk) Θ(nk) O(nk) O(n+k)
Counting Sort Ω(n+k) Θ(n+k) O(n+k) O(k)
Cubesort Ω(n) Θ(n log(n)) O(n log(n)) O(n)

Module System Common Syntax
CommonJS require,module.exports
AMD require,define
ES2015 import,export

What is Application State? (State stays in store)

  • Server response data
  • User information
  • User input
  • UI state
  • Router/location state

We compose application state in our Store.

State Management Libraries

  • Model our app state
  • Update state
  • Read state values
  • Monitor/observe changes to state

Redux: Three Principles

  1. Single source of truth
  2. State is read-only
  3. Pure Functions update state

Single source of truth

  • One state tree inside Store
  • Predictability, maintainability
  • Universal apps (SSR)
  • Testing and debugging

State is read-only

  • Derive properties from state
  • Dispatch actions to change the state
  • Immutable update patterns

Pure functions update state

  • Pure functions are reducers
  • Reducers respond to action types
  • Reducers return new state

Redux: Core Concepts

  • Single state tree
  • Actions
  • Reducers
  • Store
  • One-way dataflow

Single State Tree

  • Plain JavaScript Object
  • Composed by reducers
const state = {
todos:[]
};

Actions

  • Two properties:
    type: string, describes event payload: optional data
  • Dispatch actions to reducers
const action = {
type: 'ADD_TODO',
payload: {
label: 'Eat pizza',
complete: false
}
}

Reducers

  • Pure functions
  • Given dispatched action
    • Responds to action.type
    • Access to action.payload
    • Composes new state
    • Returns new state
function reducer(state, action) {
switch(action.type) {
case 'ADD_TODO': {
const todo = action.payload;
const todos = [...state.todos, todo];
return { todos };
}
}

return state;
}
const state = {
todos: [
{ label: 'Eat pizza', complete: false }
]
};

Store

  • State container
  • Components interact with the Store
    • Subscribe to slices of State
    • Dispatch Actions to Store
  • Store invvokes Reducers with pervious State and Action
  • Reducers compose new State
  • Store is updated, notifies subscibers

One-way dataflow

                       --------------------------------------
        Dispatch       |            ---------- Sent to      |
     ------------------|----------->| Action |--------      |
     |                 |            ----------       |      |
     |                 |                             |      |
     |                 |                             V      |
-------------          |                        ----------- |
| component |          |    Store               | Reducer | |
-------------          |                        ----------- |
     ^                 |                             |      |
     |                 |                             |      |     
     |  Render         |            ---------        |      |
     ------------------|------------| State |<--------      |
                       |            --------- New State     |
                       --------------------------------------

Immutable and Mutable Javascript

An immutable object is an object whose state cannot be modifies after creation.

Why Immutable ?

  • Predictability
  • Explicit state changes
  • Performance (Change Detection)
  • Mutation Tracking
  • Undo state changes

Mutability in JavaScript

  • Functions
  • Objects
  • Arrays

Immutability in JavaScript

  • Strings
  • Numbers
const character = { name: 'Han Solo' };

// Object.assign({}, character, { role: 'Captain'});
const updatedCharacter = {...character, role: 'Captain'};

// { name: 'Han Solo' };
console.log(character);
// { name: 'Han Solo', role: 'Captain' };
console.log(updatedCharacter);

ngrx/effect

listen for ngrx/store actions

Isolate side effects from components

Communicate outside of Angular

Effects flow

                       -------------------------------------- ------------
        Dispatch       |            ---------- Sent to      | | Effects  | 
     ------------------|----------->| Action |--------      | |          | 
     |                 |            ----------       |      | |          |
     |                 |                             |      | |          |
     |                 |                             V      | |  EFFEC   |
-------------          |                        ----------- | |          |
| component |          |    Store               | Reducer | | |          |
-------------          |                        ----------- | |          |
     ^                 |                             |      | |          |
     |                 |                             |      | |          |    
     |  Render         |            ---------        |      | |          |
     ------------------|------------| State |<--------      | |          |
                       |            --------- New State     | |          |
                       -------------------------------------- ------------
ng generate m cover --routing
ng generate @ngrx/schematics:action scenario/quote --group --spec
ng generate @@ngrx/schematics:feature quote/benefits -m quote/quote.module.ts --group --reducers selectors/index.ts
ng generate @ngrx/schematics:store cover/Cover -m cover.module.ts --statePath selectors

Youtube

You might not need NgRx | Mike Ryan | AngularConnect 2018

Angular: when ngrx is an overkill

State Management Patterns and Best Practices with NgRx – Victor Savkin – AngularConnect 2017

NgRx Selectors How to stop worrying about your Store structure - David East & Todd Motto

Reducing the Boilerplate with NgRx - Brandon Roberts & Mike Ryan

Good Action Hygiene with NgRx Mike Ryan

Authentication with NgRx - Brandon Roberts

Reactive Testing Strategies with NgRx - Brandon Roberts & Mike Ryan

Just Another Marble Monday – Unit Testing NGRX RxJS with Marbles - Sam Brennan & Keith Stewart

NgRx Schematics - Vitalii Bobrov

Ionic, ngrx and Angular: building web and mobile apps with one code base - Duncan Hunter

RXJS Observables in Angular - Ward Bell & Sander Ellis

Lesson 1

private: this Class.
package-private(default): Classes in same package
protected: Subclasses + Classes in same package
public: All

static: create class method and variables
final: finalize the implementation
abstract: create abstract class and methods
synchronized: prvent

Static:

  • Static variable
    Refer the common property of all objects of a class Gets memory only once in class area at the time of class loading

isolated from enclosing class instance.

  • Static method
    class Arrays {
    public static void sort(int[] a) {
    ...
    }
    }

    public static void main(Strings[] args) {
    int a[] = {2, 3, 1};
    Arrays.sort(a[]);
    }

Belongs to class rahter than object of the class Can be invoked without creating an instance of a class
Can access and update static member of the class Cannot access non-static members

the same, cannot access non-static members.

  • Static class
    Outer class cannot be static Inner class can be static
    ** User inner class without creating an instance of outer class

static inner class isolated from enclosing class instance.

  • Static initializer
public class Solution {
public static void main(String [] args) {
System.out.println("Main Method.");
}

static {
System.out.println("Inside Static Initializer.");
}
}

Run only one time before constructor/mmain method called No return
No arguments No this/super support

  • Final
    Final Class: class cannot be extended Final method: method cannot be override
    ** Final variable: variable can only be assigned once. (Reference!)

  • Data Structures
    What you’ll learn in this course:
    ArrayList LinkedList
    HashTable/Map/Set Tree
    Stack/Queue Heap

ArrayList in Jave - method review
create - List list = new ArrayList<>();
add - list.add(e) - return: boolean
remove - list.remove(index) - return: element removed
get - list.get(index) - return element
size - list.size() - return: int

*Algorithms
What you’ll learn in this course:

Binary Search Sort (quickSort/mergeSort)
DFS & BFS Dynamic Programming

Linear Search vs Binary Search

Search target: 51

Middle index = (start + end) / 2 = (0+8)/2 = 4

Search

Linear Search: O(n)
Binary Search: O(logN)

Lesson 2

4 Fundamental Concepts

  • Inheritance
  • Polymorphism
  • Abstraction
  • Encapsulation

Inheritance

  • SubClass acquire properties from SuperClass
  • Java does not support multi-inheritance => can only extend from one class.

Overriding vs Overloading

  • Overloading: allow a class to have multiple methods of the same name signature
public Vehicle() {
owner = "";
speed = 0.0;
}

public Vehicle(String owner, double speed) {
this.owner = owner;
this.speed = speed;
}

## 'Object' class (java.lang.Object/Csharp.System.Object)
* **Every** class has 'Object' class as a superclass.
* All objects implement the methods of this class
* finalize()
* equals(Object obj)
* hashCode()
* toString()

protected void finalize()
* garbage collector determins there's no more reference to the object.

* boolean equals(Object obj)

* int hashCode()

* Consistency -> called multiple times, same result
* If two objects equals() to each other, their hashCode() must return identical integer
* Necessary to override hashCode() once override equals()

```java
public boolean equals(Object obj) {

return (this == obj);
}

public native int hashCode();

native implementation which provides the memory address to a certain extent.

Polymorphism

  • Single object -> multiple forms

Abstraction

  • Provide a generalization over a set of behaviors
  • User cares about high-level functionality not implementation
  • abstract class & interface

Interface - Java 8 - Default Method

interface Vehicle {
String getOwner();

default void start() {
System.out.println(
String.format("%s is starting vehicle... ", getOwner());
)
}
}

Interfaces vs Abstract Classes

Interfaces (Interface => Description (e.g. Icomparable or Iserializable))

  • Do not maintain state (all variables are static final).
  • Multiple inheritance

Abstract Class (Abstract Class => Code Sharing Basis )

  • Share code among classes.
  • Share common non-public method
  • Share code which could chnange the state of the object.

Encapsulation

  • Hiding implemementation details
  • Easy to change implementation with new requirements
  • Control “who” can access “what”

Factory Pattern

  • Remove instantiation of actual implmentation classes from client code.

4 Fundamental Concepts

  • Inheritance: one class based on another
  • Polymorphism: single object -> many forms
  • Abstraction: provide generalization
  • Encapsulation: hide implememention details

Test: ParkingLot

  • ParkingLot
  • Slot - small, large, etc
  • Vehicle - Car, Bus, etc
  • Parker ?
  • Park car
  • UnPark car
  • Find empty space
  • Is full?

Java Multi-threading

Thread vs Process

  • A process has one or more threads
  • Threads share the address space; processes have own address space.
  • Cancel, change priority, etc to main thread may affect the behavior of other threads;
    changes to parent process does not affect child process.

Life-cycle of a thread

------------End of execution--------------
|                                        V

New Thread() -> New -> (Start()) -> Runnable -> (run()) -> Running -> (Sleep(), Wait()) -> Waiting -> Dead
| ^

|                                                                                     |
---------------------------------------------------------------------------------------

Create a Thread

public class VehicleClient implemeents Runnable {
@Override
public void run() {
builder.createVehicle("Car", "Bob", id);
}
}

new Thread(new VheicleClient()).start();
public class VehicleClient extends Thread {
@Override
public void run() {

}
}

new VehicleClient().start();

Algorithms

English-language description

Compute the greatest common divisor of two nonnegative integers p and q as follows: if q is 0, the answer is p. If not, divide p by q and take the remainder r. The answer is the greatest common divisor of q and r.

Java-language description

```java
public static int gcd(int p, int q)
{
if (q == 0) return p;
int r = p % q;
return gcd(q, r);
}






































Hook Purpose and Timing

ngOnChanges()

Respond when Angular (re)sets data-bound input properties.
The method receives a SimpleChanges object of current and previous property values.
Called before ngOnInit() and whenever one or more data-bound input properties change.

ngOnInit()

Initialize the directive/component after Angular first displays the data-bound properties
and sets the directive/component’s input properties.
Called once, after the first ngOnChanges().

ngDoCheck()

Detect and act upon changes that Angular can’t or won’t detect on its own.
Called during every change detection run, immediately after ngOnChanges() and ngOnInit().

ngAfterContentInit()

Respond after Angular projects external content into the component’s view.
Called once after the first ngDoCheck().
A component-only hook.

ngAfterContentChecked()

Respond after Angular checks the content projected into the component.
Called after the ngAfterContentInit() and every subsequent ngDoCheck().
A component-only hook.

ngAfterViewInit()

Respond after Angular initializes the component’s views and child views.
Called once after the first ngAfterContentChecked().
A component-only hook.

ngAfterViewChecked()

Respond after Angular checks the component’s views and child views.
Called after the ngAfterViewInit and every subsequent ngAfterContentChecked().
A component-only hook.

ngOnDestroy

Cleanup just before Angular destroys the directive/component.
Unsubscribe Observables and detach event handlers to avoid memory leaks.
Called just before Angular destroys the directive/component.