This post basically explains some of the "useful" api's in the java world which i started using recently and found them to be very helpful.However most of the things i am going to list below, have been here since quite some time now.I suppose its very important for any programmer to know about the latest open source api's which are gaining popularity.I believe it gives you more options to do the same things in different ways.You can either choose to pick it or leave it depending upon the difference it makes to your coding efficiency.Hence its always better to know all the options available to you before you start.
I would like to keep this post short and sweet.Also i would encourage you to visit the links given below to explore the details as i found them to be very much valuable.
Google Collections API -
Google collection api's have been here from quite some time now.The api contains few new implementation classes such as the BiMap,MultiMap etc which are quite useful.There are also a few utility classes added such as the objects,Comparators etc.
e.g. You no longer need to write the entire implementation of the objects equal() and hashCode() methods as the Objects class of the Google collection api provides you the ready to use Objects.equal and hashCode utility methods that you may use frequently.
The following is a very informative guide to use Google's collections api -
http://publicobject.com/2007/09/series-recap-coding-in-small-with.html
Google Guice -
This is basically a framework based on dependency injection principle and uses annotations.It allows you to write a code where in the dependencies are injected by the framework as defined by you.Also you can change the dependencies when there is a need.By dependencies i mean the instance variables present in your class.It also allows you to do many more things.
e.g. You may have a class say Person having an Address instance field (either HomeAddress or OfficeAddress) and depending on the address a particular action is taken.
class Person {
Address address = new HomeAddress();
// methods
.....
.....
}
In the above code the Address is tied to the implementation HomeAddress.Tomorrow in case you need to change the address to OfficeAddress it would be required to change the code.
Instead you can write a class as follows -
Class Person {
Address address;
public Person(Address address) {
this.address = address;
}
// methods
.....
.....
}
Now depending on which Address implementation you pass to the constructor you will fill the Persons Address field.Thus both implementations can be injected through constructor.
This is where Guice comes into picture.Guice does the work of injecting the dependencies depending on which implementation you want the Address object to be constructed.It allows you to do this using Module.In Guice Module is the place where you specify the binding of the dependencies to its concrete implementations.
There is no better place to start reading on Guice than the following -
http://code.google.com/p/google-guice/wiki/Motivation?tm=6
1 comment:
Fantastic!
Post a Comment