<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.3">Jekyll</generator><link href="https://kevkeyingli.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://kevkeyingli.github.io/" rel="alternate" type="text/html" /><updated>2023-02-07T02:04:01+00:00</updated><id>https://kevkeyingli.github.io/feed.xml</id><title type="html">Kevin’s Tech Notebook</title><subtitle>Web Developer, Data Visualization, Machine Learning, Music Lover...</subtitle><entry><title type="html">Next Technology Revolution</title><link href="https://kevkeyingli.github.io/Next-Technology-Revolution/" rel="alternate" type="text/html" title="Next Technology Revolution" /><published>2020-08-01T00:00:00+00:00</published><updated>2020-08-01T00:00:00+00:00</updated><id>https://kevkeyingli.github.io/Next-Technology-Revolution</id><content type="html" xml:base="https://kevkeyingli.github.io/Next-Technology-Revolution/">&lt;h1 id=&quot;next-technology-revolution&quot;&gt;Next Technology Revolution&lt;/h1&gt;
&lt;p&gt;Science and Technology is the driving force of all human world advancements. From steam engine to electricity, information technologies to artificial intelligence. Here are some of the up and coming technological trend that will change the world.&lt;/p&gt;

&lt;h2 id=&quot;genetic-engineering-to-change-humans-relationship-with-its-own-physiology&quot;&gt;Genetic Engineering to change human’s relationship with its own physiology.&lt;/h2&gt;
&lt;p&gt;Gene editing, Gene therapy, potentially genetic enhancements(with radical ideological revolution and emancipation)&lt;/p&gt;

&lt;h2 id=&quot;brain-computer-interface-to-change-human-computer-interaction&quot;&gt;Brain Computer Interface to change human computer interaction&lt;/h2&gt;
&lt;p&gt;Revolutionize human computer interaction from physically typing, clicking, tabbing, seeing, hearing, reading to mentally two way signaling.&lt;/p&gt;

&lt;p&gt;A whole other level from the VR/AR/MR we dream of today.&lt;/p&gt;

&lt;p&gt;Interpersonal interaction will advance from phone call, text message, video chat to a whole new level of mind sharing.&lt;/p&gt;

&lt;p&gt;Human will need to find ways and learn to share what they want, and protect what they don’t want to share. (Like in Inception)&lt;/p&gt;

&lt;p&gt;Protecting privacy, peace of mind will be extremely challenging.&lt;/p&gt;</content><author><name></name></author><summary type="html">Next Technology Revolution Science and Technology is the driving force of all human world advancements. From steam engine to electricity, information technologies to artificial intelligence. Here are some of the up and coming technological trend that will change the world.</summary></entry><entry><title type="html">Effective Java Ch1</title><link href="https://kevkeyingli.github.io/Effective-Java-Ch1/" rel="alternate" type="text/html" title="Effective Java Ch1" /><published>2018-09-22T00:00:00+00:00</published><updated>2018-09-22T00:00:00+00:00</updated><id>https://kevkeyingli.github.io/Effective-Java-Ch1</id><content type="html" xml:base="https://kevkeyingli.github.io/Effective-Java-Ch1/">&lt;p&gt;Effective Java, Third Edition (Joshua Bloch)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;您在位置 #322-325的标注&lt;/td&gt;
          &lt;td&gt;添加于 2018年9月19日星期三 下午9:26:34&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;clarity-and-simplicity-are-of-paramount-importance-the-user-of-a-component-should-never-be-surprised-by-its-behavior-components-should-be-as-small-as-possible-but-no-smaller-as-used-in-this-book-the-term-component-refers-to-any-reusable-software-element-from-an-individual-method-to-a-complex-framework-consisting-of-multiple-packages-code-should-be-reused-rather-than-copied-the-dependencies-between-components-should-be-kept-to-a-minimum-errors-should-be-detected-as-soon-as-possible-after-they-are-made-ideally-at-compile-time&quot;&gt;Clarity and simplicity are of paramount importance. The user of a component should never be surprised by its behavior. Components should be as small as possible but no smaller. (As used in this book, the term component refers to any reusable software element, from an individual method to a complex framework consisting of multiple packages.) Code should be reused rather than copied. The dependencies between components should be kept to a minimum. Errors should be detected as soon as possible after they are made, ideally at compile time.&lt;/h1&gt;
&lt;p&gt;Effective Java, Third Edition (Joshua Bloch)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;您在位置 #327-328的标注&lt;/td&gt;
          &lt;td&gt;添加于 2018年9月19日星期三 下午9:27:06&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;learning-the-art-of-programming-like-most-other-disciplines-consists-of-first-learning-the-rules-and-then-learning-when-to-break-them&quot;&gt;Learning the art of programming, like most other disciplines, consists of first learning the rules and then learning when to break them.&lt;/h1&gt;
&lt;p&gt;Effective Java, Third Edition (Joshua Bloch)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;您在位置 #362-366的标注&lt;/td&gt;
          &lt;td&gt;添加于 2018年9月19日星期三 下午9:29:31&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;the-language-supports-four-kinds-of-types-interfaces-including-annotations-classes-including-enums-arrays-and-primitives-the-first-three-are-known-as-reference-types-class-instances-and-arrays-are-objects-primitive-values-are-not-a-classs-members-consist-of-its-fields-methods-member-classes-and-member-interfaces-a-methods-signature-consists-of-its-name-and-the-types-of-its-formal-parameters-the-signature-does-not-include-the-methods-return-type&quot;&gt;The language supports four kinds of types: interfaces (including annotations), classes (including enums), arrays, and primitives. The first three are known as reference types. Class instances and arrays are objects; primitive values are not. A class’s members consist of its fields, methods, member classes, and member interfaces. A method’s signature consists of its name and the types of its formal parameters; the signature does not include the method’s return type.&lt;/h1&gt;
&lt;p&gt;Effective Java, Third Edition (Joshua Bloch)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;您在位置 #367-370的标注&lt;/td&gt;
          &lt;td&gt;添加于 2018年9月19日星期三 下午9:30:16&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;unlike-the-java-language-specification-this-book-uses-inheritance-as-a-synonym-for-subclassing-instead-of-using-the-term-inheritance-for-interfaces-this-book-simply-states-that-a-class-implements-an-interface-or-that-one-interface-extends-another-to-describe-the-access-level-that-applies-when-none-is-specified-this-book-uses-the-traditional-package-private-instead-of-the-technically-correct-package-access&quot;&gt;Unlike The Java Language Specification, this book uses inheritance as a synonym for subclassing. Instead of using the term inheritance for interfaces, this book simply states that a class implements an interface or that one interface extends another. To describe the access level that applies when none is specified, this book uses the traditional package-private instead of the technically correct package access&lt;/h1&gt;
&lt;p&gt;Effective Java, Third Edition (Joshua Bloch)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;您在位置 #371-375的标注&lt;/td&gt;
          &lt;td&gt;添加于 2018年9月19日星期三 下午9:31:01&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;the-term-exported-api-or-simply-api-refers-to-the-classes-interfaces-constructors-members-and-serialized-forms-by-which-a-programmer-accesses-a-class-interface-or-package-the-term-api-which-is-short-for-application-programming-interface-is-used-in-preference-to-the-otherwise-preferable-term-interface-to-avoid-confusion-with-the-language-construct-of-that-name-a-programmer-who-writes-a-program-that-uses-an-api-is-referred-to-as-a-user-of-the-api-a-class-whose-implementation&quot;&gt;The term exported API, or simply API, refers to the classes, interfaces, constructors, members, and serialized forms by which a programmer accesses a class, interface, or package. (The term API, which is short for application programming interface, is used in preference to the otherwise preferable term interface to avoid confusion with the language construct of that name.) A programmer who writes a program that uses an API is referred to as a user of the API. A class whose implementation&lt;/h1&gt;
&lt;p&gt;Effective Java, Third Edition (Joshua Bloch)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;您在位置 #371-375的标注&lt;/td&gt;
          &lt;td&gt;添加于 2018年9月19日星期三 下午9:31:06&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;the-term-exported-api-or-simply-api-refers-to-the-classes-interfaces-constructors-members-and-serialized-forms-by-which-a-programmer-accesses-a-class-interface-or-package-the-term-api-which-is-short-for-application-programming-interface-is-used-in-preference-to-the-otherwise-preferable-term-interface-to-avoid-confusion-with-the-language-construct-of-that-name-a-programmer-who-writes-a-program-that-uses-an-api-is-referred-to-as-a-user-of-the-api-a-class-whose-implementation-1&quot;&gt;The term exported API, or simply API, refers to the classes, interfaces, constructors, members, and serialized forms by which a programmer accesses a class, interface, or package. (The term API, which is short for application programming interface, is used in preference to the otherwise preferable term interface to avoid confusion with the language construct of that name.) A programmer who writes a program that uses an API is referred to as a user of the API. A class whose implementation&lt;/h1&gt;
&lt;p&gt;Effective Java, Third Edition (Joshua Bloch)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;您在位置 #371-375的标注&lt;/td&gt;
          &lt;td&gt;添加于 2018年9月19日星期三 下午9:31:16&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;the-term-exported-api-or-simply-api-refers-to-the-classes-interfaces-constructors-members-and-serialized-forms-by-which-a-programmer-accesses-a-class-interface-or-package-the-term-api-which-is-short-for-application-programming-interface-is-used-in-preference-to-the-otherwise-preferable-term-interface-to-avoid-confusion-with-the-language-construct-of-that-name-a-programmer-who-writes-a-program-that-uses-an-api-is-referred-to-as-a-user-of-the-api-a-class-whose-implementation-uses-an-api-is-a-client-of-the-api&quot;&gt;The term exported API, or simply API, refers to the classes, interfaces, constructors, members, and serialized forms by which a programmer accesses a class, interface, or package. (The term API, which is short for application programming interface, is used in preference to the otherwise preferable term interface to avoid confusion with the language construct of that name.) A programmer who writes a program that uses an API is referred to as a user of the API. A class whose implementation uses an API is a client of the API.&lt;/h1&gt;
&lt;p&gt;Effective Java, Third Edition (Joshua Bloch)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;您在位置 #371-375的标注&lt;/td&gt;
          &lt;td&gt;添加于 2018年9月19日星期三 下午9:31:22&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;the-term-exported-api-or-simply-api-refers-to-the-classes-interfaces-constructors-members-and-serialized-forms-by-which-a-programmer-accesses-a-class-interface-or-package-the-term-api-which-is-short-for-application-programming-interface-is-used-in-preference-to-the-otherwise-preferable-term-interface-to-avoid-confusion-with-the-language-construct-of-that-name-a-programmer-who-writes-a-program-that-uses-an-api-is-referred-to-as-a-user-of-the-api-a-class-whose-implementation-uses-an-api-is-a-client-of-the-api-1&quot;&gt;The term exported API, or simply API, refers to the classes, interfaces, constructors, members, and serialized forms by which a programmer accesses a class, interface, or package. (The term API, which is short for application programming interface, is used in preference to the otherwise preferable term interface to avoid confusion with the language construct of that name.) A programmer who writes a program that uses an API is referred to as a user of the API. A class whose implementation uses an API is a client of the API.&lt;/h1&gt;
&lt;p&gt;Effective Java, Third Edition (Joshua Bloch)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;您在位置 #375-380的标注&lt;/td&gt;
          &lt;td&gt;添加于 2018年9月19日星期三 下午9:31:58&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;classes-interfaces-constructors-members-and-serialized-forms-are-collectively-known-as-api-elements-an-exported-api-consists-of-the-api-elements-that-are-accessible-outside-of-the-package-that-defines-the-api-these-are-the-api-elements-that-any-client-can-use-and-the-author-of-the-api-commits-to-support-not-coincidentally-they-are-also-the-elements-for-which-the-javadoc-utility-generates-documentation-in-its-default-mode-of-operation-loosely-speaking-the-exported-api-of-a-package-consists-of-the-public-and-protected-members-and-constructors-of-every-public-class-or-interface-in-the-package&quot;&gt;Classes, interfaces, constructors, members, and serialized forms are collectively known as API elements. An exported API consists of the API elements that are accessible outside of the package that defines the API. These are the API elements that any client can use and the author of the API commits to support. Not coincidentally, they are also the elements for which the Javadoc utility generates documentation in its default mode of operation. Loosely speaking, the exported API of a package consists of the public and protected members and constructors of every public class or interface in the package.&lt;/h1&gt;
&lt;p&gt;Effective Java, Third Edition (Joshua Bloch)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;您在位置 #375-380的标注&lt;/td&gt;
          &lt;td&gt;添加于 2018年9月19日星期三 下午9:32:18&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;classes-interfaces-constructors-members-and-serialized-forms-are-collectively-known-as-api-elements-an-exported-api-consists-of-the-api-elements-that-are-accessible-outside-of-the-package-that-defines-the-api-these-are-the-api-elements-that-any-client-can-use-and-the-author-of-the-api-commits-to-support-not-coincidentally-they-are-also-the-elements-for-which-the-javadoc-utility-generates-documentation-in-its-default-mode-of-operation-loosely-speaking-the-exported-api-of-a-package-consists-of-the-public-and-protected-members-and-constructors-of-every-public-class-or-interface-in-the-package-1&quot;&gt;Classes, interfaces, constructors, members, and serialized forms are collectively known as API elements. An exported API consists of the API elements that are accessible outside of the package that defines the API. These are the API elements that any client can use and the author of the API commits to support. Not coincidentally, they are also the elements for which the Javadoc utility generates documentation in its default mode of operation. Loosely speaking, the exported API of a package consists of the public and protected members and constructors of every public class or interface in the package.&lt;/h1&gt;
&lt;p&gt;Effective Java, Third Edition (Joshua Bloch)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;您在位置 #380-381的标注&lt;/td&gt;
          &lt;td&gt;添加于 2018年9月19日星期三 下午9:32:38&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;module-system-was-added-to-the-platform-if-a-library-makes-use-of-the-module-system-its-exported-api-is-the-union-of-the-exported-apis-of-all-the-packages-exported-by-the-librarys-module-declaration&quot;&gt;module system was added to the platform. If a library makes use of the module system, its exported API is the union of the exported APIs of all the packages exported by the library’s module declaration.&lt;/h1&gt;

&lt;h1 id=&quot;note-template&quot;&gt;Note template&lt;/h1&gt;
&lt;h2 id=&quot;what-the-problem-to-solve&quot;&gt;What? The problem to solve&lt;/h2&gt;
&lt;h2 id=&quot;how-the-pattern&quot;&gt;How? The pattern&lt;/h2&gt;
&lt;h2 id=&quot;compare-other-solutions-and-patterns&quot;&gt;Compare? Other solutions and patterns,&lt;/h2&gt;
&lt;h2 id=&quot;benefits&quot;&gt;Benefits&lt;/h2&gt;
&lt;h2 id=&quot;shortcomings&quot;&gt;Shortcomings&lt;/h2&gt;
&lt;h2 id=&quot;where-to-use-and-where-not-examples&quot;&gt;Where to use and where not, examples&lt;/h2&gt;
&lt;h2 id=&quot;related-java-knowledge&quot;&gt;Related Java Knowledge&lt;/h2&gt;
&lt;h2 id=&quot;terminologies&quot;&gt;Terminologies&lt;/h2&gt;
&lt;h2 id=&quot;related-patterns--references&quot;&gt;Related patterns &amp;amp; references&lt;/h2&gt;</content><author><name></name></author><summary type="html">Effective Java, Third Edition (Joshua Bloch) 您在位置 #322-325的标注 添加于 2018年9月19日星期三 下午9:26:34</summary></entry><entry><title type="html">Effective Java Item 1</title><link href="https://kevkeyingli.github.io/Effective-Java-Item-1/" rel="alternate" type="text/html" title="Effective Java Item 1" /><published>2018-09-22T00:00:00+00:00</published><updated>2018-09-22T00:00:00+00:00</updated><id>https://kevkeyingli.github.io/Effective-Java-Item-1</id><content type="html" xml:base="https://kevkeyingli.github.io/Effective-Java-Item-1/">&lt;h1 id=&quot;chapter-2-creating-and-destroying-objects&quot;&gt;Chapter 2 Creating and Destroying Objects&lt;/h1&gt;

&lt;h2 id=&quot;item-1-consider-static-factory-methods-instead-of-constructors&quot;&gt;Item 1 Consider static factory methods instead of constructors:&lt;/h2&gt;

&lt;p&gt;A class can provide its clients with static factory methods instead of, or in addition to, public constructors. Providing a static factory method instead of a public constructor has both advantages and disadvantages.&lt;/p&gt;

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

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    public static Boolean valueOf(boolean b) {
          return b ? Boolean.TRUE : Boolean.FALSE;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;terminologies&quot;&gt;Terminologies&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;instance controlled&lt;/strong&gt;
The ability of static factory methods to return the same object from repeated invocations allows classes to maintain strict control over what instances exist at any time. Classes that do this are said to be instance-controlled.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;service provider frameworks&lt;/strong&gt; e.g. JDBC 
A service provider frameworks is a system in which providers implement a service, and the system makes the implementations available to clients, decoupling the clients from the implementation&lt;/p&gt;

&lt;p&gt;There are three essential components in a &lt;strong&gt;service provider framework&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;a &lt;em&gt;service interface&lt;/em&gt;, which represents an implementation;&lt;/li&gt;
  &lt;li&gt;a &lt;em&gt;provider registration API&lt;/em&gt;, which providers use to register implementations; and&lt;/li&gt;
  &lt;li&gt;a &lt;em&gt;service access API&lt;/em&gt;, which clients use to obtain instances of the service. The service access API may allow clients to specify criteria for choosing an implementation, return a default implementation, or let client cycle through all available implementations. This is the flexible static factory that forms the basis of the service provider framework.&lt;/li&gt;
  &lt;li&gt;An optional fourth component of a service provider framework is &lt;em&gt;a service provider interface&lt;/em&gt;, which describes a factory object that produce instances of the service interface.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are many variants of the service provider framework pattern:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;the service access api can return a richer service interface to client than the one furnished by providers. &lt;em&gt;Birdge pattern [Gamma 95]&lt;/em&gt;&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;Dependency injection framworks (Item 5)&lt;/em&gt; can be viewed as powerful service providers.&lt;/li&gt;
  &lt;li&gt;Since Java 6, the platform includes a general-purpose service provider framework, &lt;em&gt;java.util.ServiceLoader (Item 59)&lt;/em&gt;, which you should generally use&lt;/li&gt;
  &lt;li&gt;JDBC doesn’t use ServiceLoader, since it’s earlier.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;benefitsreasons&quot;&gt;Benefits/reasons:&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;Unlike constructors, &lt;strong&gt;static factory methods have names&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;a well-chosen name results in client code easier to read.&lt;/li&gt;
      &lt;li&gt;Creating multiple constructors with different param types is bad. replacing multiple constructors with same signature with static factory methods with carefully chosen names highlights their differences.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Unlike constructores, &lt;strong&gt;static factory methods are not required to create new object each time they’re called.&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;This allows &lt;em&gt;immutable classes[Item 17]&lt;/em&gt; to use preconstructed instances or cache and reuse constructed instances. e.g. Boolean never creates an object.&lt;/li&gt;
      &lt;li&gt;This is similar technique to &lt;em&gt;Flyweight pattern&lt;/em&gt;&lt;/li&gt;
      &lt;li&gt;improves performance, if equivalent object is requested often and expensive to create.&lt;/li&gt;
      &lt;li&gt;This ability makes the classes &lt;strong&gt;instance controlled&lt;/strong&gt;. There are several reasons to write instance-controlled classes.
        &lt;ul&gt;
          &lt;li&gt;Instance control allows a class to guarantee that it is a &lt;em&gt;singleton (Item 3)&lt;/em&gt; or &lt;em&gt;noninstantiable (Item 4)&lt;/em&gt;.&lt;/li&gt;
          &lt;li&gt;Also, it allows an &lt;em&gt;immutable value class (Item 17)&lt;/em&gt; to make the guarantee that no two equal instances exist: a.equals(b) if and only if a == b. This is the basis of the &lt;em&gt;Flyweight pattern [Gamma95]&lt;/em&gt;. &lt;em&gt;Enum types(item 34)&lt;/em&gt; provide this guarantee.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;A third advantage of static factory methods is that, unlike constructors, &lt;strong&gt;they can return an object of any subtype of their return type&lt;/strong&gt; -&amp;gt; great flexibility in choosing the class of the returned object.
    &lt;ul&gt;
      &lt;li&gt;One application of this flexibility is that an API can return objects without making their classes public. Hiding implementation classes in this fashion leads to a very compact API. This technique lends itself to &lt;em&gt;interface-based frameworks (Item 20)&lt;/em&gt;, where interfaces provide natural return types for static factory methods.
        &lt;blockquote&gt;
          &lt;p&gt;Prior to Java 8, interfaces couldn’t have static methods. By convention, static factory methods for an interface named Type were put in a &lt;em&gt;noninstantiable companion class (Item 4)&lt;/em&gt; named Types.”  java.util.collections has 45 convenience implementations of its collection interface, nearly all of these implementations are exported via static factory methods in one non-instantiable class java.util.Collections, the classes of the returned objects are all non-public. examples: java.util.Collections and java.util.EnumSet(Item 36).
The Collections Framework API is much smaller than it would have been had it exported forty-five separate public classes, one for each convenience implementation. It is not just the bulk of the API that is reduced but the conceptual weight: the number and difficulty of the concepts that programmers must master in order to use the API.
Java 8 requires all static members of an interface to be public. Java 9 allows private static methods, but static fields and static member classes are still required to be public.&lt;/p&gt;
        &lt;/blockquote&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;A fourth advantage of static factories is that the class of the returned object can vary from call to call as a function of the input parameters. Any subtype of the declared return type is permissible.&lt;/li&gt;
  &lt;li&gt;A fifth advantage of static factories is that the class of the returned object need not exist when the class containing the method is written.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;##Limitation/Shortcoming&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The main limitation of providing only static factory methods is that classes without public or protected constructors cannot be subclassed.
    &lt;ul&gt;
      &lt;li&gt;Arguably this can be a blessing in disguise because it encourages programmers to &lt;em&gt;use composition instead of inheritance (Item 18)&lt;/em&gt;, and is required for &lt;em&gt;immutable types (Item 17)&lt;/em&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;A second shortcoming of static factory methods is that they are hard for programmers to find. They don’t stand out in API docs as constructors. In the meantime, you can reduce this problem by drawing attention to static factories in class or interface documentation and by adhering to &lt;strong&gt;common naming conventions&lt;/strong&gt;. Here are some common names for static factory methods.
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;from&lt;/code&gt; – A type-conversion method&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;of&lt;/code&gt; – An aggregation method&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;valueOf&lt;/code&gt; – A more verbose alternative to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;from&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;of&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;instance&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getInstance&lt;/code&gt; reutnrs an instance that is described by its parameters&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;create&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;newInstance&lt;/code&gt; each call should guarantee to return a &lt;strong&gt;new&lt;/strong&gt; instance.&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;get[Type]&lt;/code&gt; like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getInstance&lt;/code&gt;, but returns instance of a different class indicated by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Type&lt;/code&gt; in the name. e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getFileStore&lt;/code&gt;.&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new[Type]&lt;/code&gt; like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;newInstance&lt;/code&gt;, but returns a new instance of a different class. e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;newBufferedReader()&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[type]&lt;/code&gt;: a concise alternative to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;get[Type]&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new[Type]&lt;/code&gt; e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collections.list()&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;
&lt;p&gt;Static factory and constructors both have their uses, and it pays to understand their relative merits. &lt;strong&gt;Often static factories are preferable, so avoid the reflex to provide public constructors without first considering static factories.&lt;/strong&gt;&lt;/p&gt;

&lt;h2 id=&quot;related-java-knowledge&quot;&gt;Related Java Knowledge&lt;/h2&gt;
&lt;p&gt;Java 8 requires all static members of an interface to be public. Java 9 allows private static methods, but static fields and static member classes are still required to be public.&lt;/p&gt;

&lt;h2 id=&quot;related-patterns--references&quot;&gt;Related patterns &amp;amp; references&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Flyweight pattern&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;immutable classes[Item 17]&lt;/em&gt;&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;singleton (Item 3)&lt;/em&gt;&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;noninstantiable (Item 4)&lt;/em&gt;&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;Enum types(item 34)&lt;/em&gt;&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;noninstantiable companion class (Item 4)&lt;/em&gt;&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;refering to returned object by interface rather than implementation class is good practice(Item 64)&lt;/em&gt;&lt;/li&gt;
  &lt;li&gt;The enumSet class (Item 36 )&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;use composition instead of inheritance (Item 18)&lt;/em&gt;&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;immutable types (Item 17)&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><summary type="html">Chapter 2 Creating and Destroying Objects</summary></entry><entry><title type="html">Effective Java Item 2</title><link href="https://kevkeyingli.github.io/Effective-Java-Item-2/" rel="alternate" type="text/html" title="Effective Java Item 2" /><published>2018-09-22T00:00:00+00:00</published><updated>2018-09-22T00:00:00+00:00</updated><id>https://kevkeyingli.github.io/Effective-Java-Item-2</id><content type="html" xml:base="https://kevkeyingli.github.io/Effective-Java-Item-2/"></content><author><name></name></author><summary type="html"></summary></entry><entry><title type="html">… in JS</title><link href="https://kevkeyingli.github.io/.-in-JS/" rel="alternate" type="text/html" title="… in JS" /><published>2017-09-10T00:00:00+00:00</published><updated>2017-09-10T00:00:00+00:00</updated><id>https://kevkeyingli.github.io/...-in-JS</id><content type="html" xml:base="https://kevkeyingli.github.io/.-in-JS/">&lt;p&gt;“…” is an important new feature in ES6, that brings simplicity and elegance to JS.&lt;/p&gt;

&lt;p&gt;Briefly the … three dots actually have two different identities in different scenarios. &lt;strong&gt;Spread Syntax(Operators)&lt;/strong&gt; and &lt;strong&gt;Rest Syntax(Parameters)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;As MDN described it:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Spread syntax&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;allows an iterable such as an array expression to be &lt;strong&gt;expanded&lt;/strong&gt; in places where zero or more arguments (for function calls) or elements (for array literals) are expected,&lt;/li&gt;
  &lt;li&gt;or an object expression to be &lt;strong&gt;expanded&lt;/strong&gt; in places where zero or more key-value pairs (for object literals) are expected.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Rest Parameters&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The rest parameter syntax allows us to represent an &lt;strong&gt;indefinite number of arguments as an array&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The names are self-explanatory. **Spread operator operates on, and expands array or object. while rest parameters represent the rest parameters in a function definition. **&lt;/p&gt;

&lt;p&gt;For examples of these two use cases, go to the MDN site which includes a good number of different ways of using …:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator&lt;/li&gt;
  &lt;li&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a little history of how … changed javascript and life of millions of developers, here is a good article:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;https://dmitripavlutin.com/how-three-dots-changed-javascript/&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><summary type="html">“…” is an important new feature in ES6, that brings simplicity and elegance to JS.</summary></entry><entry><title type="html">Useful Technical Resources</title><link href="https://kevkeyingli.github.io/Useful-Technical-Resources/" rel="alternate" type="text/html" title="Useful Technical Resources" /><published>2017-05-24T00:00:00+00:00</published><updated>2017-05-24T00:00:00+00:00</updated><id>https://kevkeyingli.github.io/Useful-Technical-Resources</id><content type="html" xml:base="https://kevkeyingli.github.io/Useful-Technical-Resources/">&lt;p&gt;Free books from oreilly
http://www.oreilly.com/programming/free/&lt;/p&gt;

&lt;h2 id=&quot;javascript&quot;&gt;Javascript&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Best Javascript doc site: MDN&lt;/li&gt;
  &lt;li&gt;A re-introduction to JavaScript (JS tutorial by MDN) https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><summary type="html">Free books from oreilly http://www.oreilly.com/programming/free/</summary></entry><entry><title type="html">MongoDB Quick Start</title><link href="https://kevkeyingli.github.io/MongoDB/" rel="alternate" type="text/html" title="MongoDB Quick Start" /><published>2016-10-28T00:00:00+00:00</published><updated>2016-10-28T00:00:00+00:00</updated><id>https://kevkeyingli.github.io/MongoDB</id><content type="html" xml:base="https://kevkeyingli.github.io/MongoDB/">&lt;p&gt;This learning note follows the tutorial &lt;a href=&quot;https://www.youtube.com/watch?v=pWbMrx5rVBE&quot;&gt;MongoDB In 30 Minutes&lt;/a&gt; on Youtube.&lt;/p&gt;

&lt;h2 id=&quot;set-up&quot;&gt;Set up&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Download and install&lt;/li&gt;
  &lt;li&gt;make a few folders where you want to store your database&lt;/li&gt;
  &lt;li&gt;and set the path to be used by mongodb:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mongod --directoryperdb --path 'directory' --logpath 'logpath/mongo.log' --logappend --rest --install&lt;/code&gt; installs the mongodb as a rest service&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Now we can run the service: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;net start MongoDB&lt;/code&gt;(This is for windows only). the MongoDB now can run on the background as a service.&lt;/li&gt;
  &lt;li&gt;type in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mongo&lt;/code&gt; and you are in the mongoDB shell.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;usual-commands&quot;&gt;Usual commands&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;show dbs&lt;/code&gt;: shows all the databases, don;t touch the default database &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;local&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;use databasename&lt;/code&gt;: creates a new database&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db&lt;/code&gt; shows you the current database you are in.&lt;/li&gt;
  &lt;li&gt;MongoDB use JSON format to interact with data. Can contain: string, number, array, objects, basically any normal data structure.&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;to create a user:&lt;/p&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  db.createUser({
      user:&quot;username&quot;,
      pwd:&quot;password&quot;,
      roles:[&quot;roles of the user&quot;]
  });
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db.createCollection('customers')&lt;/code&gt; create a collection(table)&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;show collections&lt;/code&gt; will show all the collections&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db.customers.insert({one json like entry})&lt;/code&gt;, note that ‘customer’&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everytime a new entry is inserted, an id is assigned.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db.customers.find()&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db.customers.find().pretty()&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db.customers.update({first_name:&quot;John&quot;},{first_name:&quot;John&quot;, last_name:&quot;...&quot;, })&lt;/code&gt;: replace an entry with a new entry, The ID does not change. The first parameter is used as a condition like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WHERE&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;How to update only one field(change/add/delete): Use operators : &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$set&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$inc&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$unset&lt;/code&gt;&lt;/p&gt;

    &lt;p&gt;db.customers.update({condition},{$$$set:{gender:”male”}})
  db.customers.update({condition},{$$$inc:{age:5}})
  db.customers.update({first_name:”Steve”},{$$$unset:{age}})&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db.customers.update({first_name:&quot;NoExistName&quot;},{first_name:&quot;NoExistName&quot;, last_name:&quot;K&quot;,},{upsert:true}); &lt;/code&gt; we can add a new entry if it is not find.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db.customers.update({condition},{$rename:{&quot;gender&quot;:&quot;sex&quot;});&lt;/code&gt;: change attribute name&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db.customer.remove({conditions},{justOne:true})&lt;/code&gt;remove the matching entries, if &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;justOne&lt;/code&gt; is not specified, all matches will be deleted.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db.customers.find($or:[{condition one},{condition two}])&lt;/code&gt; using logic operator.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$lt&lt;/code&gt;,&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$gt&lt;/code&gt;,&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$lte&lt;/code&gt;,&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$gte&lt;/code&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db.customers.find({age:{$lt:40}}).pretty();&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db.customers.find({&quot;address.city&quot;:&quot;Boston&quot;});&lt;/code&gt; : using attribute of attribute(member of dictionary, which is also a member of a dictionary). &lt;strong&gt;Note&lt;/strong&gt;: dontforget the quots in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;address.city&quot;&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Last one queried a &lt;strong&gt;Dictionary&lt;/strong&gt;, we can also query an &lt;strong&gt;Array&lt;/strong&gt;. For example, every/some entries have attribute &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;membership=['mem1','mem2']&lt;/code&gt; which is an array containing different kinds of memberships. we can do: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db.customers.find({membership:&quot;mem1&quot;});&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Sorting by some attribute: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db.customer.find().sort({last_name:1}).pretty()&lt;/code&gt;. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt; for ascending, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-1&lt;/code&gt; for descending.&lt;/li&gt;
  &lt;li&gt;Count documents: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db.customers.find({conditions}).count();&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Set limit: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db.customers.find({conditions}).limit(4).sort({last_name:1});&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Iterate using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;forEach&lt;/code&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db.customers.find().forEach(function(doc){print(doc.first_name)});&lt;/code&gt; this could call javascript function.&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Kevin</name></author><summary type="html">This learning note follows the tutorial MongoDB In 30 Minutes on Youtube.</summary></entry><entry><title type="html">Reading note for introduction to algorithms</title><link href="https://kevkeyingli.github.io/Reading-note-for-Introduction-to-Algorithms/" rel="alternate" type="text/html" title="Reading note for introduction to algorithms" /><published>2016-08-15T00:00:00+00:00</published><updated>2016-08-15T00:00:00+00:00</updated><id>https://kevkeyingli.github.io/Reading%20note%20for%20Introduction%20to%20Algorithms</id><content type="html" xml:base="https://kevkeyingli.github.io/Reading-note-for-Introduction-to-Algorithms/">&lt;h1 id=&quot;reading-note-for-introduction-to-algorithms&quot;&gt;Reading note for Introduction to Algorithms&lt;/h1&gt;

&lt;h2 id=&quot;foundations&quot;&gt;Foundations&lt;/h2&gt;

&lt;h2 id=&quot;and-order-statistics&quot;&gt;and Order Statistics&lt;/h2&gt;

&lt;h2 id=&quot;data-structures&quot;&gt;Data Structures&lt;/h2&gt;

&lt;h2 id=&quot;advanced-design-and-analysis-techniques&quot;&gt;Advanced Design and Analysis Techniques&lt;/h2&gt;

&lt;h3 id=&quot;dynamic-programming&quot;&gt;Dynamic Programming&lt;/h3&gt;
&lt;p&gt;DP is typically used for solving optimization problems, there are basically four steps:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Characterize the structure of an optimal solution&lt;/li&gt;
  &lt;li&gt;Recursively define the value of an optimal solution&lt;/li&gt;
  &lt;li&gt;compute the value of an optimal solution, typically in a bottom-up fashion(top-down memoization is also usable some times)&lt;/li&gt;
  &lt;li&gt;Construct an optimal solution from the computed information(Interview questions might not need this)
    &lt;h2 id=&quot;151-rod-cutting-problem&quot;&gt;15.1 Rod cutting problem&lt;/h2&gt;
    &lt;p&gt;Rod cutting problem exhibits &lt;strong&gt;optimal substructure&lt;/strong&gt;: optimal solution to a problem incorpporate optimal solution to related &lt;strong&gt;subproblems&lt;/strong&gt;, which we may solve &lt;strong&gt;independently&lt;/strong&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The biggest benefit of DP is to reduce the overlapping/wasted computations. Basically two ways&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;top-down memoization: recursive way, but stores information when backtracking&lt;/li&gt;
  &lt;li&gt;bottom up memorization: iterative way usually, going through all unique sub problems.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;DP is an example of &lt;em&gt;time-memory tradoff&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A DP approach runs in polynomial time when the number of distinct subproblems involved is polynomial in the input size and we can solve each such subproblem in polynomial time.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Bottom-up method&lt;/strong&gt;, we sort the subproblems by size and solve them in size order, smallest first.&lt;/p&gt;

&lt;p&gt;In some cases, top-down method might be faster than bottom up solution, since some subproblems that the latter computed, might not be used in constructing final solution.&lt;/p&gt;
&lt;h3 id=&quot;sub-problem-graph&quot;&gt;Sub problem graph&lt;/h3&gt;
&lt;p&gt;Sub problem graph&lt;/p&gt;
&lt;h2 id=&quot;152-parenthesis-matrix-chain-multiplication&quot;&gt;15.2 Parenthesis Matrix Chain Multiplication&lt;/h2&gt;

&lt;h2 id=&quot;my-thinking-after-these-two-examples&quot;&gt;My thinking after these two examples:&lt;/h2&gt;
&lt;h3 id=&quot;on-their-difference&quot;&gt;On their difference:&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Why rod cutting is cutting off one piece every time while matrix multiplication, splits the problem into two subproblems?&lt;/li&gt;
  &lt;li&gt;What if each cut has a cost for &lt;em&gt;rod cutting&lt;/em&gt;&lt;/li&gt;
  &lt;li&gt;What is the difference of their representation? Why
    &lt;ul&gt;
      &lt;li&gt;rod cutting only need to keep track of one index to identify the sub problem, while matrix multiplication, uses two indices to keep track of which problem is tracked.&lt;/li&gt;
      &lt;li&gt;This indicates the space/time complexity of the solution&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Representation of the problem determines the complexity of the problem&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;another-way-to-think-about-it&quot;&gt;Another way to think about it:&lt;/h3&gt;
&lt;p&gt;The book gives us a quite standard way to think about this problem:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Optimal structure of problems and subproblems, first break down the optimal problem into combination of smaller &lt;strong&gt;Independent&lt;/strong&gt; optimal subproblems.&lt;/li&gt;
  &lt;li&gt;Use spcae to assist computation, and reduce redundant compuation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I am thinking may be we can think it in a different way, just for fun. When you are givin a optimization problem:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;first start off think from the smallest problems, base situations.&lt;/li&gt;
  &lt;li&gt;Solve every base problems, and to see if you could, combine that information to build up a solution for second level problem.&lt;/li&gt;
  &lt;li&gt;Keep going from there…&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This way of thinking follows the same step of the bottom up method:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Rod - cutting, build a tabular that comtains all possible lengths, from the shortest possible, and grow one step at a time.&lt;/li&gt;
  &lt;li&gt;Parenthesize Matrix Multiplication: Start off compute the cost of multiplying all matrix pairs, then triplets, then for consecutive matrixs…Each step built on the previous.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, consider the all possible solution for these problems, the number of all possible solution is usually exponential, but by computing the small element and build the solution bottom up, will avoid overlapping compuatioin&lt;/p&gt;

&lt;h3 id=&quot;greedy-aglorithms&quot;&gt;Greedy Aglorithms&lt;/h3&gt;

&lt;h3 id=&quot;amortized-analysis&quot;&gt;Amortized Analysis&lt;/h3&gt;

&lt;h2 id=&quot;advanced-data-structures&quot;&gt;Advanced Data Structures&lt;/h2&gt;

&lt;p&gt;(trees Sets)&lt;/p&gt;

&lt;h2 id=&quot;graph-algorithms&quot;&gt;Graph Algorithms&lt;/h2&gt;

&lt;h3 id=&quot;22-elementary-graph-algorithms&quot;&gt;22 Elementary Graph Algorithms&lt;/h3&gt;

&lt;h3 id=&quot;23-minimum-spanning-tree&quot;&gt;23 Minimum Spanning Tree&lt;/h3&gt;

&lt;h3 id=&quot;24-single-source-shortest-paths-643&quot;&gt;24 Single-Source Shortest Paths 643&lt;/h3&gt;

&lt;p&gt;####24.1 The Bellman-Ford algorithm 651&lt;/p&gt;

&lt;p&gt;####24.2 Single-source shortest paths in directed acyclic graphs&lt;/p&gt;

&lt;h4 id=&quot;243-dijkstras-algorithm-658&quot;&gt;24.3 Dijkstra’s algorithm 658&lt;/h4&gt;

&lt;p&gt;####24.4 Difference constraints and shortest paths 664&lt;/p&gt;

&lt;h4 id=&quot;245-proofs-of-shortest-paths-properties-671&quot;&gt;24.5 Proofs of shortest-paths properties 671&lt;/h4&gt;

&lt;h3 id=&quot;25-all-pairs-shortest-paths-684&quot;&gt;25 All-Pairs Shortest Paths 684&lt;/h3&gt;

&lt;h4 id=&quot;251-shortest-paths-and-matrix-multiplication&quot;&gt;25.1 Shortest paths and matrix multiplication&lt;/h4&gt;

&lt;h4 id=&quot;252-the-floyd-warshall-algorithm-693&quot;&gt;25.2 The Floyd-Warshall algorithm 693&lt;/h4&gt;

&lt;h4 id=&quot;253-johnsons-algorithm-for-sparse-graphs&quot;&gt;25.3 Johnson’s algorithm for sparse graphs&lt;/h4&gt;

&lt;h3 id=&quot;26-maximum-flow-708&quot;&gt;26 Maximum Flow 708&lt;/h3&gt;

&lt;h4 id=&quot;261-flow-networks-709&quot;&gt;26.1 Flow networks 709&lt;/h4&gt;

&lt;h4 id=&quot;262-the-ford-fulkerson-method-714&quot;&gt;26.2 The Ford-Fulkerson method 714&lt;/h4&gt;

&lt;h4 id=&quot;263-maximum-bipartite-matching-732&quot;&gt;26.3 Maximum bipartite matching 732&lt;/h4&gt;

&lt;h2 id=&quot;selected-topics&quot;&gt;Selected Topics&lt;/h2&gt;</content><author><name></name></author><summary type="html">Reading note for Introduction to Algorithms</summary></entry><entry><title type="html">Angular2 Service and Dependency Injection Learning Note</title><link href="https://kevkeyingli.github.io/Angular-Service-and-Dependency-Injection/" rel="alternate" type="text/html" title="Angular2 Service and Dependency Injection Learning Note" /><published>2016-08-05T00:00:00+00:00</published><updated>2016-08-05T00:00:00+00:00</updated><id>https://kevkeyingli.github.io/Angular-Service-and-Dependency-Injection</id><content type="html" xml:base="https://kevkeyingli.github.io/Angular-Service-and-Dependency-Injection/">&lt;p&gt;Service is an important design choice in angular 2, the idea is to keep components lean. Here I will cover what I learned about using service and dependency injection. A nice and more detailed resource to look at: https://angular.io/docs/ts/latest/guide/architecture.html&lt;/p&gt;

&lt;h3 id=&quot;service&quot;&gt;Service&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Service is intended to provide service for component. To separate operational logic from component(so component can focus on controling the view)&lt;/li&gt;
  &lt;li&gt;The code in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;service.ts&lt;/code&gt; file defines the &lt;strong&gt;service class&lt;/strong&gt;, which acts as a prototype for service instances.&lt;/li&gt;
  &lt;li&gt;The thing that is injected into components is &lt;strong&gt;service instance&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;component&quot;&gt;Component&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;responsible of defining and controling views, each view/tag can be considered as a &lt;strong&gt;component instance&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;In component, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;constructor&lt;/code&gt; determines/specifies which service will be used.&lt;/li&gt;
  &lt;li&gt;In the component constructor, we usually see &lt;em&gt;service instances&lt;/em&gt;,&lt;em&gt;member variables&lt;/em&gt;, ?(variable from other module? like child module?)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;providers-array&quot;&gt;Providers Array&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;To use a service in a component, we need to register the service as a service provider, so the &lt;em&gt;injector&lt;/em&gt; will know how to create instances.&lt;/li&gt;
  &lt;li&gt;Can register a service as a provider in mainly two ways:
    &lt;ul&gt;
      &lt;li&gt;register it in the provider array&lt;/li&gt;
      &lt;li&gt;register when bootstrap&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Provide different granuality/coverage&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;injector&quot;&gt;Injector&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Injector is used to
    &lt;ul&gt;
      &lt;li&gt;create/maintain service instances.&lt;/li&gt;
      &lt;li&gt;According to the providers&lt;/li&gt;
      &lt;li&gt;before the constructor of a component can be called&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Additionally you need to import the service class in the component to use it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;to-use-a-service-in-a-component&quot;&gt;To use a service in a component:&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Import the service in the component&lt;/li&gt;
  &lt;li&gt;Include it in the component’s provider array, or bootstrap the service already&lt;/li&gt;
  &lt;li&gt;Declare a instance of the service in the constructor of the component, so each component can have a service instance.&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Kevin</name></author><summary type="html">Service is an important design choice in angular 2, the idea is to keep components lean. Here I will cover what I learned about using service and dependency injection. A nice and more detailed resource to look at: https://angular.io/docs/ts/latest/guide/architecture.html</summary></entry><entry><title type="html">Problems questions and solutions</title><link href="https://kevkeyingli.github.io/Problems-Questions-and-Solutions/" rel="alternate" type="text/html" title="Problems questions and solutions" /><published>2016-07-22T00:00:00+00:00</published><updated>2016-07-22T00:00:00+00:00</updated><id>https://kevkeyingli.github.io/Problems%20Questions%20and%20Solutions</id><content type="html" xml:base="https://kevkeyingli.github.io/Problems-Questions-and-Solutions/">&lt;p&gt;I start this post in the idea of collecting and centralizing technical problems and questions that I have through my work and study. It is a place to revisit if similar problem re-occurs or some knowledge fades away. I will keep adding new things into here, as well as collect the scattered notes of the past.&lt;/p&gt;

&lt;h1 id=&quot;keep-ssh-sessions-running-after-disconnection-and-resume-it-later&quot;&gt;Keep SSH Sessions running after disconnection, and resume it later&lt;/h1&gt;
&lt;p&gt;from http://unix.stackexchange.com/questions/479/keep-ssh-sessions-running-after-disconnection?newreg=54f0dfa60fde4ed7881d617ab7a8a447&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Use nohup to make your process ignore the hangup signal:&lt;/p&gt;

    &lt;p&gt;$ nohup long-running-process &amp;amp;
  $ exit&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;You want to be using GNU Screen. It is super awesome!&lt;/p&gt;

    &lt;p&gt;ssh me@myserver.com
  screen               #start a screen session
  run-a-long-process&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;CTRL+a , d to detatch from your screen session&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;exit                 #disconnect from the server, while run-a-long-process continues When you come back to your laptop:

ssh me@myserver.com
screen -r            #resume the screen session Then check out the progress of your long-running process!
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;screen is a very comprehensive tool, and can do a lot more than what I’ve described. While in a screen session, try ctrl+a,? to learn a few common commands. Probably the most common are:&lt;/p&gt;

&lt;p&gt;CTRL+a , c to create a new window
CTRL+a , n to switch to the next window in your screen session
CTRL+a , p to switch to the previous window in your screen session
if you log in from a bunch of different systems, you may have accidentally left yourself attached to an active screen session on a different computer. for that reason, I always resume with screen -d -r to ensure that if another shell is attached to my screen session, it will be detached before I resume it on my current system.&lt;/p&gt;

&lt;p&gt;Other valuable answers:
http://unix.stackexchange.com/questions/89483/keeping-a-process-running-after-putty-or-terminal-has-been-closed
Screen Manual is here: https://www.gnu.org/software/screen/manual/screen.html&lt;/p&gt;</content><author><name></name></author><summary type="html">I start this post in the idea of collecting and centralizing technical problems and questions that I have through my work and study. It is a place to revisit if similar problem re-occurs or some knowledge fades away. I will keep adding new things into here, as well as collect the scattered notes of the past.</summary></entry></feed>