Discovering Notes 8: Enabling Java 5 source compilation


I’m playing around with Notes 8 to get my bearings on the Gold release and I’m liking it. I’m kind of a Java-nut so I wanted to see if Lotus delivered on their promises to include Java 5 in Notes 8 and they did. Unfortunately the Java API hasn’t been updated for this release but hopefully this will happen in the near future. I know I will certainly stress that it will in the Domino Application Development Design Partner program where I have been fortunately enough to be included (together with Nathan and a fine line of other fine folks).

To test it out I fired up Domino Designer and created an agent to use generics and some autoboxing. Both are highly awaited in the Notes Java world – at least by me – and it will be really nice to have. The test agent code is as follows (generics and autoboxing is highlighted):

import lotus.domino.*;
import java.util.*;

public class JavaAgent extends AgentBase {

   public void NotesMain() {

      try {
         Session session = getSession();
         AgentContext agentContext = session.getAgentContext();

         int size = new Integer(10);
         List<Document> docs = new ArrayList<Document>(size);
         for (Document d : docs) {
            d.getUniversalID();
         }

      } catch(Exception e) {
         e.printStackTrace();
      }
   }
}

To my surprise the above code didn’t compile and gave me the below compile error message.

I tried compiling the same code in Eclipse (using Java 5 source compatibility) and importing the class file as an Imported Java agent which worked fine. Hmmm – binary support but no source support? Last resort – look for clues in the release notes and there you have it! In the section “Installation, migration, upgrade, and configuration informationUpgrade notesNotes/Domino 8 upgrade to JDK (Java Development Kit) 1.5” it states that in order to keep backwards compatibility Java 5 source compilation in Domino Designer is disabled out of the box. To enable it add the following notes.ini variable and restart Notes:

JavaCompilerTarget=1.5

Once this line has been added I was able to compile the above code… ๐Ÿ™‚

Looking forward to Java 5+ support in Notes

I’m currently trying to figure out some replication issues for a customer and to help me diagnose the problems I’m writing a reporting tool. I hope to be able to share the tool shortly as it has proven an invaluable tool to help monitor cluster replication as well.

The tool is written in Eclipse using Java and I wrote it using some of the features of Java 5 such as the enhanced for-loop, autoboxing and generics since it was to be a one time thing running from a console. Well as with all quickies – they turn out to stick around…

Now the customer would like to keep monitoring the replication and by far the easiest way is to schedule it using an agent. This however meant that I had to port the code to Java 1.4.2… ๐Ÿ™ I don’t think you fully appreciate the new features of Java 5 until you have to revert to Java 1.4.2.

For those not in the know in Java 5 you can use an enhanced version of the for-loop to loop all types of java.util.Collection instances and arrays. This means that instead of writing:

public void loop(Collection my_col) {
  Iterator ite=my_col.iterator();
  while (ite.hasNext()) {
    Customer c = (Customer)ite.next();
    c.bill();
  }
}
...or...
public void loop(Collection my_col) {
  for (Iterator ite=my_col.iterator(); ite.hasNext(); ) {
    Customer c = (Customer)ite.next();
    c.bill();
  }
}

you can simply write

public void loop(Collection<Customer> my_col) {
  for (Customer c : my_col) {
    c.bill();
  }
}

Isn’t that nice… Apart from being shorter is much easier to read and understand. Also the added use of generics (i.e. specifying that the passed collection contains Customer objects by using the bracket notation) means no more casting of objects all the time.

Can’t wait for Java 5+ support in Notes/Domino. I wonder what the Java level is in Hannover…