Skip to main content

Posts

Showing posts from 2017

HTTP2 Server Push in Apache2

Server Push is one of the most significant features in the HTTP/2 protocol. In this post, We will see a very simple demo of the Server Push feature using HTTP/2. Below is the list of tools and tech used in the demo. Ubuntu 16.04 Chrome 60.0.3112.101 Apache2 Some browsers require TLS 1.2 to support HTTP/2. So We need to configure https on Apache server. Try to open the URL https://localhost in your browser. If the above URL not responding, It means you need to configure HTTPS on your Apache server. Please refer to the digital ocean page. https://www.digitalocean.com/community/tutorials/how-to-create-a-ssl-certificate-on-apache-for-ubuntu-14-04 I hope the URL https://localhost is working now and We can proceed further. We will do it into 2 parts. Part-I: We will just enable the HTTP/2 protocol Part-II: We will configure server push feature Part-I: Enable HTTP/2 First, check the below points. Make sure you have the http2 module in your apache. Naviga

Decorator Pattern : Real Life Example and Java Code Example

Decorator Pattern The Decorator Pattern provides a mechanism to dynamically attach the additional responsibilities to an object at runtime. Inheritance also provides the same but it is not flexible and does statically. We will see further in detail why Inheritance is not a good option as compared to Decorator Pattern. One important thing about the Decorator Pattern, It does not affect the core functionality just attach some additional. Real Life Example: Take the example of a bicycle store. When someone comes to buy a bicycle, The distributor shows the basic bicycle with core functionalities. After selecting the bicycle, He asks for the accessories you want to attach. Suppose there are accessories like carrier,stand-leg,front-light,front-box,bike-bell. The service man decorates your bicycle with accessories(additional functionalities without affecting the core functionality) as per your requirement. Java Code Example: We will try to implement the above real life exam

Factory Pattern : Real Life Example and Java Code Example

Factory Pattern The Factory Pattern is actually a method(factory method) which is used to create objects on the basis of runtime requirements. Real Life Example: The factory method is same as the real world factory, It gives the same kind of object with different(based on the input) behavior. For example, There is a machine in a factory which takes wood and paints as input and gives a painted box as the final product. We can create different boxes by just changing the color of paint in the input. Java Code Example: Before going to codes, We need to see some key points about factory method implementation. We need an interface(Suppose A is an interface). Then We need various implementations of A (Suppose B, C, D are implementing A). Finally, We need a Factory class with a factory method. The factory method must have the return type of A. Find the below problem and its solution using the factory method. Suppose We need to build an application KNOW ABOUT ANIMALS. The a

Singleton Pattern : Real Life Example and Java Code Example

Singleton Pattern The Singleton pattern uses to prevent the instantiation of an Object or creating a new one. It is used when We need only one instance in the whole application. The singleton is similar to global variables and we can find many debates over singleton vs global variables on the internet. We can choose between singleton and global variables based on the application context, But global variables violate the encapsulation policy of OOP concepts. Real Life Example: The DataSource is very good example of a singleton pattern. We initialize DataSourcet object by some parameters like host,port,user and password. Every time We need the DataSource, the values of the parameters remains same So We need exactly one instance of DataSource. Java Code Example: There is the various implementation of the singleton, based on the initialization like eager, lazy, static block and thread safe. Below implementation called Bill Pugh Singleton Implementation is simplest and also threa

How to Open a File in Vim Editor without Navigating through all the nested Directories

                      O ne day I was working on something and I needed to modify the configuration file on the server. So I had to navigate to all the way through nested directories and then finally edit the file. The requirement was quite frequent and every time I had to navigate to multiple directories. This post is about to simplify the above task. For example, We need to edit the following file. File path : /home/alex/Softwares/apache-tomcat-7.0.62/webapps/live-service/WEB-INF/classes/conf/database/database.conf We can do it by using the below command: alex:~$ vim /home/alex/Softwares/apache-tomcat-7.0.62/webapps/live-service/WEB-INF/classes/conf/database/database.conf If we count the nested directories, There are 10 directories We need to navigate through and It is cumbersome even we know the exact path of the file. We will try to do something which can reduce the effort of navigating to nested directories. eg. The below command will work as above vim command. alex:~$