I recently received a comment that I would like to address:
Hey Greg. I watched the tutorial and followed it quite easily. My biggest block to Java is why should I use it? I am having difficulty understanding what the great benefits are, other than getting skilled in a new field.
I also am perplexed as to why, for example, would I need a session helper when I have session info with my standard XPage. Another thing, having an object of a Domino document and using the object to read and write fields back to my source data seems rather tedious seeing that I can read and write straight to my source data?!?
I’m missing something for sure because everyone seems to be wanting to go the Java route.
If I had 1000 users open an XPage application and view a document then why create 1000 objects, one for each document and session helpers. Does that not take needless memory?
But I am looking forward to the next tutorial!!
There are a few questions in here that I find good to ask and that can cause some debate in the professional world. I will start off my answering my part to the question why.
Some people will say, “Use Java! Why? Because .. white noise………”
Use the correct tool for the correct job!
Yeah, but, Why Java
Maintainability, Readability, Usability. There is no better way to put it.
if(apples = oranges) doSomething();
as opposed to:
if(apples == oranges) doSomething();
Another reason why I say usability is improved with java is the tooltips/inteli-sense or whatever else you want to call this feature. If the javadoc for the API you are using is connected in the build path, you are able to look at detailed information provided by the developers, assuming that they maintained their javadoc well. This also goes for the javacode that you write. Of course you have the ability to write and look up comments in SSJS, but they do not show up like they do in Java. If I am wrong about that please tell me, but I do not believe I am. In Java, you have the ability to simply use shortcuts to import packages and classes using the inteli-sense, keyboard shortcuts, and see what members and functions are available in those classes whether they are known to designer or not.** You write a class, that class is known by the inteli-sense. It is that simple. It may not seem like a lot, but when you can quickly see what code does what, import, and comment all in one place, then why would you not want to?
Why Java? Not for the negligible speed increase, but for Maintainability, Readability, Usability.
Why a SessionHelper object?
There will be some who will say that my approach to getting a session in an external class is a bad idea. I can only say to that that I have not had any issues getting the session or the database from other helper objects and methods. An absolute no-go would be getting the objects under the database object. Your cleanup would either be messy, or give you NotesExceptions depending on how you went about it.
Java and Object Retention
Java is also the only place where you can define classes for beans to be used with scoped maps. Otherwise, you are just saving raw variables into your map and cluttering it up. Use Java to correctly store and access your information so that it can be readily accessed and executed. I am a strong supporter of Java use in XPage applications. I hope that this article has helped explain why.
* This is really a case by case decision and must be decided upon specifically when designing the application.
** By “known to designer”, I am referring to basically hard coding the inteli-sense. I actually do not know how this works and am merely guessing. Does not matter though.