Archive for the 'java' Category

Java Conference ‘05

I’m blogging this from the exhibition floor of the Java Conference ‘05 in Milan, where we have a presence. You’d expect that technical conferences like this one have free WiFi connectivity, but yesterday the only access point that I could detect led to a gateway page for a for-pay service.

Today I discovered an open access point instead. I don’t know if it is open on purpose but it doesn’t seem to be provided by the organization. Anyway, HTTP works, ssh works and Skype works, but IMAP, POP and AIM do not go through. Strange.

I briefly stuck my head into the room where Craig McClanahan was extolling once more the virtues of JSF but after five minutes I decided I wasn’t interested. In the afternoon I plan to attend the session by my namesake Ugo Landini on patterns, which promises to be entertaining. I wonder whether there’s going to be WiFi in that room.

Mozilla Rhino to be included in J2SE 6.0

rhino50.jpgLooks like the next release of Java will have support for Javascript built-in:

Another language-related JSR planned for Mustang is JSR 223. This defines a framework to allow scripting language programs to access information developed in the Java platform. We currently plan to integrate this into Mustang for b40. Aside from the framework, we will also include a JavaScript engine based on the Mozilla Rhino implementation. Later, we hope to include a scripting shell that is script language independent. This will be a very cool way to create a prototype, do some exploratory coding, and learn new APIs.

This is incredibly important for Cocoon, whose Flowscript is currently based on Mozilla’s Rhino Javascript interpreter. Actually, the Flowscript is somewhat language agnostic, but the only working implementation right now is in Javascript.

In the past there have been doubts concerning the viability of Rhino and its licensing terms, but when it’s become an integral part of the J2SE platforms, there will be no more doubts.

Now the question is: How long will it take to add continuations support to Groovy, so that developers will be able to choose between two great scripting languages for their flowscripts?

(Via Dion.)

The Open Source Zone - Tech writeup

oszone-beta.gifThe Open Source Zone is a web application that exploits a large number of Open Source libraries, frameworks and services, namely:

It would have been impossible to create The Open Source Zone in such a short amount of time if all this great code had not been contributed to the Open Source community. Our most sincere thanks go to the people who created these packages.

The heart of the system is a Java web application whose main building blocks are:

The Spring Framework, a powerful container based on dependency injection, which is used to configure and bring together the services provided by the other components, most notably Hibernate and Lucene.

Hibernate, an object-relational mapping (ORM) framework which guarantees the persistence of Java objects by abstracting away the relational model of the underlying database and hiding the complexities of JDBC programming.

Apache Lucene, which is used to provide indexing and search services.

Apache Cocoon, a powerful, XML-based web application framework, which implements the presentation layer and manages the flow of user interactions using an innovative continuations-based approach.

Spring, Hibernate, Lucene and Cocoon, together with the PostgreSQL JDBC driver are hosted inside the Jetty servlet container.

Storage of data is guaranteed by the PostgreSQL Relational DataBase Management System (RDBMS). The interface between the Java application and the RDBMS is managed by the PostgreSQL JDBC driver.

The Apache HTTPD 2.0 server is placed in front of the Jetty Servlet container as a caching proxy, using the mod_proxy and mod_cache modules. This solution provides the following benefits:

  • Static resources (images, CSS stylesheets, Javascript files) are served directly by Apache HTTPD and don’t cause unnecessary load on the Servlet container.
  • Infrequently changing data can be cached and served directly by Apache HTTPD without forwarding requests to the Java application and to the database, thus ensuring larger scalability in case of numerous concurrent requests.
  • When the Java application must be taken down for maintenance and upgrades, Apache HTTPD can show a warning page, informing users of the downtime and avoiding the dreaded “Connection refused” message.

Load balancing and clustering could be implemented in the future, simply by having one HTTPD server forwarding requests to more than one Java application server.

The exact configuration of Apache mod_proxy and mod_cache is similar to the one used by Pier and described in this wiki entry.

All The Cool Open Source Apps are in PHP

Timothy Fisher: “It seems like most of the cool end-user web applications are written in PHP. This is an area in which the Java community is way behind the PHP community.”

Having recently switched from a Java application (blojsom) to a PHP one (WordPress) for this blog, I might be tempted to agree. Particularly, it’s undeniably true that:

The open source Java community seems to be consumed with the creation of the latest and greatest framework.

Still, I’m Java programmer and I am writing my next great web application in Java. Having seen some of the PHP code from WordPress, I’m not eager to dive into more of it.

Google Video Uploader for the rest of us

Thanks to the portability of Java programs (Write Once Run Anywhere is true), the Google Video Uploader client is now available for the Mac, Linux and all platforms with Java. The Mac version is also nicely packaged as a DMG (Disk image) file that you just have to open, then drag and drop the application to your Applications folder. No installers, no setup, no stupid registries.

GoogleVideoUpload.jpg

Google Blog: A Video Uploader for the rest of us: “Anyway, now you can sign up for the Google Video Uploader for Macintosh, and ditto for Linux (and UNIX and Solaris and HP-UX and AIX and lots of other platforms). The same sign-up page goes to to the Windows version too. So now I can ponder a different problem - namely, which of my videos I want to share with the world.”

Gosling on Harmony

Image1-large.jpegIt seems now clear to me that James Gosling, as previously demostrated, does not have a clue when it comes to Open Source and his latest remarks confirm this.

Thanks to J Aaron Farr for nailing down his FUD about the GPL (since when has the ASF distributed GPL code?) and his ridiculous claim that by opensourcing Java, “any old person could check in stuff”.

On the other hand, I still have doubts about the supposed “clear need” for an Open Source J2SE claimed by Harmony supporters.

To me, it’s all about risks. While there’s a risk of Sun folding down or being acquired and stopping all Java development, the risk of spending an inordinate amount of time and energy on a project that — assuming it ever produces a release — won’t deliver much more than what Sun’s JVM delivers right now is much bigger. Of course, I might be wrong.

There’s Harmony in the Java world

By now, everybody who has an interest in Java is aware of this:

We propose that we create a new Apache project, Harmony, that will
achieve the following goals :

1) create a Compatible, independent implementation of J2SE 5
   under the Apache License v2

2) create a community-developed modular runtime (VM and class library)
   architecture to allow independent implementations to share runtime
   components, and allow independent innovation in runtime components

What I haven’t seen appearing yet are speculations, informed or otherwise, regarding the motives that got project Harmony started.

With all the J2SE implementations that exist, is there a need for yet another one? I think the answer is yes.

Fact is, Apache has an incredible amount of Java projects. Being at the mercy of one (Sun) or more (IBM, BEA, …) vendors is a big risk. And now, with J2SE 5, it is finally legal to create a compatible, Open Source implementation.

Of course, reaching the goal of a complete J2SE implementation starting from a clean slate is a daunting task. I hope it’s not so big that by the time it’s finished the target has shifted too much (i.e. Java 6, Java 7, …).

Tiger for Tiger

This puts to rest all my doubts about the availability of Java 5 for OS X 10.4 “Tiger”.

An interesting tidbit of info is that: “This release does not replace the existing installation of J2SE 1.4.2.” Good news for those developers who have to ensure compatibility of their apps with Java 1.4.

The SWT vs. Swing Controversy

I haven’t been doing “rich client” applications for a long time and did just a little Swing development at the times of Java 1.2, preferring to concentrate myself on web applications instead. With all the new developments around the concept of “Rich Internet Applications”, Ajax and the like, I don’t think I’ll be doing GUI development in Java at least for the foreseeable future.

However, I read with the utmost interest the comparison between Swing and SWT that was published today on Hacknot. You never know when you you might find yourself in the kind of situation described in the article: being forced by the management to adopt a technically inferior solution for no apparent reason.

The article is, as usual for Hacknot pieces, quite long and well documented. I suggest you read it all by yourself, but if you’re lazy, I’ll quote the main conclusions:

My prediction is that SWT will continue to limp along in support of Eclipse; neophytes will continue to discover it and sing its praises until such times as they’ve used it enough to realize its limitations; the uninformed will continue to attach a significance to platform fidelity that their user base does not; and marketers will continue to talk of SWT ‘taking over’ from Swing - as they have for the last three years - despite the lack of evidence that such a takeover is actually occurring. I expect the enormous maintenance burden incurred by SWT’s multiple code bases to become the limiting factor in its ongoing development, and cross-platform stability and consistency to remain ever elusive as SWT rushes to keep apace of the progress and initiatives amongst the native widget sets of different platforms. Any claims to better performance will finally be abandoned in the face of increasing capabilities of the average PC, leaving SWT an anachronism without a raison d’etre.

Ten years of Java

logo_java.gifI didn’t notice, but looks like last Friday marked the 10th anniversary of the birth of the Java language. I should have really paid more attention, as for me Java was a very important part of my working life in the last ten years. Here is my personal timeline:

1995 - Java announced but not much more than a curiosity.

1996 - I start off with Java by reading David Flanagan’s Java in a Nutshell.

1997 - Java Servlet Developers Kit released. I realize that developing web apps with servlets is much easier than with CGI Perl scripts.

1998 - Java2 platform shipped. Now we’re getting serious! Also include Swing, which is much better than AWT.

1999 - I start doing some work with Apache Cocoon. Sure beats doing out.print(”“), but actually I had already discovered XSL-T and used it with a self-made framework.

2000 - I start reading about EJB, thinking that sooner or later I’ll be using this very cool technology. Five years later, EJB is out of fashion and I still haven’t developed a single application using it.

2001 - Cocoon 2.0 released. Big improvement over Cocoon 1.

2002 - Not much happening this year.

2003 - Cocoon 2.1 released. I start using Hibernate to develop database applications. Bye bye, straight JDBC!

2004 - Dependency Injection-based containers are all the rage and I start using Spring together with Cocoon and Hibernate. A very powerful combination.

Character encoding is a PITA

I don’t know if it’s just us, but we seem to periodically run into the same troubles concerning character sets in Java web apps. This time I got bitten once again by the bug that causes international characters entered into an HTML form field to come out as an unintelligible string of random symbols when displayed on another page.

Some time ago, I came to the conclusion that if we used UTF-8 everywhere, we’d have had less problems. And, indeed, by encoding all files in UTF-8, setting container and form encoding to UTF-8 in web.xml, ensuring all pipelines are serving UTF-8 streams, putting relevant <meta> tags in the HTML output, specifying UTF-8 as the charset in JDBC connection properties and having an UTF-8 encoded database, when a problem comes up it is a safe bet that someone, somewhere forgot one of these precautions and fixing it is usually just a matter of finding where.

Until today, at least. Today I spent a few hours fighting with this kind of bug and painstakingly reviewing everything in order to make sure that UTF-8 was specified everywhere, to no avail. At last, I gave up and set page encoding to ISO-8859-1 and everything is now hunky dory again.

Sometimes I wish all the world stopped using national character sets and everything was encoded as 7-bit ASCII once again. 127 characters should be enough!

Nutch Page Ranking

Nutch logoI’m presently doing some experiments with Nutch, the Open Source search engine that has recently been moved to the Apache Incubator.

I’ve been reading about how Nutch’s Open Source ranking algorithm is supposed to be better being open, but I couldn’t find — either googling around or nutching around ;) — a complete description of how it ranks pages. Does it take into consideration inbound links like Google’s or not? I’d really like to know.

LazyWeb: How to create an Image from a byte array using JAI

Dear Web,

I have the following problem: I need to adapt some code that reads an image from a file using JAI to read it from an array of bytes having exactly the same content as the file. The code for reading from a file is quite simple:

RenderedOp img = JAI.create("fileload", "filename.jpg");

My problem is that I don’t have the JPEG file on disk, but it’s in memory inside a byte[] and I guess that I should do something along the lines of:

RenderedOp img = JAI.create("WHOKNOWS", data);

Or:

RenderedOp img = JAI.create("WHOKNOWS", new ByteArrayInputStream(data));

I couldn’t find anything googling around, the JAI documentation is a mess and the FAQ is of no help.

Please help! What operation name should I use instead of “WHOKNOWS”, assuming what I’m trying to do is even possible?

Please note that the byte array does not contain a raster, but a JPEG-encoded image.

Security update makes Java unusable on OS X

If this is for real, I will hold off upgrading to 10.3.9, which I planned to do later today. On the other hand, I’ running the stock JDK and not a developer release, so maybe this doesn’t apply.

Mark Watson: “This morning when applying the latest software update zapped Java, I just went ahead and did an OS X re-install followed by re-applying security patches, etc. About 90 minutes wall clock and about 20 minutes of my time wasted.. eerrrrrr….”

By the way, there is no evident comment or trackback link on Mark’s site, so I hope he’s checking his referrer logs.

No Tiger for Tiger or …?

Some people are lamenting that the upcoming OS X 10.4 (a.k.a. Tiger) release won’t include Java5 (a.k.a. Tiger).

Bruce Werner: “Apple is on an upswing with code monkeys like me, with Powerbooks turning in to the developer tool of choice for Java development, both J2EE and j2SE. So why is Apple falling flat on the Java front? Waiting till OS X 10.4 released is barely permissable, but not including Java 5.0 in even this OS release but perhaps releasing a Technology Preview is inexcusable. This has been a part of some heated debate in the Java community, and rightfully so. Either just put it in /usr/local/ and seed it out to Sun and backport the CoreAudio.jar as Technology Previews, or step up to the plate, SWT looks better in Max OSX anyway, and that had no Sun or Apple involvement.”

Others are saying that it will. I’m confused. I know that people who have put their hands on a nearly-final release of Tiger are probably under an NDA, but maybe someone could leave here an anonymous comment.

Growing Groovy

groovy-logo.png
James Strachan: “I'm really proud of the team and what we've achieved with the new Groovy JSR 01 release that's just gone out. Who-hoo!

This is the first full release of the JSR version of Groovy; we've integrated the new parser, got it well and trully bedded down and all our test cases pass (finally :). This was a huge amount of work and I'd like to thank all those on the team who worked real hard to get Groovy-JSR stable.”

This is really great news. I had lots of expectations regarding Groovy, but decided to hold off until the viability of the project looked better and the constant bikeshedding arguments over the syntax had ended. I must say that the future looks definitely brighter now. Keep up the good work!

Comparable vs. equals()

I just spent a few hours debugging a strange bug, whereby I couldn't add some elements to a Set even though no element already contained in the Set, when compared for equality to the element to be added, resulted to be equal. In other words, I could not add an element to a Set, even though the Set did not actually contain the element.

After having printed all the involved variables before insertion, a couple of JUnit runs confirmed that this was indeed the case, while I had spent the previous three hours chasing a bug in my persistence code that was not there, and not even in Hibernate.

Turns out the Set was actually a TreeSet, and the objects contained in the Set implemented the Comparable interface. Looking at the Java docs, I came upon this:

Comparable (Java 2 Platform SE v1.4.2):

The natural ordering for a class C is said to be consistent with equals if and only if (e1.compareTo((Object)e2) == 0) has the same boolean value as e1.equals((Object)e2) for every e1 and e2 of class C. Note that null is not an instance of any class, and e.compareTo(null) should throw a NullPointerException even though e.equals(null) returns false.


It is strongly recommended (though not required) that natural orderings be consistent with equals. This is so because sorted sets (and sorted maps) without explicit comparators behave 'strangely' when they are used with elements (or keys) whose natural ordering is inconsistent with equals. In particular, such a sorted set (or sorted map) violates the general contract for set (or map), which is defined in terms of the equals method.


For example, if one adds two keys a and b such that (!a.equals((Object)b) && a.compareTo((Object)b) == 0) to a sorted set that does not use an explicit comparator, the second add operation returns false (and the size of the sorted set does not increase) because a and b are equivalent from the sorted set's perspective.”

I incorrectly assumed that Set.add checked for equality via the Object.equals method! My compareTo method, on the other hand, used only a subset of the fields used by equals, since the other fields did not matter, as far as sorting was concerned. Well, according to Java, this is wrong.

I should also have remembered Item 11 from Joshua Bloch's Effective Java: “A class whose compareTo method imposes an order that is inconsistent with equals will still work, but sorted collections containing elements of the class may not obey the general contract of the appropriate collection interfaces (Collection, Set or Map).”

You'll never stop learning!

Is this blog appropriate for javablogs.com?

I had a couple comments from readers who found some of my posts syndicated on javablogs.com which had nothing whatsoever to do with Java. OK, folks, you're right.

javablogs.com

So, I changed my javablogs syndication settings so that only posts from the devel category will be fetched. I won't promise that the devel category will exclusively be dedicated to Java, but mostly it will be, directly or tangentially.

Hibernate 3.0 released!

Hibernate logo

Hibernate 3.0 released!: “Hibernate 3.0 is the world's most sophisticated ORXM (Object/Relational/XML Mapping) solution. Hibernate3 makes it easier than ever before for Java applications to interact with persistent data, allowing a single definition of the transformation between various in-memory representations of the entity data and the relational schema, even in the case of very complex legacy schemas and schemas for historical data or data with visibility rules. Hibernate3 also provides the most comprehensive object/relational query functionality, with three full-featured query facilities: Hibernate Query Language, the newly enhanced Hibernate Criteria Query API, and enhanced support for queries expressed in the native SQL dialect of the database.”

If you've been following this blog, you certainly know that I'm a big Hibernate fan. So I'm very excited about this release and can't wait to start using Hibernate 3. Before I start using it in production, however, I will have to wait for a Spring release with Hibernate 3 support, but I hear that's not so far away, fortunately.

IBM fed up with Java? You must be joking!

IBM backs open-source Web software | CNET News.com: “'IBM's been so fed up with Java that they've been looking for alternatives for years,' the executive said. 'They want people to build applications quickly that tap into IBM back-ends…and with Java, it just isn't happening.'”

I'll believe it when I see it.

(Via IndicThreads.com.)