Java risks becoming a kind of modern-day Cobol

Talk about impeccable timing (link), maybe Neil is stalking my blog!  The title to this post is from an article Neil McAllister just posted on InfoWorld.  Neil talks about the exact same things I had mentioned yesterday and then some.  His spin is, this could mean the end of Java due to the issues Oracle is having with the other major players of Java like Google.  I think Google is a major consumer of Java and getting them off of Java any time soon would be shocking, but like I stated yesterday, JavaScript is showing some promising momentum on the server side.  I also agree that JavaFX has not made any headway in the market and that may be because of Flash and the promising API’s of HTML 5 looming over the industry.  Already many browsers support Canvas and the mobile browsers are actually ahead of the game.

While Java eventually found its niche as a server-side application language, JavaScript trounced it in the browser. Today, projects such as CommonJS and Node.js are extending JavaScript even further, allowing it to take on Java’s traditional role in the data center. In a fascinating role reversal, JavaScript is becoming the versatile, powerful, all-purpose language for the Web, while Java risks becoming a kind of modern-day Cobol. – link

Node.js is getting some momentum

Tonight I am messing around on the net looking for all I can find about Node.js.  I like JavaScript for a lot of reasons but I would never have thought it to be a server side scripting language.  The Node.js stuff is pretty amazing however.  They use the CommJS package system, which is very similar to Dojo’s but in my opinion much better because it forces a one-to-one modular approach between class and file.  I started messing around with it and it seems very fast; but I certainly am no benchmark expert in this area.

I then saw a cloud based service that supports Facebook called Joyent.  These guys built an entire cloud based application offering based on server side JavaScript.  It appears from a few posts their server is based on SpiderMonkey and not NodeJS but there is talk they will be moving to NodeJS.

In short, I think I like this idea and concept.  If you can remove the complexity of creating complex servlets/php/rails based applications using a common language like JavaScript it can only be a good thing right?  It also seems that because it does support many platforms and some key threading techniques out of the box it might be a viable approach.

Node is tested on Linux, Macintosh, and Solaris. It also runs on Windows/Cygwin, FreeBSD, and OpenBSD.

Node tells the operating system (through epoll, kqueue, /dev/poll, or select) that it should be notified when a new connection is made, and then it goes to sleep. If someone new connects, then it executes the callback. Each connection is only a small heap allocation. – nodejs

Why BrowserFunction is so cool

If you are familiar with the embedded browser in the Lotus products you may or may not have heard of BrowserFunction, most likely not!  The problem is this class is not very well documented and was part of E4 and is scheduled for Eclipse 3.6.  Notes 8.5.2 does however support this SWT class so you can begin to play with it once 8.5.2 is available.

Why is this so important?  Well, just imagine, now you can completely communicate between Java and JavaScript using this.  You can use the SWT Browsers execute() or evaluate() methods to execute JavaScript from Java and now you can execute Java from JavaScript using BrowserFunction.

This implies you could potentially write all of your UI using HTML/CSS/JavaScript technologies!

The Attachment viewer is such an application, you can check out the code on OpenNTF.  I don’t use the BrowserFunction in the OpenNTF version but I have already begun to make an Lotus Notes 8.5.2 version of the plugin that has much better integration with the Notes client.  If you are writing side bar plugins and want to standardize on writing in a single technology you should check out the SWT Browser and the BrowserFunction support.

A powerful function…

Many have downloaded, looked at, and have commented on the source code for the attachment viewer project but some may not be aware of a powerful function the SWT Browser brings to the table.  As described in a past post about the architecture, the line where the browser is connected with the embedded browser process (its actually a dotted line) is where this call happens.  The function, or method, is the execute method on the SWT browser.  This allows you to run essentially any JavaScript on a given web page or DOM.  The attachment viewer uses this method to call a JavaScript function named “showAttachments()”.  The Eclipse Java code takes the current selection – which in this case it looks for IAttachment – and then passes a set of URL’s and JSON to that JavaScript function.   This is how easy it is to “connect” the web world with the Eclipse world.

String cmd = "showAttachments(" + jObj.toString() + ");";
 if (browser.execute(cmd) == false){

REST services are a snap with Dojo

As I sit here late at night thinking about what to write about I figured I would share some insight into a night time project I have been playing around with.  The project uses a basic Java servlet on Tomcat that serves up JSON to clients.  I have constructed the servlet to handle many different kinds of requests based on what parameters are passed into it.  The reason I wanted to blog about this was because my first client is being implemented in JavaScript, Dojo and HTML 5.  I am using Eclipse, WTP, and Aptana as the development environment – which I must say is amazingly simple to code, launch, and debug.  The great thing is I can write the Servlet code (in Java), the client wrapper (HTML), and the client-server interaction (JavaScript) all from the same IDE and debugger.  I do however find myself launching in FireFox to use Firebug for some debugging but outside of that its pretty self contained.

I chose the REST service to emit JSON because it makes it very easy to process on the client.  Check out the Dojo code below that creates a session with the “Base” servlet and then processes the response as a regular JS object, in this case “session = dojo.fromJson(response);“:

var session = null;

function createSession(){
     url : "Base?c=cs",

     handleAs : "json",

     load : function(responseObj, ioArgs){
         console.log("successful session creation", responseObj ,ioArgs);
         session = responseObj;
         dojo.byId("session-info").innerHTML = "<b>Id = </b>" + + "<br>";
         return responseObj;
     error : function(responseObj, ioArgs){
         console.log("failed session creation", responseObj ,ioArgs);
         dojo.byId("session-info").innerHTML = responseObj;
         return responseObj;

Dojo and Duck Typing

JavaScript is powerful yet unruly language but through creativity, standards, and best practices you can control the unruliness. Dojo has put a lot of this into consideration and the topic I am writing about today is a technique called Duck Typing.  In the book, Dojo The Definitive Guide, there is a chapter dedicated to utilities and within that chapter there is a section on type checking.

“Duck typing is based upon the saying that if it walks like a duck and quacks like a dck, then its a duck.”

Dojo comes with a bunch of methods to help with this, like isString(), isArray(), isFunction(), isObject(), isArrayLike(), isAlien().

These kind of functions can make your code a lot more safe if you expect a certain type in your function and use them to test that you received what you expected.  Unlike in Java where you can use actual interfaces and class types, you do not have that in JavaScript.

Book Review: High Performance JavaScript

This book is a great resource and reference.  It is probably not something you will read from front to back but more reference the individual sections when needed.  What I did was somewhat scan the entire book first and then revisited each chapter for a clearer picture.  What I found was an amazing amount of tips and tricks to have high performing JavaScript in your code.  Many may think with frameworks like Dojo you don’t need this stuff but that is not the case.  You will need to write your own code at one point – unless you only reference Dojo declaratively – and even so, you could always check the Dojo code to see if it is using the techniques suggested in this book!  What I really like is how the book explains the current browser landscape and shows performance numbers between the different browsers in most cases.  This sort of time stamps the book but it does not invalidate the many examples of making your script perform well.  From simple string concatenation to regular expressions, the book has a wide range of tips to help your applications.  I recommend this book to anyone writing web applications that use JavaScript for any platform or browser.  This book could easily enable developer leads to create a checklist of code review items for JavaScript.

Who uses the E4 Rhino JavaScript debugger?

I hear a lot of people use Firebug and other means to debug their JavaScript or they are starting to use other things like GWT based development to debug.  The JDojo site promotes the use of the E4 Rhino JavaScript debugger and I have not used this as of yet. You can read more about E4 here on the site.

What combination or technique do you use?

Introducing jDojo!

Ok, I don’t really have any authority or any involvement whatsoever with jDojo but I figured I would introduce it on my site.  I am going to be checking it out more closely going forward and seeing what benefit it really gives us.

You will need to register to get into the jDojo site so go ahead – I think it is well worth it.  The latest version now has support for Dojo 1.4 – which tells me these guys are making sure the community has the ability to support very current API’s.  I didn’t get to see the EclipseCon session Michael gave but it looked very interesting and also gives a great summary of what jDojo is.

“The programmer does not program against the Java JDK classes, but against Dojo and JavaScript stubs that JDojo provides.”

I would really like to see a good comparison to how jDojo compares to GWT and the advantages and disadvantages of both – I have some high level ideas but it is clear these two projects are attempting to do something similar (make web 2.0 development easier).   It is very clear that large enterprise JavaScript applications are a bear to manage and tools like these kinds of tools make it very easy to quickly create cross browser applications based on HTML, CSS and JavaScript.  The thing I love best about jDojo is the code you write looks almost exactly like JavaScript so you aren’t really “compiling” per say.  The benefits you get are typed programming and error checking right within Eclipse.  From the main page of the jDojo site here is a summary of the key benefits:

The benefits in summary..

  • The JDojo programmer can now write its Web UI code using the features of the Eclipse Java tooling.
  • The JDojo compiler ensure that correct Dojo and JavaScript code is generated (no missing/unnecessary commas, brackets etc) but also automatically handles things like the list of ‘required’ statements.
  • Type information is now part of the code, and not of the documentation anymore.
  • The programmer still deals with the DOM, browser environment etc, having the full control over all the details.
  • Existing code can be easily integrated by writing a JDojo stub for it.
  • The generated JavaScript code matches the style of the existing code and can co-exist easily in the same project.

Using FireBug to speed up your site

I have been really diving on my site, making tweaks and optimizations and some minor cosmetic changes.  One tool that I have been using to speed up my site is Firebug.  The optimizations this great tool points out can be found under the “Page Speed” tab of the Firebug user interface.  You can systematically go down each item found and fix them; some are more valuable than others but the point is the way the tool works is very slick.  You can even compare your site score to some more popular sites to see how well you are doing.  One thing I may play with is compiling my JavaScript and other files.  From the screen shot below it looks like I can change some cache timeout settings to further speed my site up!