Archive for the ‘java’ Category

Seam makes JSF sexy again

Thursday, May 31st, 2007

Kito Mann of JSFCentral just posted the PDF slides for our JavaOne talk on Seam and JSF. The slides cover what is hot about JSF and what is not, and more importantly, how Seam enhances and improves JSF in 14 important ways. :) Just to wet your appetite, here are the 14 key points elaborated in the slides:

1. Reduces Boilerplate code
2. Dependency bijection
3. No XML hell
4. Integrated ORM support (a.k.a, use Hibernate as Gavin intended! ;))
5. RESTful URLs and page actions (for GET requests)
6. Extensive and expanded use of JSF Expression Language (EL)
7. Fine-grained stateful conversations (web transaction, multi-tab support etc.)
8. Direct JavaScript integration for Ajax (use Dojo with your JSF apps)
9. Elegant input validation
10. Graceful exception handling
11. Easy-to-use and rule-based security
12. Business process and rules integration
13. Very easy to test (both unit test and integration test)
14. Tools support (Seam Gen for RoR-like experience for CURD apps)

Go check it out!

Seam NetBeans Plugin Updated

Wednesday, May 30th, 2007

Petr Pisl has released the 0.2 version of the Seam NetBeans plugin (man, he is so conservative with version numbers! ;)). It works with Seam 1.2.1 GA (w/ deployment to JBoss AS 4.0.5 GA). Petr has also fixed a few Windows bugs. It is essentially the same plugin we demonstrated at JavaOne. Please visit here for a quick tutorial on how to use the plugin.

Eclipse users: stayed tuned! The Red Hat Developer Studio with full Seam support is just around the corner! It will be worth the wait!

Seam book examples updated to JBoss AS 4.2.0 GA

Tuesday, May 29th, 2007

I have just updated all the 17 sample applications in my JBoss Seam book to JBoss AS 4.2.0 GA (w/ Seam 1.2.1 GA). You can now download the sample projects for both JBoss AS 4.0.5 and 4.2.0. If you find those examples useful, I’d appreciate if you can buy a copy of the book as well. :)

Since a lot of people seem to be confused about this, let me list the steps you need to convert a Seam application from JBoss AS 4.0.5 to JBoss AS 4.2.0:

1. Edit the resources/WEB-INF/web.xml file, and remove the MyFaces listener.

2. Edit the resources/META-INF/application.xml file, and remove the modules referencing el-api.jar and el-ri.jar.

3. Remove the el-api.jar and el-ri.jar files from the final application archive (edit the build.xml file for the ear or war tasks).

4. Edit the resources/WEB-INF/faces-config.xml file and add the SeamELResolver using the new JSF 1.2 XML schema declaration.

Do NOT miss the crucial step of removing el-*.jar from both the application and from the application.xml. If you do not remove those JARs and their references, your application will hang on JBoss AS 4.2.0 GA with a cryptic error message (before you ask, yes, we are fixing it). So, be aware!!

Note: Evidentially, the Seam security package still has some residue dependency on the Sun EL RI package. So, you might consider leaving el-ri.jar in the app if you use those features. It is confirmed to work in JBoss AS 4.2.1 GA. See comments below.

Made it to the Amazon best seller list (Java category)

Sunday, May 27th, 2007

Okay, now the “JBoss Seam” book is not only a top 10 best seller in JavaOne 2007. It is also an Amazon.com #19 best seller in the “Computer Programming — Java” category! Since Amazon lists more than 2500 books in the category, that makes it top 1%. I’d like to congratulate myself here. ;) Here is proof:

Picture 2.png

com.sun.robot.humanoid — the Office Toy in JBoss/RedHat Austin

Friday, May 18th, 2007

Phillip and I bought the "Java robot" from JavaOne, and decided to keep it in the office as an "office toy". This is easily the coolest geek toy I have seen in years. It can walk around, sit / get up, pick up stuff with its hands, speak / sing (plays any MP3), play video / games on its LCD screen, and even take pictures. It detects and responds to sound, visual objects, and colors. It can even automatically recognize and follow humans. Of course, it can be remotely controlled as well.

Picture 7.png

But the best feature of all is that the robot runs Linux and can be programmed via a simple Java API! There is a simple Java wrapper class that allows your application to interact with all sensors and motors on the robot. You typically run your application in a loop, and try to make the robot respond to events coming in from the sensors. I have not tried but here is some sample code from the SDK. You are smarter than the robot and can figure out what it is supposed to do. :) Isn't that COOL!

JAVA:
  1. Humanoid humanoid = Humanoid.getInstance();
  2.  
  3. ... ...
  4.  
  5. while (true) {
  6.   // Turn off the bright LED in the eyes.
  7.   humanoid.enableLED(false);
  8.            
  9.   // Look around.
  10.   humanoid.VISION.track();
  11.            
  12.   // Check for color red in vision field. Run to red.
  13.   if (humanoid.VISION.getTarget(Vision.RED)) {
  14.     // Turn on the LED in eyes to signal that it sees RED
  15.     humanoid.enableLED(true);
  16.                
  17.     // Advance on target.
  18.     humanoid.WALK.walk(Walk.FORWARD_GAIT1, 10);   
  19.                
  20.     // Are we at the bump?
  21.     If (humanoid.TOUCH_LEFT_FOOT_FRONT.isTriggered()||
  22.               (humanoid.TOUCH_RIGHT_FOOT_FRONT.isTriggered()) {
  23.       // We are done.
  24.       break;
  25.     }
  26.   } else {
  27.     // Do not see RED in current vision field -- so the robot moves around to search for RED
  28.     boolean wanderLeft = 1 != rand.nextInt(1);
  29.              
  30.     // Wander left or right
  31.     if( wanderLeft ) {
  32.       humanoid.WALK.turnRight(2);
  33.     } else {
  34.       humanoid.WALK.turnRight(2);
  35.     }
  36.              
  37.     // Walk forward a bit
  38.     humanoid.WALK.walk(Walk.FORWARD_GAITFAST, rand.nextInt(3) + 3);
  39.   }
  40. }
  41.  
  42. // Raise the arm to declare victory
  43. humanoid.SHOULDER_LEFT_SERVO.moveToPosition(
  44.   humanoid.SHOULDER_LEFT_SERVO.maxPosition() / 4,
  45.   humanoid.SHOULDER_LEFT_SERVO.maxSpeed());
  46.  
  47. // Take a picture of the RED target and display it on the LCD
  48. String pictureFile = humanoid.CAMERA.takePhoto(0);
  49. humanoid.CAMERA.displayImage(pictureFile, 5000);
  50.  
  51. // Say something
  52. humanoid.AUDIO.playClip(mission_accomplished.mp3);
  53. ... ...

The robot is BIG -- it was a challenge to bring it back from San Francisco. :) Just notice how big it is compared with Phillip's 19" monitor in the background.

Picture 6.png

Anyway, we have not officially started playing with it yet (product release deadlines! ;)). I will continue to blog about it here in this blog as we discover its features. If you have ideas on applications, leave a comment -- we might implement it and post a video!

The Weird Geeky T-shirt from Sun’s CommunityOne Event

Monday, May 14th, 2007

It took me a while to figure out the cartoons on Sun's "CommunityOne" T-shirt ...

The front of the T-shirt says: O-pen-sew-(hor)se: Open Source

Picture 31.png

The back of the T-shirt says: Comb-ewe-knit-e-one: CommunityOne (Thanks David for the correction, see comments. I am bad at math ;))

Picture 4.png

JBoss Seam book makes the JavaOne official best seller list

Wednesday, May 9th, 2007

JavaOne has a long tradition of tabulating and ranking book sales from the conference official book store. All technical book publishers are present in the bookstore and they make their most popular Java book titles available at a discount to the 15,000+ JavaOne attendee. The attendees' interest in technical books is often a gauge of the technology trend in the Java world.

Well, on the first day of the conference, my new book "JBoss Seam" made the top 10 best seller list! That says a lot about Seam's momentum among developers. Furthermore, I have several interesting observations of titles on the list:

1. JavaServer Faces (JSF) is really taking off! Despite what the "cool kids" say in the blogsphere, JSF is very much in demand in the real world! The number one book on the list is a JSF book and my book is closely related to JSF. Actually, according to Matt Raible's 2007 web framework comparison report: JSF leads other post-Struts web frameworks by a big margin in terms of number of jobs available.

2. In terms of dynamic scripting languages, people are much more interested in Groovy / Grails than Ruby / JRuby / Rails -- that is despite 2 days of intensive JRuby / Rails brain-wash from Sun. The best selling Rails book is at #15 while 3 Groovy / Grails books made into top 10. I guess Java developers do want a scripting language that is closely related to Java!

3. Netbeans marketing surely is effective!

Here is the actual list:

Picture 3.png

JavaOne book store will update the best seller list on a daily basis. So, let's stay tuned to see what happens tomorrow! :)

Update: By the end of the conference, the book remained at #6 on the best seller list although other top books get shuffled around. I finally got a JavaOne best seller under my belt! :) Here is the final tally:

Picture 1.png

Interests in JBoss Seam is Very High in JavaOne

Wednesday, May 9th, 2007

Last night, we had two Seam-related BoFs in JavaOne. Kito Mann and myself presented "Extend and Improve JSF with Seam" at 9pm, and then Petr Pisl and I presented "Rapid Seam App Development with NetBeans" at 10pm. Despite the late timing, the first BoF attracted around 150 to 200 people, and the latter one attracted around 80 people. That was more people than some afternoon technical sessions! I have presented on JavaOne BoFs for years and those were the best turn-outs I have seen. Seam is the way to go!

We will post more materials -- slides, demos, and update software -- from the sessions very soon (after I recover from all the partying in San Francisco! ;)). Stay tuned!

The Most Stolen Book in JavaOne?

Wednesday, May 9th, 2007

My new JBoss Seam book came out just in time for the JavaOne conference. The publisher (Prentice Hall) brought 5 copies of the book for display in their booth as well as in the Red Hat booth. Well, before the day's end, we only have 2 copies left! The display copies are simply disappearing from the booth as people walked by! ;)

41vCXc6lGUL._AA240_.jpg

It is hard to imagine that people paying $5000+ to attend JavaOne would "steal" a $40 book on the show. They probably think that the display copies are vendor freebies? But then, this does not seem to happen to other books and certainly never happened in the vendor booths I had worked in the past 3 JavaOne conferences (we have books on display every year)!

Anyway, we will be running out of display copies very soon at this rate. But here is a tip: there are plenty copies in the JavaOne official book store -- along side with my Java ME best seller "Enterprise J2ME". So, bring it on! Go steal that book!

PS. That just remind me an episode a year ago when my "Nokia Smartphone Hacks" book made the "daily most downloaded book" on popular BitTorrent site Mininova. Well, I am flattered and offended at the same time!

Google Mobile Maps versus Yahoo! Go

Wednesday, April 25th, 2007

Mobile local search is obviously one of the biggest opportunities for Internet search companies like Google, Yahoo, and Microsoft. According to this New York Times article:

“The biggest growth areas are clearly going to be in the mobile space,” Eric E. Schmidt, chief executive of Google, said when asked about new opportunities at a conference here this week. In case his point wasn’t clear, Mr. Schmidt drove it home: “Mobile, mobile, mobile.”

Well, I have been using both Google Maps and Yahoo! Go for some time. They are both excellent J2ME applications. Here are some of my thoughts:

What I like about both apps

Both Google Maps and Yahoo! Go are very usable mapping applications. They can find locations by address or business names (even incomplete ones), display area map, support multiple levels of zooming, and support easy scrolling / panning. Leveraging the multi-thread mobile application runtime, they both fetch new map images tiles in background -- and hence they are much more usable than displaying static maps on a mobile web page.

Local business search is built into both applications. When you enter a search phase, the application searches for businesses in the vicinity of your current location and marks the business locations on the current map. You can then access information of those businesses by pressing the corresponding number key. You can call any business from the app if it has a phone number listed. You can get driving directions to/from that location. You can also see reviews and ratings in Yahoo! Go.

The turn-by-turn driving directions are handled very well on both applications. You can view each turn instruction with its corresponding map like a slide show -- using your keypad to navigate to the next/prev turn. The experience is quite like having a real GPS in your hand.

Screenshot0061.jpgScreenshot0060.jpg

What I like about Google

While Google Maps is not full screen (this seems to be a big oversight), it manages to display maps in finer details than Yahoo (see below). I think high map resolution is crucial for mobile phones -- it reduces the need to zoom in and out just to see a street name. Somehow, the maps from Yahoo! Go look very clumsy on the mobile and there are too few street names on the Yahoo Map -- you have to zoom really close to see the street name and then zoom back out to see the overall area.

Typical Google Maps:
Screenshot0055.jpgScreenshot0054.jpg

A typical Yahoo map:
Screenshot0051.jpg

Google Maps is more stable than Yahoo! Go. The Yahoo application occasionally freezes if you try to do too many things too quickly (it even freezes if you try to zoom too quickly). That is highly annoying on a mobile phone. I almost never encountered a freeze on the Google application.

The overall workflow of Google Maps is also more efficient than Yahoo! Go due to the support for "saved" locations. In Google, you can save any address (or search result) in a "favorite" list. You can then go to any saved point directly to view its surrounding map, get driving directions to/from it, and search businesses / locations around it. When you select a search result anywhere on the map, you can also easily choose a location from the favorite list to calculate the driving directions. It is very useful if your trip has several stops. Yahoo, on the other hand, do not provide an easy mechanism to save locations temporarily. You can only save Yahoo locations on the Yahoo web site and then access the saved list from the phone. That quite severely limits the usefulness of the mobile client. Of course, Yahoo has a very nice "auto-completion" feature in its input box that makes finding previous locations a little easier (see more on this later).

Google Maps makes better use of the numeric keypad to provide quick access to saved address lists, search results, driving directions, zooming, and other important menu functions. Yahoo! Go requires you to use the softkeys (or the joystick) to navigate, which is just a lot slower than shortcut numerical keys.

Google Maps provides satellite images as well as street maps. I find that quite useful when the streets are confusing. Yahoo does not offer that feature.

Screenshot0062.jpg

Mapping applications are bandwidth intensive. I can easily consumer more than 1 MB of data in one day while I am on a trip. The kilobytes gauge on Google Maps is useful when you are on a metered Internet connection. It allows you to see how much bandwidth you have consumed in the current session. It would be nicer if the bandwidth gauge is saved in a persistence storage and collect data across different sessions.

What I like about Yahoo

Now, you might think that I like Google Maps much more than Yahoo! Go. But that is far from the truth. ;) Mobile applications are like icebergs -- they are 10% mobile UI and 90% server support. IMO, the strong point of Yahoo! Go is its tight integration server services. In contrast, Google leverages little server services other than geo-coding, map rendering, and local business searching.

Yahoo! Go incorporates a complete Yahoo search engine. You can search any term and get a list of businesses / locations back. You can view the details of each search result including its ratings, reviews, or even go to its web site -- Yahoo! Go reformats the web site and fits it into your mobile screen. Google, on the other hand, offers a much less sophisticated local search engine. When you enter a search term in Google, it just marks the returned locations on the map. Each Google location only has an one-line title. It is sometimes woefully inadequate -- I tried to search for USPS post offices on Google Local Mobile: it returns some shipping supply shops and USPS pickup locations, but gives me no way to tell which one is the real post office.

Screenshot0058.jpgScreenshot0059.jpg

In addition, Yahoo! Go integrates personalized news, stock quote, email etc. from your Yahoo account all into one application. Of course, that is beyond the scope of a "mobile map" application but I find the highly integrated user experience very appealing.

Besides tight server integration, Yahoo! Go also offers several mobile UI features Google lacks: The Yaoo app is full screen -- very important for mobile phone apps. The text input box in Yahoo! Go remembers all the phrases you typed in the past and offers auto-completion suggestions as you type.

The verdict

I guess the bottom line is that I liked both applications. I find myself using Google Maps more often while I am driving / walking around since it has better maps. But when I am at a place and try to plan the next destination, I almost always use Yahoo! Go to take advantage of its better search features.

The missed opportunities with Yahoo! Go

Tuesday, April 24th, 2007

Yahoo! Go is a mobile application that I use every day. It integrates with my personal online Yahoo account to provide mobile access to Yahoo email, customized news and RSS feeds, stock quotes, local maps, flickr photos from friends, and local search. It has a very slick mac-like UI that allows me to thumb through the screens quickly. Overall, the Yahoo! Go rich client user experience is much much better than the Yahoo Mobile thin client web site.

Screenshot0063.jpg

Yahoo! Go is only available on a selected list of Java devices -- the idea is that the application will be "ported" and customized for each device for the best user experience. For instance, on my Nokia N80, the application graphics are optimized to look good on the large screen. However, IMHO, Yahoo! Go's device-specific port is superficial at best. It misses some real opportunities to take advantage of what the device has to offer.

For instance, my Nokia N80 supports the J2ME File Connection and PIM API. That means the Java app will have permission to write to the local file system. Then, why on earth did the N80 version of Yahoo! Go NOT offer an option to save a Flickr image to the device gallery? If the image could be saved to device gallery, I would have been able to use it as the wallpaper or do any number of cool things with it.

Screenshot0065.jpg

Instead, Yahoo! Go took a "lowest common denominator" approach with the application -- it only provides features that are common to all the phones it support and focuses the porting effort on polishing the UI. I believe that is the wrong approach. If we are porting a J2ME app to multiple devices, we should take max advantage of the device's built-in features.

Photo-realistic 3D driving games on Java mobile phones

Monday, April 23rd, 2007

It seems that all major game developers have ported their best 3D driving games from consoles to Java handsets in the past couple of months. For less than $10 / game, you can now enjoy "Project Gotham Racing", "Need for Speed: Carbon", "Asphalt Street Rules" and more on your mobile phone -- all in stunning 3D graphics.

NFSCarbon_176x208_anim.gif pgr3D-s5.jpg asphalt-street-rules-anim.gif

I have tried a couple of them on my Nokia N80, and have to say that they are exceeding all my expectations. In terms of graphics, well, they rival the original games on my XBOX. Of course, the keypad controls on the phone are not as good as the Xbox controller, the phone CPU is occasionally slow to render complex 3D scenes (i.e., buildings pop up ahead of you as you drive), the frame rate is probably low at less than 10 frames / second, and battery life is a concern if you play the game for a couple of hours a day. However, the ability to play photo-realistic driving games while you are in a boring meeting is priceless. :)

Now some people might ask: how is it possible to run photo-realistic 3D video games on a mobile phone? Isn't the screen too small for that? Well, the mobile phone screen may be small but it certain has enough pixels to render complex graphics. My Nokia N80 has a resolution of 352x416 pixels -- that is significantly greater than the resolution of standard TV signals. If you can play video game on your standard big screen TV, you can certainly play it on the high end phone! The screen shots shown above are at the lower 176x208 resolution.

With new devices like the Nokia N95, which provides hardware 3D acceleration support, Java 3D experience can only get better on mobile phones!

If you have a highend Nokia / Sony Ericsson phone and not done mobile gaming, you need to check out those games. They are truly eye openers.

First Release of Seam Plugin for NetBeans!

Tuesday, April 17th, 2007

Update: Use the 0.2 version of the plugin for Seam 1.2.1 GA and JBoss AS 4.0.5 GA.

Petr Pisl of Sun has just released a first-look Seam Gen plugin for NetBeans. It allows you to generate complete Seam CRUD applications in NetBeans much the same way Red Hat Developer Studio allows you to do in Eclipse. I am extremely excited. So, here is a mini tutorial with some screen shots (taken from a Vista box -- NetBeans look pretty good on Windows Vista).

Tutorial

1. Download and install the Seam module in NetBeans 5.5.1. We recommend you to install the Facelets support modules as well. Use "Tools -> Update Center -> Install Manually" to install those nbm files.

2. Install JBoss AS 4.0.5 with EJB3 support and set up a database with some existing data. Register the JBoss server and database connection in NetBeans. This is standard NetBeans stuff. If you are not familiar with that, read the Notes at the end of this post. You should see something like this in the Runtimes window after you are done.
seamgen01.png

3. Use "Files -> New Project" to create a new Seam project. You need to point it to the Seam 1.2.0 PATCH1 installation directory. You need to also specify the JBoss AS instance and the database connection registered in NetBeans.
seamgen02.png
seamgen03.png
seamgen05.png

4. The project is then created. You can open any XHTML file to see the capability of the Facelets support module (e.g., syntax highlighting, auto-completion etc.)
seamgen06.png

5. Right click on the project and select Deploy to build and deploy the project to the selected JBoss AS instance.
seamgen07.png

6. Start the JBoss AS server in the NetBeans server manager.
seamgen08.png

7. You can see the basic web page in your browser.
seamgen09.png

8. Select "New -> Files" in the project and select generate-entities to generate a complete CRUD application based on the data in the database connection.
seamgen10.png

9. Java classes and UI XHTML files are generated into the project.
seamgen12.png

10. Deploy the app and refresh your browser. You now have a complete AJAX CRUD application (see it in action here).
seamgen13.png


Notes: Set up JBoss and database server

a. Install JBoss AS 4.0.5 GA from the installer and choose the EJB3 profiler when asked.

b. Register the server in NetBeans via "Runtime -> Servers -> Add Server" in context menu and select the JBoss AS installation directory.

c. Download and expand the following zip file for a HSQL database, and start the database by running the runDBServer script. Of course, if you have an existing DB running, you can skip this step.

d. Add the DB driver via "Runtime -> Databases -> Drivers ->New Driver" in context menu and select the hsqldb/lib/hsqldb.jar file. If you are using other DB servers, you need to add its JDBC driver.

e. From the context menu over the added HSQLDB driver, select "Connect Using ..."

- Database URL: jdbc:hsqldb:hsql://localhost:1701

- Username: sa

- and the schema is PUBLIC

That's it!

Are Rails and Grails Scalable?

Wednesday, March 28th, 2007

Note: Some people keep complaining that I mistook "performance" with "scalability". Please READ THE ARTICLE! I am talking about the performance *decreases* with increased number of threads. That is *scalability*. Please read before your comment on it again!

The short answer is no and here is why: Graeme Rocher, of the Grails fame, recently posted a simple benchmark comparison between Rails and Grails. While Grails beats Rails in the benchmark, it looks to me neither of them is scalable in a multi-core environment. From our internal tests, JBoss Seam easily out-performs both. ;)

Let me begin by saying that I admire Graeme's coding skills -- Grails is an excellent framework and JBoss Seam is built on many of the same ideas. But benchmark results like the following really do not bode well with Grails or Rails:

testD_overall.png

It shows that the overall throughput decreases significantly when Ruby processes increase from 1 to 10, or Tomcat threads increase from 10 to 25. From my own experience in performance testing, that is a tell-tale sign of CPU contention in synchronized code blocks or collection objects. CPU contention does not happen very often on single CPU machines. However, it happens a lot on multi-core (or multi-CPU) systems, which this benchmark is tested on. Basically the CPUs are all waiting to access a single block of synchronized code or object. If you do a JVM thread dump here (or something equivalent in Ruby), you will see most threads are waiting and the CPU load slowly creeps up to 100% as the backlog increases.

Another way to see the CPU contention is to look at application response times. When the CPUs start to wait upon each other, some threads would hang and produce extremely long response time for some requests. So, let's look at Graeme's response time graph. The max response times are indeed extremely long -- consistent with hang threads. Actually, in this scenario, the mean value of the response time is meaningless since they are screwed by the long response times (i.e., the distribution is no longer normal). The median response time would be a much more robust gauge for user experience here.

testD_averages.png

Since the benchmark application itself is very simple, it is very unlikely that the contention point is in the application. It has to be in the framework or in the underlying application server. In JBoss, we try very hard to eliminate the contention points in the application server (and in Tomcat). As a result, frameworks like JBoss Seam can easily outperform Grails or Rails based on our internal tests (cannot publish numbers yet. Take my word with a grain of salt! ;)) ... That is a huge benefit you get by choosing "mature" application servers. ;)

In any case, I wish the best for Grails. It is probably a minor contention point that show up big time in the CRUD tests. It should be resolved with a simple thread dump (or a profiler). I am sure Graeme will be able to find it and fix it very soon!

My Seam Talks in JavaOne 2007

Tuesday, March 20th, 2007

I am running two Seam-related BoFs on the first night of JavaOne 2007.

BOF-4400: Improve and Expand JavaServer Faces Technology with JBoss Seam
May 8th, 9pm, Hall E - 134 (Moscone Center)
By Michael Yuan and Kito Mann

BOF-9792: Rapid Seam Application Development with the NetBeans IDE
May 8th, 10pm, Gateway - 104 (Moscone Center)
By Michael Yuan and Petr Pisl

Come and chat with us if you are going to JavaOne!

In addition, Gavin is giving two technical sessions on Seam and WebBeans JSR. Make sure that you attend those too! :)