Thursday, August 07, 2008

Back from Hibernation

After a long time of dozing and sleeping i am back. When i started this blog i was working in a company where there were no restrictions or limits on the learning front, But after switching to another company which is comparatively huge in size and count but has very little scope for individual development i fell fast asleep.
Anyways this time i would be sharing not only technical stuff but also some general stuff.
So keep one eye on this space.....Interesting things coming up

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.

Thursday, November 02, 2006

Using Collections.synchronizedList

Till yesterday i was thinking that if i use a Collections.synchronizedList () and use that returned list , i need not synchronize that list. But after running my app i found that i was getting the ConcurrentModificationException which encouraged me to look at the java api ocs and then i found out that my conception was entirely wrong as can be seen from the exceprt below



It is imperative that the user manually synchronize on the returned list when iterating over it:
List list = Collections.synchronizedList(new ArrayList());
...
synchronized(list) {
Iterator i = list.iterator(); // Must be in synchronized block
while (i.hasNext())
foo(i.next());
}
Failure to follow this advice may result in non-deterministic behavior.

Seeing the above docs i was confused as to what is the usage of the synchronizedList??
If we are anyways synchronizing it externally then we can as well use the normal list and
synchronize it rather than using the synchronized list.I stilll have to find out the reason for this
can anyone put some light on me regarding this?

Sunday, October 29, 2006

Disabling the right click of a browser window

When going through some of the forums i found out the way to disable a right click of the browser,
So in our applications we can create our own right click menu instead of the default menu that comes up. the code is prettty simple as it can be seen below

To disable the right click of the browser just use the following code on the body element of the html page
just define a oncontextmenu="return false;"
on the body element of your page
for calling your own function you can call your function before returning false. oncontextmenu="test();return false;"

Thursday, August 31, 2006

Garbage Collectors in J2SE Platform version 1.5

In the J2SE Platform version 1.5 there are three additional collectors. Each is a generational collector which has been implemented to emphasize the throughput of the application or low garbage collection pause times.

  1. The throughput collector: this collector uses a parallel version of the young generation collector. It is used if the -XX:+UseParallelGC option is passed on the command line. The tenured generation collector is the same as the serial collector.

  2. The concurrent low pause collector: this collector is used if the -Xincgc or -XX:+UseConcMarkSweepGC is passed on the command line. The concurrent collector is used to collect the tenured generation and does most of the collection concurrently with the execution of the application. The application is paused for short periods during the collection. A parallel version of the young generation copying collector is used with the concurrent collector. The concurrent low pause collector is used if the option -XX:+UseConcMarkSweepGC is passed on the command line.

  3. The incremental (sometimes called train) low pause collector: this collector is used only if -XX:+UseTrainGC is passed on the command line. This collector has not changed since the J2SE Platform version 1.4.2 and is currently not under active development. It will not be supported in future releases.

Note that -XX:+UseParallelGC should not be used with -XX:+UseConcMarkSweepGC.

For more info refer here