To Java or not to Java?
That is the question. We often get questions about when to use Java rather than LotusScript. Back when LotusScript was first introduced, the question was when to use LotusScript over the formula language. Now it seems almost second nature and usually self-evident to use LotusScript, so the question rarely comes up. (Although I do remember having a conversation last year with a longtime Notes developer who was still using formula when LotusScript may have been much more appropriate.)
Sometimes it's just a matter of preference when it comes to determining which language to use. If that's what it comes down to for you, and you can use Java, then I would go with Java. In the long term, I think it would be better use of your skills and help increase your proficiency with Java, something that is more likely to be marketable in the future. But if you are the only person in your shop familiar with Java, then there is always the issue of just who is going to maintain the code if you're unavailable.
Sometimes you just can't Java
Sometimes the tasks you are trying to perform just don't lend themselves to Java development. If you need access to the Notes front-end (UI) classes, then Java is not an option. If you plan on using COM classes to access other applications like spreadsheet or word processing applications, again, Java won't fit your needs.
Sometimes it's better to Java
When you have a certain task to perform, Java is the more logical choice. If you need to integrate your code with Websphere or other J2EE applications, use Java. If your code will be parsing data and/or reading Web pages, go with Java. Its string class provides a wide variety of methods for parsing data. Extensive and ever expanding, libraries provide methods for networking, handling graphics and much more. You can import a library into your project and the methods are available to you.
And, of course, Java is designed to run on many different operating systems. The choice of which language to use still comes down to your personal choice, but considering the differences, you can make a better, informed decision.
If you do Java be aware
There are a few things that you should be aware of if you haven't coded in Java before. Java is case sensitive, so referring to the variable myDatabase is not the same as my Database. In Java, a string never changes. You need to use a StringBuffer to concatenate and work with strings.
In Java, the console is your debugger. You don't have extensive debugging capabilities and will rely on the Java equivalent of print:
System.out.println("Your debugging message").
But the biggest "Gotcha!" for beginning Domino Java developers is the need to recycle. When Java accesses Domino, it is doing so using the C API. Unlike LotusScript, which does extensive cleanup and garbage collection for you, you need to indicate what is garbage. To do this, use the recycle method once you are finished with a Domino object. For example:
view.recycle(). This is very important to prevent memory leaks, which lead to exploding applications.
Where to start
This is a really high-level look at some of the things you need to consider. If you're an experienced Domino programmer, the basic syntax in Java is the same as the syntax in LotusScript. The Domino Object model is the same, although classes don't usually start with Notes. So what you want is a jump-start course and reference. A good place to start is Team-TSG.
Team-TSG (Two Short Guys) is the pairing of the Domino and Java expertise of Joe Litton and Tom Duff. The TSG site has links to their Lotusphere 2004 presentation, Java For The Domino Developer. In addition, each of their sites have some great tips and experience with Domino and Java (among other things). They recently wrote articles in Lotus Advisor Magazine on getting started in Java for Domino Developers (December 2003 and February 2004).
I think that Mahoney has taken a very simplistic view of this issue. Generally we take the following approach for the following reasons:
- When programming exclusively in the Lotus Notes Client, use LotusScript due to the access to the front-end UI classes.
- When programming exclusively for the Web use Java, both in query open and close agents, although I like to stay away from these if possible and use a Java Applet and Servlet for all retrieval of data such as lookup lists.
The use of a DBLookup and DBColumn applet and servlet enables the developer to avoid page refreshes with cascading selection lists, thereby removing a significant performance hit from straight Domino @function-driven Web applications.
Thanks for this article. I was stressing out about having to learn Java, but as I'm mainly developing in-house databases, it looks like I can probably put off learning Java for a while and concentrate upgrading my skills/qualifications to R6.
-- Walter P.
Do you have comments of your own? Let us know.