May 30 2007

Effective Java Reloaded – This Time It’s for Real

Joshua Bloch presented on his upcoming book Effective Java Reloaded. This was a repeat of his presentation given during last years JavaOne. I was astounded on the line to get into the room for this presentation. The line snaked the pavilion and back.

The following are some the suggestions given by Joshua during the Effective Java Reloaded session.

For object creation, Joshua recommends using the static factory pattern. The static factory has advantages over constructors, such as allowing flexibility for returning subtypes, caching, and in Java 5 you can do type inference.

Use the builder pattern to overcome the numerous telescoping constructor signatures or the bean style getter/setter methods. The build() method of the builder class constructs a object in a consistent state and can check for inconsistencies.

The following tips deal with Java generics.

Joshua suggested to avoid raw type in new code. Use generics for compile time checking. He recommends that you fully understand each warnings caused by generics and try to eliminate them if possible. If you can’t eliminate the warnings, suppress them at the lowest possible scope using the @SuppressWarnings annotation.

Use bounded wildcards to increase applicability of APIs. Use <? extends T> when parameterized instance is a T producer. <? super T> when the API is a T consumer.

Don’t confuse bounded wildcards with bounded type variables. A bounded type variable, <T extends Number>, restricts the actual class to a subclass of the typed parameter, in this case Number.

As a rule of thumb, if a type variable appears only once in a method signature, use wildcard instead. It is usually best to avoid bounded wildcards in return types. Don’t overuse wildcards, it might water down the benefits of generics.

Generics do not mix well with arrays or variable length arguments. If given a choice, choose generics.

Joshua also talked about a cool mind expanding pattern, the Typesafe Heterogeneous Container (THC) pattern, which he talked about last year.

Joshua said that generics are tricky but well worth learning as they make your code better and safe.

Joshua also recommended the use of the @Override annotation every time you want and think you are overriding a method because sometimes you are overloading a method instead.

And finally, final is the new private. Minimize mutability where ever possible, but be caution when working with serialization or cloneable.

Technorati Tags: , , , ,


May 29 2007

Swing Vector Graphics

Luan O’Carroll, director of Xeotrope and lead developer of the XUI project, talked about how to improve your average pizza box-like business User Interface with Swing and Vector Graphics. According to Luan, the basic application UI is horrible with lack of style. It is hard to enhance or create a custom Swing Look and Feel so most developers don’t bother and instead hope and wait that Sun will make a push for the desktop.

Luan provides a prescription for better User Interfaces which include using Synth, SVG, Swing, Java2D, Swinglabs, Timing Framework, and the Painter API.

Synth provides support for application UI skins and themes. Synth is basically a configurable L&F which can easily allow for skins. Synth requires less knowledge for customing the UI that creating a new L&F from scratch. Luan recommends you use SVG instead of rasterized images with Synth because one size does not fit all with raster images.

SVG is an XML-based standardized format for describing vector graphics. Gaphic illustrators and graphics tools are familiar with this format. SVG provides a rich feature set such as animations, layers, overlays, and effects. There are seveal Java toolkits for woking with SVG, such as Apache Batik and SVG Salamander.

You can breakout of the square Swing component with SVG graphics. Custom SVG/Swing components can be animated and support mouse events such as clicks and rollovers. It is possible to have Jave2D interact with SVG and vice versa so you can get the best of both worlds.

Luan mentioned the Synth SkinBuilder application which helps to customize the Synth Look and Feel. As of this writing, SkinBuilder does not seem to be available check Luan’s blog for updates.

Technorati Tags: , , , , , , ,


May 29 2007

JavaOne 2007: Wednesday General Session

Thomas Kurian, Senior Vice President of Development in Oracle, gave the Wednesday morning general session. Thomas said that Oracle is following four key technological trends including JEE 5.0, Server-Oriented Architecture and Event Driven Architecture, Web 2.0, and grid computing. As Thomas spoke I keep thinking of JEE 5.0 as a MVC framework with EJB3/JPA as the model, JSF/AJAX as the view, and JSF as the controller.

Thomas talked about having JSF components that would generate AJAX or Flash widgets just as naturally as HTML. Thomas also talked a bit about enterprise mashups as corporations begin to bridge together AJAX, JSF, SMS, RSS, wiki, blogs, and social applications with business applications.

Thomas also position Oracle as a large and committed Open Source contributer and mentioned EclipseLink, Oracle recent code donation to the Eclipse Foundation.

While Thomas spoke about Oracle’s position in the middleware, a thought occurred to me. Plain Old Java Objects (POJO) as used in EJB 3 and JPA are not as plain as you are lead to believe, but these objects might well be renamed to Plain Annotated Java Objects (PAJO).

Technorati Tags: , , , , , , , ,


May 29 2007

Rapid Seam Application Development with the NetBeans IDE

Michael Yaun, JBoss/Red Hat evangelist and co-author of JBoss Seam: Simplicity and Power Beyond Java EE, presented on the Seam development using NetBeans. Michael started by stating the state of the art in web applications which include animations, effects, partial page upload, AJAX, RESTful URLs, back button support, etc. Any modern framework needs to have support for all these features. JBoss Seam takes a page from Ruby on Rails.

JBoss Seam is a complete Java EE stack made up of JavaServer Faces (JSF), Hibernate, and Spring-like dependency injection which adheres to Convention over Configuration and generators for rapid web application development.

JBoss Seam provides code generation, configuration by exception, testing is crucial, simplify simple cases (don’t over engineer), and adhere to agile web development. A key feature of JBoss Seam is that is follows the Java way, is standards based, scalable, allows for reusable components, and provides a choice in enterprise components.

JBoss Seam has code generators that can create a whole scaffold web application based on your database schema. For each HTML page you have two files, one XHTML and one XML use for page navigation. From what I gather, Seam seems more verbose than Grails or Rails and even Yuan himself said, “If you are not familiar with Seam it might seem really intimidating with all those XML files.”

JBoss Seam can be easily integrated with JBoss Rules engine and all those popular AJAX libraries such as Dojo and GWT. You can use the Red Hat Developer Studio for Eclipse will make Seam development easier.

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 29 2007

Developing a Real-World Web Application with NetBeans 5.5 Visual Web Pack

David Botterill walk the audience through the design, analysis, issues, and resolutions of creating the NetBeans plugin portal site using NetBeans, of course, and JavaServer Faces (JSF). Some of David’s best practices for JSF development include are to come up with a preliminary set of requirements, use best guess at page design and page flow in prototype to get feedback, solidify the UI during analysis (the UI will effect the architecture), use Firefox Firebug to debug tricky HTML, CSS, and JavaScript.

Many of the issues described in by David seemed to have been web pack bugs that have since been fixed. That said, he did suggest some common pitfalls and how to avoid them. David suggested to start with Plain Old Java Objects, POJOs, not with relational tables and foreign keys, and joins, etc. David also stated that getting started with JPQL queries was a bit difficult, if for no other reason than it is something new that he had to go through. David found it difficult to have a button for a form which you can just press the enter button to submit it because there was no submit button on the form. Be aware of session timeouts, don’t make assumption in your software about the state of the session, always test for it. Be diligent about separating your CSS in separate files from your HTML. If you have a web application that relies heavily on the GET method then reevaluate using JSF because it makes it difficult.

Finally, David believes that for web applications resiliency is better than efficiency.

Technorati Tags: , , , , , ,