LDAP Timestamp


The unix/epox timestamp is not used by the active directories. Instead the number of ticks from 1st Jan 1601 is used.  CAUTION: the number of ticks is not really in milliseconds, in fact 1 millisecond = 10000 ticks. Now, how to covert no of ticks to a human readable date. The difference between the two dates in seconds is 11644473600 seconds. Thus, lets say we have x ticks. milliseconds = x / 10000seconds = milliseconds / 1000 unixTimestamp = seconds – ...

The ConcurrentModificationException


Have you ever tried to modify a collection on which you are iterating upon? In case you have, you have also probably encountered the evil called the Concurrent Modification Exception. In case you want to get rid of the concurrent modification exception, you will have to understand the cause of its occurrence. Please never believe in the myth, that only enhanced for loops can cause this exception. The good old iterators do throw the same exception. But, it is also ...

if else performance optimization


I’ve often heard that while using an if/else statement, it is often preferred to place the statement which is expected to be true more often in the if condition instead of the else condition. Well, today I did try this out and yes it is true. void runIf(String varString) {    if(varString.equals(“expected-to-be-true-more-often”)) {        System.out.println(“test1”);    } else {        System.out.println(“test2”);            }}  Now, call the function with varString = “expected-to-be-true-more-often”, about a ...

When to use entity manager flush in EJB 3.0


The flush API of entity manager is a very helpful operation as far as single transaction and CMP (Container Managed Persistence) is concerned. Especially when you are trying to save two related entities in a single transaction. Example: Lets say that we are trying to save a Student entity having a many-to-many relation with the Subject entity. Now, we are trying to add new Subject to a preexisting Student entity. Since, the Subject doesn’t exist in the db yet, and ...

The Road Less Traveled By


I’ve always been fascinated by the famous lines by Robert Frost, “Two roads diverged into the woods, and I took the less traveled by and that made the whole difference.” Well, I got news for you Mr. Robert Frost. Sometimes the road less traveled by is less traveled for a reason. And I found that the hard way today.