Posts

Reactive Programming with Observables in RxJS and Angular

We have seen that now a days reactive programming has changed the whole structure of how we develop our web application. Reactive programming is a programming paradigm that works with asynchronous data streams.It treats everything as a stream ordered in time and this stream can be generated by Http Requests, UI Events or array-like objects etc. RxJS is one of the implementation in javascript of ReactiveX API.These API can be used with many others languages such as Java, C#, Python, PHP, ruby etc. It is a library for composing asynchronous and event-based programs by using observable sequences for reactive programming In this post we will deep dive how RxJS observables are being used with Angular to do reactive programming and different operator which RxJs provides to handle the data well. So Let's start from observables first . What are Observables ?    Observables are nothing but a stream of data whose data arrive asynchronously .These data streams can be of anythi

Deploy standalone Spring MVC Application in Docker Container

Image
In this post we will deploy simple standalone spring mvc application in Docker container. If you want to deploy the spring boot application in docker container, you can check my post Containerize Spring Boot application using Docker   . We know that in spring boot application there is embed Tomcat application server and run our app on top of it but in case of standalone spring mvc application we don't have embed Tomcat server , hence we need to deploy the application in explicit tomcat standalone server. Process to deploy the spring mvc in docker container : 1) First we need to get the Tomcat image. 2) Second to deploy the war in tomcat we need to save it in tomcat webapps direcory. Create Docker file  FROM : Using docker FROM command we are fetching the tomcat image from the Docker Hub. COPY : In the second line we are copying the war file in tomcat webapp directory. Note :  Any war saved in the tomcat webapps folder will be installed on tomcat start up. Yo

Containerize Spring Boot Application using Docker

Image
In this post we will deploy the simple Spring Boot Hello World application into Docker container. Going through,  we will see some other important concepts like how to go inside docker container and verify the images created. To deploy the Jar file into container, we will use the docker own build form i.e. Dockerfile. A Dockerfile is in principle, a linewise batch file, containing commands to build an image. It’s not absolutely necessary to put these commands into a file, because we’re able to pass them to the command-line, as well – a file is simply more convenient. Set up Spring Boot Application The following project can be cloned from official git repository in order to run the basic example of spring boot application inside a container. $git clone https://github.com/spring-guides/gs-spring-boot-docker.git Its a simple Hello world application. The code for the java file is as below : Create Dockerfile Docker has a simple Dockerfile file format that it uses t

Refactor Code : Separate Query from Modifier

In this post we will learn about the one of the important code refactoring algorithm "Separate Query from Modifier" .When you have a method that gives you a value and has no observable side effects, you have a lot less to worry. You can move the call to other places in this method freely. A good rule to follow is to say that any method that returns a value should not have other observable side effects.  You have a method that returns a value but also changes the state of an object . Create two method, one for the query and one for the modification. We first take the example of the below and will find out what is wrong with this code and refactor it. In the above , method findMiscreant(List<Person> people) signifies that its responsibility will be to find miscreant only. But if we give clear look to the method , apart from finding Miscreant , it is sending some notification as   SendAlert()  to other system . Hence we can easily see that this method is doi

Design a parking lot using object-oriented principles?

Image
To design the parking lot system , we will make our own assumption to start with . So that we could keep our design simple and easy to grasp what is happening . As we would  be done with the development as per our first assumption. We will gradually increase the dimension of our assumption and enhance the system accordingly. Our assumption are as below: 1) Parking lot is only ground floor , so there is no multiple level i.e there is only one level. 2) Parking lot has three different kind of parking lot : small parking lot, medium parking lot and large parking lot. 3) There are three different kind of vehicle which needs to be parked. 4) Motorcycle needs to be parked in small parking lot , car needs to be parked in medium parking lot and bus needs to be parked in large parking lot. As we can see that motorcycle and bus all comes in the category of vehicle. So we will be using the inheritance property of OOPS and will create vehicle abstract class and will keep the

Covariant Return Type in Java

Before JDK 5.0, it was not possible to override a method by changing the return type. When we override a parent class method, the name, argument types and return type of the overriding method in child class has to be exactly same as that of parent class method. Overriding method was said to be invariant with respect to return type. Java 5.0 onwards it is possible to have different return type for a overriding method in child class, but child’s return type should be sub-type of parent’s return type. Overriding method becomes variant with respect to return type. Co-variant return type is based on Liskov substitution principle . Below is the simple example to understand the co-variant return type with method overriding. Output: Note : If we swap return types of Base and Derived, then above program would not work See the below example : Output:  Advantages: 1) It helps to avoid confusing type casts present in the class hierarchy and thus making the code rea

SQL Query Practice Question

Que 1:-Write a query to find the number of employee in each department. Given table is following. Emp_id Emp_name Department 1 ishant cse 2 rahul ece 3 ankit cse 4 deepak it 5 anshul it 6 anurag ece 7 aman cce 8 rohit it 9 rajesh cse 10 Kamal ece                                                                  (tbl  ) Before reaching to the exact answer of the above question we will see some basic  concepts . Now the question is what will happen if we write the following query select * from tbl group by department; result  is:- Emp_id Emp_name Department 9 rajesh cse 10 kamal ece 8 rohit it I am sure you must be wondering why it is just giving the single row rather you have applied group by on department .So the answer is of your question is in the folling question.    Suppose I have a table Tab1 with attributes - a1, a2, ... etc. None of the attributes are unique. What will be the nature of the following query? Will it return a single row al