Have You Seen This?
I upgraded to the latest IntelliJ IDEA 6.0.5 today. And I'm seeing some weird error messages when I ran JUnit 4.3.1 unit tests:
Exception in thread "main" java.lang.NoSuchMethodError:
org.junit.internal.runners.MethodValidator.validateAllM
ethods()Ljava/til/ist;
This is with JDK 1.5.0_11 on Windows XP Por SP2.
Is it just me, or are you seeing something similar?
Can I Turn The Stupid XMLHttpRequest Thing Off
Enough of this AJaX non-sense!
See what it did to my browser:
... all because some webapp (which shall remain nameless) decided it's a good idea to hog the UI thread waiting for some AJaXy response from the server, for more than three minutes!
Oh, Isn't It Cute?
(This post is an exercise in using Creative Commons licensed Free Art.)
Mozilla Developer Center beta: His name is Kit … Developer Kit.
Web developers: there is a new ally in the fight for open standards on the web, and while he only looks to be about a foot tall, he appears to be extremely effective. He took SXSW Interactive 2007 by storm, and has already been on DL.TV. He’s just a young little fella, so we call him Kit … Developer Kit.
I've been using Mozilla® and Firefox® for many years, on many platforms, and free of charge. It is natural that I would like to help them spreading the "Use Open Standards" message.
[*] Mozilla is a registered trademark of the Mozilla Foundation.
[*] Firefox is a registered trademark of the Mozilla Foundation.
[*] The above art is created by Sean Martell and licensed under the Creative Commons Attribution-NonCommercial 3.0 Unported license.
Printer-Hostile Web Pages? OpenOffice.org To The Rescue
A while back (840 days ago, to be exact) I blogged about the NVU HTML authoring tool and its use in reformatting and printing printer-hostile web pages.
Well, NVU 1.0 was released in June 2005. And I have been using it to good effect. However, for some reason, NVU development stopped, and the download site still shows a binary for Fedora Core 3, even though the current version of Fedora Core is FC6. And I couldn't find NVU in FC6's own yum repository. I could download the distribution-agnostic version, but that would mean I have to untar it and then create a launcher icon for it by myself. It's no big deal, but like recompiling Linux kernels (which I did back in the pre-1.0 days), it gets old really fast.
So, I'm looking for an easier way. Just by luck, I clicked on the OpenOffice.org Writer icon on my quick launch bar, which has always been there since the pre-Fedora days, and pasted some random HTML into it. And guess what? It took it.
So until every web site out there becomes printer-friendly, I'll be using OpenOffice.org Writer to compensate. Here's OOo Writer in action, formatting this page:
Public Alpha Of The Next Big Thing
(Via A VC.)
A nameless Adobe PR firm person: SAN JOSE, Calif. — March 19, 2007 — Adobe Systems Incorporated (Nasdaq: ADBE) today announced that the first public alpha version of Apollo is now available for developers on Adobe Labs. Apollo is the code name for a cross-operating system application runtime that allows web developers to leverage their existing skills in HTML, JavaScript and Ajax, as well as Adobe® Flash® and Adobe Flex™ software to build and deploy rich Internet applications (RIAs) on the desktop. Apollo combines the reach of Internet technologies with the richness of desktop applications, working seamlessly across operating systems and outside the browser to deliver a more consistent and engaging user experience. The alpha version of the Apollo application runtime and the Apollo Software Developer’s Kit (SDK) can be downloaded for free from www.adobe.com/go/apollo .
Google Guice 1.0 Release Sparks Discussions
(Neal Gafter started the trend of referring to him as "crazy" Bob Lee.)
After hearing about his DI framework 57 days ago, in the context of my "erase erasure" discussion, I'm very glad to see "crazy" Bob Lee release Google Guice 1.0 as open source:
"crazy" Bob Lee: We're pleased to announce the open source release of Google's internal Java dependency injection framework Guice. Guice wholly embraces annotations and generics,
thereby enabling you to wire together and test objects with less effort than ever before. Annotations finally free you from error-prone, refactoring-adverse string identifiers.
Guice injects constructors, fields and methods (any methods with any number of arguments, not just setters). Guice includes advanced features such as custom scopes, circular dependencies, static member injection, Spring integration, and AOP Alliance method interception, most of which you can ignore until you need it.
An earlier version of Guice already powers Struts 2's plugin architecture. Google has been running Guice in mission critical applications for months, and now you can, too. We hope you enjoy Guice as much as we do.
Guice lives at Google Code. From there, you'll find the user's guide, Javadocs, and download. Please direct any questions to the mailing list.
The release sparked immediate discussions in the Java blogging community:
- InfoQ
- TheServerSide
- Stuff That Happens
- crazybob.org
- OnJava.com
- SpringFramework Support Forum
- Stephen Colebourne's Weblog
- The BileBlog
- Google Code Blog
It also sparked several rounds of discussions among colleagues in the office here. I would imagine similar discussions went on in hundreds of other places where Java developers try to solve real world problems.
Here are some aspects of the discussions that I found interesting:
The Nature of Dependency Injection
I've heard all of the following opinions:
- DI is just the Strategy pattern.
- DI is just the Factory pattern.
- DI is a pattern on its own, useful with several other patterns.
- I prefer the practice of following the DI pattern without using a third party framework.
- I use Spring's DI framework and like the result very much.
Wiring is the term that people use liberally in DI related discussions without too much discrimination. Everybody assumes that everybody else knows what it means, and that its meaning is clear-cut and uniformly agreed.
However, depending on the Who, When, Why, What, How of the wiring, it could be made to mean different things:
- internal component assembly (a Swing programmer wiring a custom Model to a GUI component)
- component configuration (setting logging appenders and levels for components)
- application configuration (selecting to use MySQL vs. Oracle database drivers)
- performance tuning (setting the size of the connection pool)
- end-user preferences (disabling JavaScript in the browser)
While one can do all of the above using Guice (or some other framework like Spring), it is not always productive to mix all these different kinds of wiring together and treat them as the same thing.
Embracing Java 5 Features
Two and a half years after the release of Java 5, I think it is time for everybody but the most conservative ("my system is done and making me tons of money, I'm not touching it") to move on to the new platform.
I also think it is time for new products and new versions of existing products to exhibit their commitment to the new platform by taking advantage of new language features like annotations and generics.
Those organizations and developers who still operate in the 1.4 platform need to feel all the pressure that associating with a legacy platform engenders.
That's why I'm really glad that Guice is unabashedly embracing annotations and generics and all the rest of the Java 5 language features.
Already, the source code of Guice is the bed for innovative idioms of Java generics, as Neal Gafter pointed out here and here.
Other surprises and a-ha's as I was browsing through Guice source include an implementation of an annotation, the use of String.format(), and the <T> T notNull(T t) template.
Guice Is Extremely Easy To Use
Guice does its job with a straightforward user interface. The User's Guide prints out to about 30 pages of easy to follow recipes. My experience with API design tells me that this is not an accident.
I'm not surprised that Eric was able to swap Guice in to replace Spring IOC in a day.
At this point I must confess that I haven't worked on a so called Spring/Hibernate project that was so prevalent in the last couple of years. And my previous experience with an DI/IOC framework consists of me working out the Pico container tutorial (boy.kiss(girl);, cute) and promptly forgot about the details; and multiple attempts at learning the Spring IOC framework, and feeling like hitting a brick wall when it comes to actually write the @#$%ed xml configuration file.
With Guice there is no XML configuration files, and that's a big win in my book.
Guice, Or Something Like It, Should Be In The JDK
About the only thing that makes feel a little bit uncomfortable is the use of Guice specific imports in my application code.
Wouldn't it be nice if I don't have to do a
import com.google.inject.*;but do a
import java.lang.inject.*;instead?
That, and the fear of the dueling frameworks scenario, where I want to use both frameworks A and B while framework A requires Guice 10.7.19 and framework B requires an incompatible Guice 10.8.1, prompt me to suggest that maybe Guice, or something like it, ought to be in the JDK.
"Keep an eye on JSR 299." was the answer.
So here's my eye on JSR 299—Web Beans. It's scope is Java EE rather than Java SE. But features of Java EE have known to migrate to Java SE.
Relation Between DI and Other Patterns
Although Dependency Injection is officially a design pattern now ("says who?" you ask. "Wikipedia. If it's on Wikipedia, it must be true, right?") in many ways it doesn't feel like a design pattern, although I can't pin down exactly in what way this pattern is not like the others.
Viewed in the narrow sense, DI is a mechanism that links a client that makes use of an interface with a concrete implementation of that interface. Many of the GoF patterns uses the abstract interface/concrete implementation paradigm. Yet I don't think it make sense to say that these patterns depend on (or include) a dependency injection subpattern.
Another clue that dependency injection is different is that it is rarely called dependency injection when done without the assistance of an DI/IOC container—it's just initialization code. It's almost like the situation with garbage collection—when done by hand, it's called memory management.
If you stop to think about it, there is a duality between a dependency injector and a garbage collector: one is where objects come from to live, the other is where objects go to die.
How About That Logo?
If you are familiar with my cute logo theory, you should recognize the genius of announcing Guice with the kid with a glass image. Although not an official logo of the project, the picture is attractive enough that it may very well serve the purpose of a logo.
"The first thing I noticed was the image. It's so cute, I have to try the Guice. I took one sip and am hooked!"
Eric Burke: Java Concurrency By Example
We had an outstanding presentation at the St. Louis JUG yesterday evening. Eric Burke, of the It's Just a Bunch of Stuff That Happens fame, gave a presentation on some of the new Java 5 and 6 concurrency features, through a series of examples. Like in the past, this is another one of those "you have to be there to experience it" presentations.
Here's what I learned from this presentation:
- The Java Concurrency in Practice book, by Brian Goetz, with Tim Peierls, Joshua Bloch, Joseph Bowbeer, David Holmes, and Doug Lea, is a must read for anyone developing Java applications on a modern Java platform.
- Have you written something like this
try { Thread.sleep(1000); } catch (InterruptedException e) { // ignored }This is completely wrong. - i++ is not atomic.
- The new concurrency utilities package in Java 5 and 6 is very rich. It's worth studying in depth.
- TimeUnit
- CopyOnWriteArraySet
- Use a ThreadFactory to create threads and give them proper names instead of the default "Thread-1", "Thread-2" and register UncaughtExceptionHandler's.
- Executor, Future
- Lock, tryLock(), lockInterruptibly()
- ReadWriteLock
- BlockingQueue
- Here's how a thread should be written
new Thread() { public void run() { while (!Thread.currentThread().isInterrupted()) { // do the work... } } }
At the meta level, I think the lesson is there are so much stuff that's new in Java 5, that it's worth learning it anew.
On a different topic in the post presentation chats, Eric mentioned that the latest Java 6 have many improvements over Java 5. And if you are upgrading from Java 1.4, you might as well skip Java 5 and jump directly to Java 6
Quote Of The Day
Dr. Heinz M. Kabutz (in The Java Specialists' Newsletter): Migrating is migrane and grating rolled into one!
Erasure To Be Erased In Java 7
Peter Ahé: Alex and I are on stage at EclipseCon 2007 waiting to give our presentation, unfortunately this means that we are missing Scott Adams who we can hear from the conference room next to ours.
The "presentation" is about Java SE 7 Language Features. I'm delighted to see that my call to "Erase Erasure" 45 days ago made it into the Java 7 feature list (page 12):
Today's Task: Explain Just Copy My War File Into Your Webapps Folder
My contention is that you can't explain "just copy my war file into your webapps folder" without
- first training him into a Java developer
- and then teaching him the full Servlet Specification
- and then showing him how a war file is really a jar file in disguise
- and then how a jar file is nothing but a zip file
- and that a zip file is sort of like a directory
- and that the webapps folder is inside your servlet container
- and that the servlet container will unzip your war file and put the result into a directory whose name is the same as the war file without the war extension
- and that that directory name is really your context
- and that the context is really something that you put at the end of your URL
In other words, forget about it.
Java News Brief (JNB): Introduction to Grails
The March issue of the Java News Brief (JNB) is out. Jeff Brown gives an introduction to Grails—the "framework for agile web development using Groovy and Java."
Jeff Brown: Grails is a remarkably flexible framework while maintaining an ease of use that is unparalleled by other web application frameworks targeted for the JVM. Use the exercises in this article as a jump start with Grails and have fun exploring the possibilities.
Software Update: I Don't Want To Restart Now!
Both Firefox and Thunderbird have instituted automatic software update features whereby the browser and email reader periodically check their home sites to download any updates. This is a good thing, in my opinion.
However, both programs has also gotten into the habit of popping up a message box, the moment the download is complete, asking "Hey, new updates are here. You need to restart?" And I can choose either "Now" or "Later."
This is annoying. Just think about it: I've been using the old version of your product for months, and things are just fine. And I start and quit Firefox and Thunderbird all the time, at least several times a day. (With Firefox routinely taking up 200M of memory, and not to mention the AJaX induced CPU load, nowadays, I have to close it down from time to time.) Can the newly downloaded stuff wait quietly for just a few more hours for one of my restarts?
And what if I accidentally clicked on the "Now" button? I'd loose my "place"—all the tabs I have opened, and the form I'm in the middle of filling out will be gone. That'll make me very angry. Enough to write a blog entry bashing your feature.
thereby enabling you to wire together and test objects with less effort than ever before. Annotations finally free you from error-prone, refactoring-adverse string identifiers.