Item 57: Minimize the scope of local variables

Declare the variable where it is first usedThe reader will not be distracted to figure out where the variable is declared Prefer for loops to while loops, assuming the contents of the loop variable aren’t needed after the loop terminates. Advantages of for lops over while loops Eliminate copy-paste errors Shorter and more readable Declare […]

Item 25: Limit source files to a single top-level class

Never put multiple top-level classes or interfaces in a single source file. Following this rule guarantees that you can’t have multiple definitions for a single class at compile time.

Item 22: Use interfaces only to define types

Interfaces should be used only to define types. They should not be used merely to export constants. The constant interface pattern is a poor use of interfaces If the constants are best viewed as members of an enumerated type, you should export them with an enum type (Item 34) If the constants are NOT strongly […]

Item 20: Prefer interfaces to abstract classes

Advantages Existing classes can easily be reconstructed to implement a new interface. You just need to use implements clause to the class declaration and add the required methods Interfaces are ideal for defining mixins (Example: Interfaces allow for the construction of non-hierarchical type frameworks. They are great for organizing things that don’t fall into a hierarchy […]

Item 18: Favor composition over inheritance

Inheritance violates encapsulation unless the superclass’s authors have designed it specifically for the purpose of being extended The superclass’s implementation may change from release to release, and if it does, the subclass may break, even though its code has not been touched. As a consequence, a subclass must evolve in tandem with its superclass, unless […]

Item 17: Minimize Mutability

An immutable class is simply a class whose instances cannot be modified. All of the information contained in each instance is fixed for the lifetime of the object, so no changes can ever be observed. An immutable object can be in exactly one state, the state in which it was created Immutable objects are inherently […]

Item 15: Minimize the accessibility of classes and members

Encapsulation A well-designed component hides all its implementation details, cleanly separating its API from its implementation. Components then communicate only through their APIs and are oblivious to each others’ inner workings. This concept, known as information hiding or encapsulation, is a fundamental tenet of software design. The advantages of encapsulation are as follows: Speeds up […]

Spring: Big Picture

What is Spring? Spring makes it easy to create Java enterprise applications.It is a complimentary to Java EE. Spring is open source. It has a large and active community. Spring 5.0 requires JDK 8+ and provides out-of-the-box support for JDK 9. Fundation: Spring Framework The Spring Framework is an application framework and inversion of control container for the Java […]

Useful commands for SSL certificates

Generate self signed certificate and export to truststore 1. Generate a certificate using keygen command in windows keytool -genkey -alias myAlias -keyalg RSA -sigalg SHA256withRSA -keystore keystore.jks -validity 10950 2. Self certify the csertificate keytool -selfcert -alias mycert-20161109 -keystore keystore.jks -validity 3950 3. Export certificate to folder keytool -export -alias myAlias -keystore keystore.jks -rfc -file […]