Converting JSON to XML to Java Objects using XStream

XStream library can be an effective tool for converting JSON to Java to XML translations to and fro.
Lets explore each one of them one by one, and see which driver is used.

Handling JSONs

To convert JSON to Java objects all you have to do is initialize XStream object with an appropriate driver and you are ready to serialise your objects to (and from) JSON.
Read More »


What are Reentrant Locks?

In Java 5.0 a new addition was made to enhance the intrinsic locking capabilities, called as Reentrant Lock.
Prior to this, ‘synchronized’ and ‘volatile’ were the means for achieving concurrency.

public synchronized void doAtomicTransfer(){
     //enter synchronized block , acquire lock over this object.
} // exiting synchronized block, release lock over this object.

Synchronized uses intrinsic locks or monitors. Every object in Java has an intrinsic lock associated with it. Whenever a thread tries to access a synchronized block or method it acquires the intrinsic lock or the monitor on that object. In case of static methods, the thread acquires the lock over the class object.
Intrinsic locking mechanism is a clean approach in terms of writing code and is pretty good for most of the use-cases. So why do we need additional feature of Explicit Locks? Lets discuss.

Read More »

Using verbs apart from HTTP verbs(PUT/POST..) in REST URL

As per REST, the URLs should make use of HTTP verbs to expose their REST based services via HTTP. (i.e GET/PUT/POST/DELETE)

So, a resource would be something like

GET ../foods/1 would get you the food with id 1.
PUT ../foods/2 would update the food with id 2.
POST ../foods will add a new food.
DELETE ../foods/1 will delete the food resource with id 1.</span>

But in a real life complex application, we are faced with exposing many services such as approve, reject where it becomes inevitable to add verbs to the URL. What should we do? Should we just have the URLs like ../foods/1/approve ?

What would go wrong if we use verbs in REST URL.
Whether there is some rationale behind it or it just REST dogma..
Apparently, there is :
Read More »

Using Map Reduce to find the twitter trends

Few weeks back while preparing for our presentation for agileNCR 2013, Sanchit and I started working on an interesting problem statement to solve using MapReduce.

We thought of applying MapReduce algorithm to find the trends in Twitter.

A Tweet in a twitter can have hashTags (#helloTwitter) and a certain hashTag used most number of times in tweets globally is said to have highest trend. More details can be found here.

This data is huge and also keeps on increasing, so processing it in traditional manner would not be possible.

Hence we would require hadoop to help us solve this problem.

Twiiter uses Cassandra to store the data in key-value format. Lets assume for simplicity that the key value pair for tweet data looks something like this < twitterHandle,Tweet >.

Read More »

JVM Tuning settings, the ultimate list

Let us begin with the very basic question, why do we need our JVM tuned up? And what exactly is JVM.

JVM, is the instance of Java Runtime Environment, which comes into action whenever you run your application

So, in order to make sure JVM runs fine we require that there is enough space for JVM to run programs. And hence we require timely check on the performance factors and space allotted to the JVM.

The crux of the matter: Heap and Garbage Collection
Read More »

Key to Optimization: Algorithm and Analysis

Every problem has solutions but the most important thing is to find the solution that best fits that scenario. So as we take a dig inside the algorithms and techniques we will investigate how we can analyse the complexity and conclude the correct optimized solution.

Let us begin with a simple example and try to find the time and complexity.

Example : We need the sum of n natural numbers starting from ‘a’ and ending at ‘b’. Read More »