Jun 30

Geronimo Congrats: Culture of the Engineer

Java, Tech 1 Comment »

I think it is very apt that the Apache Geronimo team passed the J2EE (Java EE :) TCK at JavaOne, 22 months after they began. Soon the server will be certified and time to move on to other things.

Sun has always been the cult of the engineer, and everytime I have seen the Geronimo team, they have been coding like mad men. You know that you will see them at a conference, and it will be the group huddled around hacking away.

Congrats guys. Great to see your hard work paying off, and I am excited to see what the team will get done now the tests are over and they can focus on items that developers really care about!

Jun 29

Java SE/EE/ME: Cutting 2000 to 2

Java, Tech No Comments »

Graham Hamilton’s come out at let us know the big news of JavaOne, in: Goodbye “J2SE”, Hello “Java SE”.

The 2 has always been dumb. Java 2 Enterprise Edition 5.0 makes no sense.

A friend on the No Fluff tour told a story of how Java 2 was actually going to be “Java 2000″. The engineers at JavaSoft got so offended that they started a petition arguing how lame that was, and asking marketing if they had see the success of Windows 2000? The price on the petition was for the engineers to quit if they didn’t make the change.

Urban legend has it that the change was made, but the problem was all of the JavaOne banners were already produced. What did they do? Cut off “000″ from the sign!

Jun 28

BEA endorses Spring

Java, Tech No Comments »

I am having fun seeing the usual suspects at JavaOne this year. The Sun keynotes have been a little painful from all accounts.

I went to the BEA keynote, and the CTO waffled around a little (starting off talking about 70% of us use frameworks??? I feel bad for the 30%).

After the fluffy “The Servlet API was here in 1999″, and the Adrian Colyer trinity of annotations/aop/dependency injection, we got to the meat.

BEA is supporting Spring. Rod Johnson was brought on stage to show how they are working together, and how the WebLogic console groks the Spring Beans via JMX etc etc.

I am looking forward to seeing “File -> New Spring Project” in the Eclipse based Workshop tool, being able to drop in Spring beans to WLS and have it just work, and all that jazz.

Marry that with Spring/Geronimo support, and Spring is everywhere ;)

Jun 23

Typical Benchmarks…. in Ruby Land

Java, Ruby, Tech 4 Comments »

A Ruby newbie posted to Ruby Lang that he had implemented an is_prime? algorythm in Ruby, Perl, and Java with results:

  1. Ruby result: 101 seconds
  2. Java result: 9.8 seconds
  3. Perl result: 62 seconds

Ruby lang is a great community, and over time they broke down the code and got all of the versions to fractions of these numbers.

It again really showed:

  • How micro-benchmarks are a scary beast
  • The choice of the algorythm here made the biggest difference (good ‘old Big O). The right choice with Ruby was magnitudes faster than the wrong choice in C.
  • The power of CPAN and company, where everything you ever need is already done
  • Inline C. Mmm :/
  • FAST ENOUGH IS FAST ENOUGH

That being said, having Ruby grow up from the world of the interpreter would be very cool (YARV etc etc).

Jun 22

Gravy: Using Ant from Groovy for short non-build scripts

Groovy, Java, Tech No Comments »

I recently had to whip out a one/few-off script that took a directory, and recursively grabbed jar files from it, and put all of the classes in one place. I looked at JarJar and Uberjar, but in the end it was easier to whip together a few lines of Groovy to make it happen (although I could have used Ruby, JavaScript/Rhino, Perl, etc etc).

When it came to jar’ing and unjaring files, instead of using the Java APIs, it was easier to just use ant via the AntBuilder. This allowed me in one simple line to use the tasks available there:

ant.unjar(src: file.path, dest: structure[typeOfJar].outputDir)

Very convenient. This isn’t using Ant in a more formal “I am driving the build from Groovy” way, but rather being pragmatic and thinking “oh there is a simple ant task that already does this, so lets just call into it”.

Example

def buildJar(String typeOfJar) {
println "Building a jar file for the type: $typeOfJar"
new java.io.File(structure[typeOfJar].dir).eachFileRecurse { file ->
try {
//println file.path
if (file.path =~ "\\.jar") {
println "jar xf $file.path $structure[typeOfJar].outputDir";
ant.unjar(src: file.path, dest: structure[typeOfJar].outputDir)
}
} catch (Exception e) {
println e
}
}

ant.jar(destfile: structure[typeOfJar].jar, basedir: structure[typeOfJar].outputDir)
ant.delete(dir: structure[typeOfJar].outputDir)
}
Jun 21

Forbes: Fighting talk on Open Source

Java, Open Source, Tech No Comments »

So, I am incommunicado for a week, and the world didn’t explode. I start trying to get through the mountain of email/rss that I now have as a gift for taking time out from the real world, and I instantly run across the Forbes.com article by Daniel Lyons.

Man he doesn’t hold back as most analysts do. He must have been shouted at by his wife or something, as he comes out with exactly what he thinks, in no uncertain terms. Kinda nice to see actually.

Cosby says IBM is just responding to customer needs. He says he hasn’t thought much about what IBM’s acquisition of Gluecode means for JBoss.

What is particularly cool about the Gluecode acquisition is:

Gluecode used to make money by selling some “closed source” programs that ran on top of its free open source stuff. No more, says IBM, which intends to release the source code for all of Gluecode’s programs and distribute them for free

A free cup of JOE huh. Nice.

Jun 12

JavaScript Embedded in Java 6

Java, JavaScript, Tech 26 Comments »

JavaScript Embedded in Java 6A brief view into the history via this Sun Java 6 announcement, shows us that in the next Java 6 build, we will have Mozilla Rhino baked 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.

First, we had a client (browser), that had both a Java VM and a JavaScript interpretter. Now, we have the same on the server-side of things.

This is pretty huge, and will spark more development in scripting languages, and JavaScript itself. Now there is no barrier to install anything, and you will had JS out of the box.

ECMAScript 4 XML is in Rhino. This means that we can leave the DOM (and friends) behind, and can use E4X right away!

Jun 10

APrefixing NCommon IInterfaces

Java, Tech 12 Comments »

Cedric discussed the recent Artima interview of Erich Gamma.

Cedric and Erich make good points, and are worthwhile reads for sure.

I know Ced is more Hungarian than French though, and I don’t get it :)

More posts like this and Howard will be happy that he used IEverything in Tapestry ;)

It isn’t a huge deal, but I really am not a fan of prefixing items with anything. I don’t like it as it gets out of the way for me. We rarely do this in English.

I want to use a Person, not an IPerson. Who cares if it happens to be an interface or a concrete class, or an abstract class? I actually don’t mind if that is encapsulated from me. I really often don’t care.

If I do care, then I let me IDE tell me what I am dealing with. Maybe someone should write an Eclipse plugin to put “I” at the beginning of all interfaces for the Hungarian crowd? And, strip them off for the others?

Keeps coming back to allowing a VIEW on my source code :)

Jun 07

Model talking to Service Layer: Good practice or bad?

Java, Tech 22 Comments »

In general I am a fan of OO practices, and giving as much behaviour as possible to my object model. Of course, this is within reason, and I only want my model to have the logic that makes sense for the given objects.

However, I often find that a lot changes when I see model’s that are used on the web tier.

I often run across this pattern:

  • Action talks to Service layer which returns dumb model objects
  • Model objects are placed in the request
  • View generates page, using the model

Since the model contains simple properties, with the odd piece of simple logic, and relationships, if a page (view) needs to get more information, it either:

  • Runs another action, which in turn talks to the service layer again to get the new info
  • The original action has multiple calls to the service layer

I actually prefer a different way of doing things. I want the dumb model smarter. I want to do real object design, and have rich behaviour in the model. In fact, I sometimes take it so far that my userSession object can traverse to most pieces of data as needed, but that is another matter.

What does this all mean? Imagine that I have a core model object that I return, and I want the object to have a method: Collection getAssociatedActivities().

What does this method do? Well, it could simply be walking our in-memory data, doing a lot of munging and calculations to work out the association based on rules.

However, this may not be enough. Maybe a complicated query needs to be done to work this out. Rather than using a Comparator and sorting through the model, and doing a bunch of aggregations, I want to let the database do what a database is good at.

This means that the implementation of this method changes from:

public Collection getAssociatedActivities() {
// sort through data model, using a lot of Comparators, making sure the data is all loaded, etc etc.

// 50 lines later...
return theAssociatedActivities;
}

to something like:

public Collection getAssociatedActivities() {
SomeService service = getSomeService(); // injected, via a BeanLookup, or what have you

return service.calculateAssociatedActivities(); // in here the services tier talks to the data tier to do a lot of the work
}

Implementation Encapsulation for Performance

What I like about tweaking the implementation of this method, is the fact that it is all encapsulated. At first I can put it in code directly. If it needs to go back to the service tier based on:

  • Performance: Turns out the DB can do this a lot faster
  • Cleanliness: Nicer to be shared at that tier

it can simply be done.

Choosing in the web tier

Compare this to an approach I see all the time, in which the web tier decides what value objects it wants back. In this case, when the interface needs to change to hit the services tier, either:

  • The main Action hits the services tier again to grab the associated activies object and plugs it in the request
  • The view does a pull which hits another Action, responsible to hitting the services tier and getting the associated objects

Any which way, you end up changing a lot, just for this issue. The web tier is totally changed for performance reasons. The rich object model is compromised, taking functionality out, for performance reasons.

Conclusion

I like rich models, and I like hidding as much as possible underneath. This allows me to change the engine under the hood without bugging the folks on the web tier. Thoughts?

Note: Cameron had some interesting things to say about Protecting the Domain Model

Jun 06

Why do I care about pluggable persistence?

Java, Tech No Comments »

Why do I care?

I have had certain people (;) question why it matters if the persistence engine is pluggable. Some vendors claim that noone has asked them for this. If you don’t like a vendors CMP engine, then use a different vendors app server. Or, just download Hibernate/Kodo and use that.

The issues that I have are:

  • Stuck with a vendor syndrome:
    I live in an area where there was once a very good golfer, who was a sales guy for IBM. That is how I explain how the entire city is blue. The state government, the university, the insurance companies. Everyone. Ask me to develop a Struts app on WebSphere? erg :/ At some of these large companies, I have seen the following issue come up time and time again. The CIO is bought in to IBM. The development team is not. Many of the projects will just run simple servlet/jsp web tiers and not use any of the WebSphere engine itself (an expensive Tomcat). Others fight political battles to try to get Spring/Hibernate solutions in to solve their problems. Management argues that “this isn’t standard!”. So now the developers are stuck between a rock and a hard place. They know they have to use WebSphere, and believe it or not, some of the large applications really benefit from pieces of that stack. However, they don’t want to use the WebSphere CMP engine. Picture the new world of a pluggable engine. Now the dev team can switch in Hibernate, yet still code to EJB 3, and can claim to management that they ARE following the standard. Everyone is happy.
  • Come on, holy lock-in batman: I am sorry app server vendors. I know that the CMP engine has been a good lock-in in the past. But you have all moved on from this up the stack anyway, so I am sure you don’t care that much anymore.
  • Why not?: Why should the ONE cross-cutting concern of persistence NOT be a pluggable API? It makes no technological sense to me. Give us the option

Do I think that everyone is going to run out and start shopping around? Maybe not. I am quite sure that a LOT of project teams and companies will be happy to install their app server, and start writing code. They don’t want to plugin something else.

However, I think there will be a lot of companies switching out. On some projects it could totally make sense to run WebLogic Application Server, with Hibernate’s persistence engine. If you are twisted you could use JBoss’ application server with IBM’s CMP engine :)

Surely choice and competition is a good thing. It will open up a LOT of companies outside of the appserver vendor space to compete, and we are going to see better and better tools to help us manage persistence.

Hopefully a year from now we will see this. We will see projects using a bit of this, and a bit of that. Who knows :)