Java 8 automatically injecting logger using trait

This post explains how default methods in Java 8 can be used as a trait to automatically inject logger instances.

To use logging in Java code, we need to add this boiler plate code in every Java class.

private static final Logger logger = Logger.getLogger(MyClass.class.getName());

Like me, most of you would hate copy pasting this line and updating the class name in every Java file. Luckily, Java 8 supports default methods in interfaces which can be used to solve this problem.


Continue reading...

Error accumulation in validation using Applicative Functors

This post explains how Applicative Functors can be used accumulate validation errors using Javaslang validation API.

Problem

To illustrate with an example, let’s say a given stream of pair of date strings in format MM/dd/YYYY, we want to print difference between them in number of years, months and days. ( For eg "01/01/2016 , 02/01/2016" should print 0 years , 1 months and 0 days).


Continue reading...

Better Exception Handling in Java 8 Streams Using Javaslang

In this post, I will provide tips for better exception handling in Java 8 streams using Functional Java library Javaslang.

Problem

To illustrate with an example, let’s say we want to print day of the week for given stream date strings in format MM/dd/YYYY.


Continue reading...

Nikola Tesla : Greatest genius who invented the Electrical Age

Nikola Tesla is a greatest genius who invented the electrical age of twentieth century. His inventions, patents, and theoretical work formed the basis of modern Alternating Current (AC) electricity, and contributed to the development of radio, television and many electrical inventions. I feel his story is important for anyone interested in history of invention and hence this blog post.


Continue reading...

Groovy - Dynamic properties in Config Slurper

In this post I will provide quick tip on how to use dynamic properties in Groovy Config Slurper. Groovy provides a nice utility ConfigSlurper for reading configuration files where settings can be overridden to different values for different environments.


Continue reading...