Tuesday, August 26, 2014

ActiveMQ Introduction

ActiveMQ is a messaging bus and helps in building Event based systems.It supports JMS which is a JavaEE based feature. In this tutorial, we will look into how to install and start a ActiveMQ server and a small program to create topic and consume topic over the message bus. We will also look into the ActiveMQ web front end where we can see what is happening in the message bus. This tutorial is based on windows but pretty much similar steps can be followed for Linux.

Installation of ActiveMQ

Monday, August 25, 2014

Map Reduce in simple terms

The one concept that is quite popular today is Map Reduce. A perception is created that all the software problems can be solved by using Map Reduce. People have created cult around Map Reduce. Ok..ok..jokes apart, Map Reduce is an important concept to understand when you are dealing with large scale data processing. In this post we will try to look into Map Reduce in simple terms and try to unravel the mystery behind it.

Map-Reduce is made up of two words. Map and Reduce. Let's take each term and see what they mean. Map is a key value pair. Here in Map Reduce concept, Map word basically refers to making a Map. This is the first step in Map Reduce. The second word is Reduce, which mean to shrink. So what we do is we shrink the number of maps, so that for one key only one store exists. In the context of this discussion, let's look into an example.

Let's say we have 3 files and each file contains some set of words.

Lambda Expression in Java

In simple terms, Lambda expression is just a block of code which can be passed as an argument. Java takes its pride in being a full object oriented language but then there are merits to functional programming. Before Java 8, when lambda expressions were not there, one has achieve the same by passing either Anonymous classes. Lambda expression needs Functional Interfaces to work. You can see details of Functional Interface here.

Let's see with an example. Let's define a class which uses comparator interface to compare the objects on different attributes.

public class Student {

Functional Interface in Java

Functional interface are introduced in Java 8 and they simply mean that they have just one method declared in it. Nothing more nothing else.

One can annotate an interface with exactly one declared method as functional interface. It's not mandatory also to define the annotation as interfaces with only one declared method will be treated as functional interface. Functional interfaces are used in lambda expression. For example, Comparator is a functional interface.

Example of a Functional Interface

Saturday, August 23, 2014

Reflection in Java

Reflection is a way to inspect the internals of a class at runtime. It's a powerful feature but has to be handled with care. It in some sense breaks the notion of Object oriented concept. When we make a variable or method private we assume that the world is not able to see it. With reflection that's not true. With reflection one can inspect the internal details of a class and can even call methods and set attributes.

Let's see this with an example. Let's say we have a class that we want to reflect

public class ClassToReflect {
//No arg constructor
public ClassToReflect(){
System.out.println("No argument Constructor");

Wednesday, August 20, 2014

Forward vs Redirect

What happens when browser or any client asks for a resource at a location and the resource is actually sitting on a different location. Server can handle that situation primarily in two ways:
  • Forward
  • Redirect

In forward, server internally manages the change of location of the resource. If you see the picture below, the browser asks for resource at location 1 but the resource is sitting at 2. So the server internally forwards the request to location 2 and the resource is returned from 2.

Tuesday, August 19, 2014

Java Webservices Framework

A web services is primarily a software interaction. Softwares have been interacting with each other right from beginning, but web services make it better by providing a XML format exchange. Lately we are seeing web services being done with JSON style payload.

At the moment in Java landscape, there are many web services framework which provide both server and client side implementation framework. The prominent names doing round are as follows: