Skip to main content

Posts

Java 8 - Lambda Expressions

Greetings! Before Java8, Java is a fully object oriented programming language. While most of the other programming languages introduces functional programming Java was in OOP way. Java8 introduces lot of features and lambdas are the biggest change that happened to the language so far. What is functional programming? It is a programming style that allows to program using expressions. With that we can create instance of a function and assign to a variable, pass functions to methods as arguments. Is OOP not enough? We can do everything without lambda expressions. But it help us to write better readable and maintainable codes. And also it gives us better support of multi-cores. In OOP we are not passing behaviors. We pass objects which have behaviors. In functional programming we can pass behaviors. Benefits of lambda expressions Parallel processing. Enable functional programming. Readable and concise. Syntax A lambda expression has 3 parts. Argument list Arrow t...

View with VueJs

Introduction Vue (pronounced /vjuː/, like  view ) is a  progressive framework  for building user interfaces.  https://vuejs.org/ We are going to build a simple ToDo app. (code in self explanatory) Code is at  https://github.com/slmanju/vuetime/tree/lesson-00 Set up # Install cli $ npm install --global vue-cli # create a new project using the "webpack" template $ vue init webpack demo-app # Install dependencies $ cd demo-app $ npm install # Start the application $ npm run dev Update HelloWorld.vue, Go to the browser to see the chagnes. http://localhost:8080/ Let's delete HelloWorld.vue file and update the App.vue as follow, In components folder create our Todo.vue and TodoList.vue components. Update the App.vue to use our new components. You can see new changes in the browser. So far we have hard coded our todos. We can pass dynamic data and use v-for directive to loop over those. <div v-for="t...

Chain of responsibility design pattern

Greetings! In this behavioral design pattern, request is handled using a chain of objects. This is used to eliminate series of if...else if...else if... statements. Thus, each of the processing object contains only the related logic (as in an if statement). It is also possible to execute all the processing objects. Since the chain work independently new handlers can be added easily, and also existing handlers can be removed. Image source wikipedia Let's see a sample.

IoC, DI and Spring

Greetings! "program to interface not implementation" IoC and DI Both words are used interchangeably in Java world but there is a difference. Inversion of Control is a more general concept Dependency Injection is a concrete pattern IoC - Inversion of Control Inverts responsibility of managing object life cycle (create, initialize, destroy, etc). In simple term, let someone else to create objects for you instead of using "new" in code itself. Normally this someone else is Ioc Container. IoC Container Framework to create dependencies and inject them automatically when required. DI - Dependency Injection Objects are depending on other Objects. In DI, Objects are given (injects) their dependencies (other objects) through their constructors, methods, fields. IoC with DI So if DI means objects are injected who is doing that. Here is where IoC comes in to play. With IoC dependencies are managed by the container. Spring Framework Spring Framework ...

Implement a JPA attribute converter

Greetings! Using JPA we can easily map our column values to Java variable and so forth. What if we want our column to have some value and mapped variable has another? One way to achieve this is to have a another method to convert the values. JPA comes with a another handy way to fulfill this. That is AttributeConverter. Only thing we want to do is to implement AttributeConverter and add our logic. Here is an example using Enums.