May 31 2007

Seamless Web Browser Integration

The complete title for this JavaOne 2007 BOF was Ingredients for a Killer Application – Adding Mojo to Your Swing and Ajax Applications with Seamless Web Browser Integration. Wow, what a mouthful. It might not be immediately clear from the title but the focus of this BOF was the use of the JDesktop Integration Components (JDIC) Web Browser embedded in a Swing application. As we all know Swing does not a complete Java-based web browser component, although there is a good XHTML Renderer. With the JDIC you can embed a native browser (IE, Firefox, or Safari) in your Swing application. Unlike the XHTML Renderer, the native browser allows you to run JavaScript code, apply AJAX/Web.2.0 effects, manipulate the DOM, and more.

Integrating JDIC into your project is as simple as adding the jar. A key demonstration of this BOF was to show how to have bi-directional native browser communication with your Swing application. To use the JDIC native browser, just create a WebBrowser object and invoke the executeScript method passing some JavaScript code in a string to communicate from the JVM to the browser.

To work your way from the broswer to the Java process you need to listen to the statusTextChange method on the WebBrowserListener. The statusTextChange method would be called when you set a string value to the browser window, as in the following JavaScript code.

[source:javascript]
window.status = “message passed to the JVM”;
window.status = “”;
[/source]

The speaker did warn the audience that using the status text to listen for processing instructions from the browser was a total and complete hack. The speaker recommended that as soon set the status to communicate with the JVM that you clear the command/message. The speaker talked about having your own mini-protocol to pass data and instructions to the JVM, I would recommend you use a standard like JSON.

Someone in the audience asked about having access to the x, y location of DOM elements in the browsers to combine with Java 2D overlays and effects, but the speaker was not sure how to go about implementing such a task.

Using the JDIC native web browser in your Swing application you can take advantage of Web 2.0 services such as Google Maps and Flickr in a Swing/Web 2.0 mashup. I have been looking into the JDIC web browser so that I can create a offline standalone web-based application by embedding a browser, Jetty, HSQLDB, and JRuby on Rails. Embedding all these components is easy enough to integrate, although you might have to write some glue code to make into a fully stacked framework.

Technorati Tags: , , , , , , , , ,


May 29 2007

Grails, Sails, and Trails – Rails Through a Coffee Filter

This JavaOne 2007 Bird of a Feather (BOF) session seemed like a brief history of web application development. In the beginning there was pain. In the second day XML moved forth. And on the last day there was Rails, and developers thought it was good. Ruby on Rails’ most mentioned philosophical innovations include Convention Over Configuration, Don’t Repeat Yourself, Opinionated Software, Test Driven Development, and the 80/20 rule. The 80/20 rules indicates that Rails is not all things for all web developer. Rails does one thing and it does CRUD applications well.

Rails growth coincides with the disillusion of EBJ 2.x, and the painful write, compile, deploy, and restart cycle.

Sails models leverage Hibernate, view uses custom template engine Viento, and the controller is rigged using custom dependency injection library which provides Convention Over Configuration. The Viento templating system provides Ruby-like features such as method missing, mixin, and reopening classes.

The second Java-based framework heavily influenced by Rails mentioned during this session was Trails. In addition to Rails, Trails was influenced by the Naked Object pattern, and domain driven design. Trails uses Tapestry, Spring, Hibernate, and Maven to tie everything together.

Grails was originally named Groovy on Rails and as such it was heavily influenced by Rails’ Convention Over Configuration, MVC, dynamic finders, and agile web development. Grails is powered by Hibernate, Spring, Sitemesh, Quartz, and the Groovy programming language.

A key benefit of Grails models over Rails models is that your model does not need to inherit some ORM ActiveRecord-like class, like in Rails. Grails embraces legacy enterprise systems with more complex relationships by leveraging Hibernate. Grails allows you to configure Hibernate and Spring when needed. A possible draw back, depending how you see it, is that in Grails you need to declare the properties in your model which will be mapped to your database table.

Groovy code compiles down to Java byte code. A Groovy class is a Java class, and vice versa.

According to the speaker both Trails and Sails don’t solve enough pain points while Grails is worth a shot. It is worth to note that as soon as some performance improvements have been made, JRuby on Rails will soon be a legitimate platform for your next web application. The benefits of Rails is that there are more books, more documentation, more inertia, and perhaps more developers for Ruby on Rails.

Technorati Tags: , , , , , , , , ,


May 28 2007

Using jMaki in a Visual Development Environment

The jMaki project started as a wrapping utility for JS libraries and widgets. The j stands for JavaScript and maki comes from the Japanese word for wrapping, maku. The intent of jMaki is to promote clean seperation between content, style, and javascript and do so in an abstraction layer that lends itself well to a component model. jMaki is a client-server framework with support in PHP, Rails, or Java web applications.

jMaki has nice IDE support in NetBeans with plenty of wizards to get you started. Since jMaki provides a nice component model you can use the visual editor to wire together the UI of a web application in your IDE. Since a big part of web application development is getting the layout right, jMaki comes with several layouts right out of the box, all you do is select the template you want to use from the IDE.

To wrap a custom JavaScript library with jMaki you will need to create a jMaki widget. A jMaki widget uses the convention, instead of configuration, which is basically a folder containing three files, a HTML template, a CSS style, and JavaScript behavior. jMaki already has support for popular JavaScript libraries such as ExtJS, YUI!, Dojo, etc.

Greg Murray stated that he developed jMaki because he “wanted the reload button to be the redeploy button.” Well, since HTML, CSS, and JS aren’t compiled, that is easy to do. One button redeploy is not the stregth of jMaki, what jMaki has going for itself is that you can visual develop a web application using NetBeans and that this wraps several libraries in a easy to use fashion. jMaki also allows you to mix and match different JavaScript libraries together and communicate with each other using Glue. jMaki provides a common ground for integrating multiple of the currently existing AJAX libraries.

There is a jMaki on Rails plugin available and a PHP library.

Technorati Tags: , , , , , , , , , , ,


May 28 2007

Evolutionary Java – General Session

Evolutionary Java was a general session held at noon on the first day of JavaOne 2007. This general session delved into some proposed features for Java SE 7. Some proposed features for Java SE 7 include modularization which will introduce the concept of super package, new byte code and careful evolution of the Java language, and better support for multiple and dynamic languages in the JVM.

During this session there where more demos including one of JRuby on Rails running a standard Rails application, Mefisto. Tor Norbye gave a demo of the new JRuby/Rails support in a beta version of NetBeans with code completion, code highlighting, and wizards for creating new projects. There was a great demo of GL Studio for Java. Basically the demo mashed up Google Earth-like earth simulation provided by NASA Ames and DiSTI 3D models of a realistic F-16 jet fighter. One of the best demo was Iris, a Flickr mashup with some great eye candy.

There was an additional demo and information on JavaFX Script (JFX). JavaFX Script is an object-oriented programming language with a declarative syntax. Think of JFX as a mini-DSL for effects, animations, and rollovers for the JVM. JFX is a programming language especially designed for effects and animations. It is interesting to note that most of the demos of JFX are ports of Flash applications. A common questions amongst those present was, why introduce another language? Why not just a Java-based library?

Technorati Tags: , , , , ,


May 28 2007

JRuby on Rails – Agility for the Enterprise

Charles Nutter and Thomas Enebo, Sun employees and key contributors to the JRuby project, gave the typical introduction into the Ruby programming language, JRuby implementation, and JRuby on Rails. Ruby is a pure Object-Oriented programming language with plenty syntactic sugar for arrays, maps, regular expressions, anonymous blocks, duck typing, and meta-programming. JRuby is a first class citizen in the JVM.

A common theme by the scripting folks, is their common dislike for regular expression in Java and how the leverage the libraries already available in Java. JRuby, in short combines the libraries and power of Java with the syntax and expressiveness of Ruby.

Charles stated that the benefits of JRuby over Ruby include better scaling, will soon be faster, native unicode support, Java libraries, easy adoption in the enterprise environment and existing applications. The benefits of JRuby over Java include Ruby language features and Ruby applications like Rails, Rake, Rave, and RSpec.

Charles Nutter, the lead on JRuby did state the the current focus is ‘compatibility over performance.’ By this, his focus is for JRuby to be equivalent to the C implementation of Ruby 1.8. Ruby does not have an official language specification, the C implementation is as close as you get to a language spec. Charles Nutter has stated that the lack of a official specification as a pain point in the development in JRuby.

There are some JRuby extras on RubyForge, include a Web Application Resource plugin recently renamed to Goldspike. Originally named Rails Intregation, the Goldspike plugin allows you to create a WAR file for a JRuby on Rails project which can be deployed on Tomcat, Jetty, or any other Servlet container. Other interesting projects include ActiveRecord-JDBC and a Java port of RMagick, the popular image package used in Rails applications.

The speakers also mentioned on the precepts and philosophy behind Rails such as Convention over Configuration, Don’t Repeat Yourself (DRY), and agile development. The typical quote around the JRuby on Rails peeps is that there is “less Rails code than Java application configuration.”

There was a question from an audience member about how JRails compares with Grails. The JRuby folks feel that Ruby on Rails currently has more books, more focus, and more developers. Grails was heavily inspired from Rails, and both projects have borrowed ideas from each other. I personally strongly recommend either Grails, and JRuby on Rails over some of the other available web application frameworks.

Technorati Tags: , , , , , , , ,


May 27 2007

CommunityOne 2007: Up the Stack

The last session of CommunityOne 2007 was titled Up the Stack. The main concern of this session was the whole software development stack, from the Operating System to the database and all the way to the web framework. For the most part, developers these days working on the next great Web 2.0 pay no heed to limitations and strengths of the OS.

This session dealt with performance and profiling considerations spanning the whole stack from using DTrace on Solaris to using caching in your application. Dtrace is dynamic tracing utility made available in Solaris that will help you discover bottlenecks in your application by analyzing the whole process.

Another session dealt with GlassFish. GlassFish is an enterprise ready Java EE 5 Application Server with easy management tools and clustering support. GlassFish supports RIFE, Rails, Struts, Wicket and just about every other Java web application framework under the sun, no pun intended.

Tim Bray of Sun moved up the stack and talked about web technologies such as PHP and Rails. Tim stated that PHP is easy to learn and quick to develop with. PHP has a share nothing architecture that is great for scaling but is historically known for the tons of security holes, SQL injection, and cross-site scripting attacks. Tim noted that some developers would trade the security of JEE for the speed of development of PHP to get first to market. Tim also mentioned that Don’t Repeat Yourself, Convention Over Configuration and the expressiveness of Ruby while talking about Rails. The Ruby programming language allows for Rapid Agile Development. The big knock against Rails is its lack luster performance and it’s multi-headed mongrel deployment story. PHP or Rails are a good solution for many of the CRUD applications that babysit a database.

The last session of the talked compared Ehcache and memcached. Memchached is said to be used in LiveJournal and Slashdot as well as many Ruby on Rails applications. Ehcache distributed peer-based caching in Java sync/async operations used in Spring and Hibernate.

Technorati Tags: , , , , , , , , , ,