Friday, December 08, 2006

Accessing Elements of a List in reverse Order

The content of this post may a silly thing but none the less i thought that there may be some people who may need it. Everyone who is dealing with List in java may be knowing about iterator for traversing the List but one facility that iterator does not provide is accessing the elements in the reverse order. For this we can use ListIterator which is a Subinterface of iterator The following code shows how to traverse list in reverse order.
consider we are having a List called testList
ListIterator itr = testList.listIterator(testList.size());
Object listEle = null;
while (itr.hasPrevious()) {
listEle = itr.previous();
}

The above loop will traverse the list in reverse order.

Monday, December 04, 2006

Static Import

Today when i was going through the installation and usage of Watij(Web Application Testing In Java) a tool for web testing in java. I came across usage of static import in java.
In order to access static members, it is necessary to qualify references with the class they came from. For example, one must say:
double r =
Math.cos(Math.PI * theta);
In order to remove the code for acessing every static variable by the class name we can have a static import similar to any other import
import static java.lang.Math.PI;
and then use the variable PI like any other variable
double r =
Math.cos(PI * theta);
If we use then the above statement can be rewritten as below
import static java.lang.Math.*;
double r = cos(PI * theta);
using static imports has its pros and cons
One advantage is that if the developer is using PI at many places in the code then he need not do a reference with the class name every time he can use it as a class level static variable.
But this is also a disadvantage as the code may become confusing if there is no reference of PI anywhere in the program and any other guy who sees this code may get confused as to where is the variable declared.
For more info on this can Click here



Sunday, December 03, 2006

IndicThreads.com Conference On Java Technology

Last weekend i attended a conference on java technology held in pune.There were many prominent speakers , some of them being Gavin King from JBoss , Debu Panda(Author of EJB 3.0 in Action), Raghu Kodali from Oracle. The conference was a pretty good one as it gave me an insight into some of the new emerging technologies in java. I heard some new buzzwords and some old ones which i think have been over emphasized and too much noise is made about them without much content in those technologies.I will be posting seperate blogs about each of the presentations, about the manner in which the presentation is given , content of it and the useful things that i got out from those presentations. But one thing that i observed is that the confidence levels of some of the speakers like Gavin King to say that a particular technology is not good was not found in some other speakers. One thing i definitely need to do is to appreciate the organizers of this event who have brought so many prominent speakers onto one stage. They have also talked about making it a annual event , so may be we are starting to see the emergence of JavaOne for India.