Sunday, May 31, 2009

Groovy and Grails at JavaOne

Hello from San Francisco! I am at JavaOne this week. Catching up on what is new, important and at issue with Java. The conference is not cheap and travel is usually one of the first things that go in reduced budgets, but if you can somehow manage it, this is the conference that all Java developers need to attend whenever possible.

The conference’s Java University started today. I attended a wonder class by Graeme Rocher on Groovy and Grails. Graeme is the project lead for Grails and head of Grails development at Spring Source.
Groovy is a programming language that has been attracting a lot of attention lately. And base on what I learned and saw today, it rightfully should. Groovy is a dynamic language inspired by a number of other such languages (most notably like Ruby, Smalltalk and Python) written specifically for the Java Virtual Machine. Its aim is to bring the “power of Ruby and Python and the elegance of the Java syntax to a JVM.” Because it is written specifically for the JVM, it is an extension to Java. Groovy provides all the power of metaprogramming but with all the benefits of Java and the JVM underneath. Although other dynamic languages like JRuby or Jython run on the JVM, they have had to be modified in order to run on the JVM. Some concessions were made in the port of Ruby and Python to the JVM. Most of the environments are an extension but a replacement of the Java API (having their own I/O and collection API for example). The goal of Groovy is simple – less code meaning faster development and hopefully easier/faster maintenance.
Grails is an MVC++ action-based web framework. Grails is to Groovy what Rails is to Ruby (more precisely Ruby on Rails). I say Grails is an MVC “plus plus” framework because it is more, way more, than just a web application framework. It also provides the entire platform for building applications from the UI to the data layer. In fact, Grails is built on Groovy (of course) as well as Spring, Spring MVC, Hibernate, Quartz (for job scheduling), SiteMesh (layout framework), Jetty and HSQLDB. Like Rails, building a CRUD (create, read, update, delete) interface can be done in minutes. But because it is also built on top of the best-of-breed Java technologies, it can also do so much more, and because it is done with Groovy, it can be done quickly with very little code.

A couple of things to consider before you start singing Kumbaya with the Grails/Groovy crowd. Grails requires a relatively up to date platform. Grails comes with its own container and even database, but most shops are going to want to run Grails on their own container. Grails requires a Web container that is at the 2.5 level (Java Servlet 2.5). Secondly, Grails is slower than Java. According to Graeme, he has seen a Java application that did ~1000 transactions a minute only perform ~750 when using Grails. The good news is that the same app using Rails did only ~150. Rails performance issues are starting to attract some attention and Grails offers the same kind of development convenience with a much better performance outlook (see http://www.infoq.com/articles/Rails-Performance or http://www.techcrunch.com/2008/05/01/twitter-said-to-be-abandoning-ruby-on-rails/ for some of the Rails issues). Lastly, Grails, while offering the promise of less code and faster development, is not a tool for novices. Under the covers of Grails and Groovy, there is a lot of Java and Java technologies. While Groovy and Grails helps abstract away many of the details and common drudgery of modern Java application development, it does not protect the developer from having to fine tune and tweak application to do the business’s bidding, especially in large scale, high performance environments. I asked Graeme if he felt developers of Grails applications needed to know Spring, Hibernate and all the underlying technologies well to be able to build a large scale performing enterprise application. He indicated that in some cases, for example Spring, developers were isolated from having to know the framework to get things to work and work well. But developers are going to have to know and understand the inner workings of other frameworks like Hibernate in order to make parts of Grails like GORM (Grail’s ORM capability) perform well. Given that Grails is built on top of Java, on top of many Java technologies like Hibernate and Spring, and on top of Groovy, this is a lot to learn and know.

Still, when you see the simplicity and speed of Groovy and Grails development, you can’t help but believe there indeed IS a better way to build Web applications. “Power to the people” with Groovy. I encourage you to take a look. More information on Groovy can be found at http://groovy.codehaus.org/. Information on Grails can be found at http://www.grails.org/.

Wednesday, May 27, 2009

New Spring Classes and a Special One-time Discount

For those interested in learning Spring, I have just completed two new Spring classes at Intertech: Complete Spring Core and Complete Spring Web. These two classes will be offered back-to-back in June.

In fact, we (Intertech) has a special offer. For the Beta (first public offering) of these two Intertech courses, we’re offering a 25% discount on the standard course rate. In exchange for the discount, you agree to give detailed course feedback. The courses and dates are:
Complete Spring Core Training, June 8-10
Complete Spring Web Training, June 11-12

To get this special pricing, you must register over the phone (651-994-8558 +23) and mention “BETA-RUN.” This is a onetime offer so sign up now.

Friday, May 15, 2009

Questions from Java "newbies"

I enjoyed being in a class with a wonderful group of students this week. The class was Intertech’s Complete Java. The group was not new to programming and they had a variety of software development backgrounds (some .NET developers, some mainframe developers, some Javascripters, some QA testers, and even a Python developer). This made for a lively class, full of great questions and plenty of prior experiences they (and I) could use to explore Java syntax and object-oriented programming concepts. A few of their questions required me to do a bit of research and therefore have earned their way as topics for discussion and learning in this blog.

1. In Eclipse, is there a way to run the Javadoc tool against my code? [Thanks Pradeep]
The answer is yes! While I knew this was possible, I wasn’t exactly sure of how this is done. It turns out using Javadoc from within Eclipse is a piece of cake. Given your Eclipse IDE is already configured to use the tools from a JDK, chances are good that it is already setup to generate Javadocs for your code with a simple menu selection. In Eclipse, look for the Project menu option on the Eclipse menu bar. Select Generate Javadoc… from the Project pull-down menu.



This should cause the Generate Javadoc window to open where you can specify what members should be included (private up to public) and where the documents generated should be put. If the JDK’s bin folder and/or the javadoc.exe tool can’t be found, the same window allows you to point Eclipse to a valid Javadoc generating tool and configure it per your needs.



Once the Javadocs are created, the documents are used by Eclipse to produce hovers over the classes, methods, variables, etc.



2. Can a list of stored procedures in a database be obtained from JDBC’s DatabaseMetaData class? [Thanks Bill]
Again the answer is yes! A DatabaseMetaData object provides all sorts of information about the database and database driver. The DatabaseMetaData interface defines 40+ fields and 100+ methods. The DatabaseMetaData object includes data about what schemas and tables are defined in the database. It allows developers to determine database capabilities programmatically, such as whether the database supports column aliasing. It also includes information such as the database name and version. To get a DatabaseMetaData object, request it from the JDBC Connection object.

Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb","root","root");
DatabaseMetaData md = conn.getMetaData();

With a DatabaseMetaData object, you can get the list of stored procedures from the database (provided your database supports stored procedures) by calling ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) on the DatabaseMetaData object. The ResultSet that is returned contains columns of data (listed below per the JDBC documentation) that describe the stored procedures.

· PROCEDURE_CAT String => procedure catalog (may be null)
· PROCEDURE_SCHEM String => procedure schema (may be null)
· PROCEDURE_NAME String => procedure name
· reserved for future use
· reserved for future use
· reserved for future use
· REMARKS String => explanatory comment on the procedure
· PROCEDURE_TYPE short => kind of procedure:
· procedureResultUnknown - Cannot determine if a return value will be returned
· procedureNoResult - Does not return a return value
· procedureReturnsResult - Returns a return value
· SPECIFIC_NAME String => The name which uniquely identifies this procedure within its schema.
Thanks to my students. If you have a "newbie" Java question, please, send it to me at jwhite@intertech.com.

Wednesday, May 6, 2009

Free Expression Blend Presentation

My fellow Intertech instructor and award winning author Andrew Troelsen will be presenting at Intertech's next Oxygen Blast on on May 26th. The topic is on Expression Blend.

We’ll cap the registrations for the event at Microsoft at 120 and over the web at 250. Both will fill. If you’re interested, beat the pack and register today:
Live At Microsoft: click here
Live Over the Web: click here.

Spring Stereotype Components

As a Java coder, have you started to familiarize yourself with the "@"? That is, have you started applying annotations to your code to reduce XML configuration? Annotations are big and getting bigger in Java. Spring Framework too has embraced annotations; especially as of Spring 2.5. In my latest article on DevX.com I provide an overview and tutorial (download the code!) of the Spring stereotype components and annotations. Of particular importance are the annotations used to develop Spring controllers. As of Spring 3.0, the old Spring MVC controller hierarchy is deprecated!

http://www.devx.com/Java/Article/41629

Haven't had a chance to learn Spring yet? Come take our Intertech classes on Spring: Complete Spring Core and Complete Spring Web. We offer classes on-site as well as virtually.