Service Locator vs. Dependency Injection

June 25, 2007 | In Java, Javaone | No Comments

Last year at Javaone I attended a session on API design held by some Netbeans developers. I remember I thought they used a strange definition on Dependency Injection (DI). Now when I see this years session on the same subject (Modular Programming with the NetBeans Platform, TS-3742) I still think it’s strange:

not_di.png

DI should use the “Hollywood Principle” - don’t call us, we’ll call you. Your Java class should get its dependencies set or wired in the constructor. It should not call out to its environment to resolve them.

The code sample above is using the Service Loader (SL) feature in Java 6. You specify somewhere under META-INF in the jar file what interface you implement. Then the client code can ask for an implementation of this interface in runtime. SL is “pull”, DI is “push”.

There is nothing wrong with this style, but it is not DI. It’s hard enough keeping up with the different idioms and patterns so please use well established names for things.

Spring Webflow

May 18, 2006 | In Java, Javaone | No Comments

This session is interesting since we build a application (not a framework!) to build dynamic flows with custom validation, branching transitions, signing, PDF generation etc.

Spring Webflow (SWF) has sort of the same idea: let the controller keep state and discover where to go next.

It works with a static set of beans. You can’t use it with our solution since we would need to dynamically change the Webflow description

SWF is saving the Flow Execution in a repository. Task execution uses the flow description to decide where to go.

Difference from us: Webflow separates the flow description from the rest of the application (beans etc.). Simpler. We have everything (data items, validation, flow, custom code) in one BIG XML file. Could we abstract the navigation part into an “execution engine”?

In the Webflow there are different types of states (think UML state diagrams):

* View state - show something to the user
* Action state - do something with the data
* Decision state - use conditions to tell where to go
* Subflow state - enter “child flow”
* End state - end the flow, clean up

Webflow can be tested in isolation, accessing Spring managed beans. So the flow can be tested from Eclipse.

Scripting in Java EE

May 18, 2006 | In Agile, Java, Javaone | No Comments

Three guys from Oracle. Two french guys that was sometimes hard to understand. :)
They started with a introduction to Groovy. Really cool things. I need to look into that in greater detail. There is two books coming out soon, one is “Groovy in Action” from Manning.

They demoed a small Groovy Swing application using JMX to deploy an EAR to Oracle App server and create a DataSource for it.

Then they showed WSDL stubs in Javascript
Automatically generates Javascript to consume a web service, from a WSDL. Then a web client can call Javascript methods to consume the service in the client.

Check out!

JSR 223: one API that scripting languages can implement. Then they can be used from ScriptEngine Interface. It supports binding variables from Java to the script. Share data.

Demo: a Javascript running inside Java 6 that talks to a web service. Then you can talk to this script from a jabber client.

JUnit 4 and Java EE 5 - Better Testing by Design

May 18, 2006 | In Agile, Java, Javaone | 1 Comment

This is the first time I will hear Kent Beck speak. I have read a few of his books and he seems like a smart guy. This session is also crowded. I seem to pick the popular ones today. But it pays off, since they all have been splendid.

The speaker is making a joke about developers that LIKE testing.

“Testing is getting respect from developers. Five years a go this room would have had five people in it.”

The testing momentum is growing, but TDD is not yet mainstream. What will happen? Will TDD be a blipp in the CS history, like “Britney Spears”. Or will it continue to grow?

“JUnit isn’t complicated, anyone could have written it. But I did, and that’s why I stand here and you all sit there.”

JUnit 4 has some big changes, but remains backwards compatible. They have removed the composite pattern (Test interface implemented both by TestCase and TestSuite). No more testFoo in test names. Instead use the @Test annotaion. No more setUp() and tearDown(). Use annotations @before and @after.

Beck is telling the storing about the flight from Zurich to the US together with Erich Gamma. beck was doing mostly Smalltalk (still doing “Latin”, said Gamma). gamma was into Java. So during the flight Beck suggested that they should do some Java hacking. That was the beginning of JUnit. Never intended to be distributed.

Some good stuff:

“If the test is hard to write you might actually have a architectural problem in the code”

“Something in my programming style leads me to never need mock object.”

Introduction to Ajax

May 17, 2006 | In Java, Javaone | No Comments

Another great session from the same guy who did the Swing session. Got to get his name for later Javaones. Another thing: these Ajax/GUI sessions seems to attract the most beautiful girls at Javaone. Good thing for all you single nerds. :)

Effective Java and Java Puzzlers

May 17, 2006 | In Java, Javaone | No Comments

As expected these session where packed. They even moved the Puzzler session to the keynote hall. Joshua didn’t finish his new version of Effective Java to Javaone as planned. Can’t wait to get my hands on it. He didn’t say when it is to be expected.

The Effective Java talk was mostly about generics. Since we are still at 1.4 (thank you IBM…) we have not put generics to test yet. But it might be a good thing, since people are still figuring out how to use them correctly. I guess Joshua’s book well be a good read when we move to 5.0.

The Puzzler talk was entertaining as always. The focus here was also on 5.0 corner cases. My coworker Anders figured out one. I had a general idea about what was wrong with a few, but didn’t find the exact error on one of them.

Now I’m waiting for a talk about what’s new in Spring 2.0 with Rod Johnson. Also packed… This day might turn out to be the best day of this years Javaone.

8 ways to make you more productive in Swing

May 16, 2006 | In Java, Javaone | No Comments

This session was great. Got to get the slides and start trying out some of the stuff.

I really would like to do some Swing.

Rest and Atom

May 16, 2006 | In Java, Javaone | No Comments

This technical session started with a comparison of SOAP and REST web services. SOAP violates the web paradigm and misuses HTTP. WS-* is too complicated (specs are over thousand pages). REST, instead of just a SOAP endpoint URL, uses simple HTTP and send XML documents. It uses HTTP verbs: POST, GET, DELETE, PUT. In REST HTTP caching will work according to specs.

Downside of REST is that it’s not standardized, less industry support. More of a developer uproar (like EJB vs. Spring). There is now interface like WSDL in SOAP, and no directory system like UDDI.

Then he described Atom. Atom is a feed format like the old RSS.
Like RSS. Atom is standardized in RFC4287.

The Atom format contains a feed with some metadata and zero or more entries, also with metadata: Feed 1..* Entries

Entries can carry anything: text, HTML ot any content you declare with a content-type.

Atom is not just for blogs anymore! It can be used in CMS, wikis or other types of application. I have few ideas for our systems.

APP is the “Atom Publishing protocol”, used to interact with a server using the Atom for its feeds and entries. For the typical Atom application, blogs, APP is used for CRUD operation on the blog. APP uses HTTP verbs: POST, GET, PUT, DELETE
APP is a REST protocol. Everything is a (URI) resource. APP also supports adding of binary data and using several authors on one blog.

Service -> Workspace -> Collection of entries
-> Collections of media

To implement in a server you need the Servlet API and the ROME feed parsing API.

A client can easily be implemented with ROME and Apache jakarta HTTPClient.

Things I need to check:
* SOAP Doc/Literal
* RESTful web services
* ROME
* Is ATOM working with Wordpress?
* http://blogapps.dev.java.net

To many people…

May 16, 2006 | In Javaone | No Comments

In the keynote today John Gage said this is probably the largest Javaone ever. Does that mean there are more than 20000 people here? I thought some of the Javaones in the dotcom years had over 20000 attendees? This year Moscone is crowded…

The keynote was quite good. A lot about Netbeans and Java EE 5. I think I’ll re-evalute Netbeans and compare it to Eclipse. I hope to do some Swing stuff in the coming year, and Netbeans might be a better tool then.

Now I’m heading to the first technical session. It’s about web services with REST. I hate SOAP and hope REST will get more common.

JavaOne, Day 0

May 16, 2006 | In Javaone | No Comments

I have arrived in San Francisco after a long and dull flight through Singapore and Hong Kong. Since I live i Sri Lanka going east was the fastest route. I had to wait eight hours in Singapore for the connecting flight, but I didn’t mind since I bought this nice MacBook Pro that I’m using now in the Apple Store on Orchard Road. I had asked them to keep a machine for me, since I wanted the faster harddrive. When I arrived they couldn’t find it. After a few minutes of despair (I had not brought any other laptop with me) they found it. The person I had talked to realized that I was really anxious to get one so she hid it to well… :)
We stay at Marriot, very close to the Moscone Center. Very good location, but the hotel doesn’t offer free wireless, and that sucks! Other conference attendees stay at cheaper hotels and they get free wireless. Marriot charges $26 a day! Last time I stay there.

We rented some bikes and road over Golden Gate. Took the ferry back. It was really misty today. You couldn’t see the bridge until you where on it, and the SF skyline was not visible. To bad for Mimmi, my co-worker, who is here for the first time.

The Fireside Chat was OK. People tend to ask nice questions and there are seldom any debate.

Now we are going to have an early night to be up fresh tomorrow for a long day of sessions and BoF:s.

Entries and comments feeds. Valid XHTML and CSS. ^Top^