Posts

The Enum is perfect... well almost.

Ok so its time to admit to something. I'm deeply in love with Java's Enum! In my opinion it was the best part of Java 5 and I still wonder why it took Sun 10 years to add this powerful static modeling construct. The power of the Enum Although there certainly are known limitations of the Enum, i.e. how you can't extend it , I have never run into a practical limitation myself. Until now that is. The issue I want to raise is that of Enum forward referencing . The great Alan Turing taught us that at the end of the day, everything can be modeled by a Turing Machine and finite automata. We may not often consciously operate at this level, but many things still makes sense to model this way being it a regular expression matcher, navigation rules or similar. The Java Enum appears to be a perfectly simple, fast and type-safe way of modeling this... or does it? State machine with an Enum Since the Java Enum effectively is just a group of static class instances, it allows us to attach...

NetBeans plugin: Special copy/paste

Image
The very little I've had to paste code into this fairly new blog, was enough to give me the idea of creating an extension to NetBeans which would help to remedy this formatting nightmare. Now, in my world, there's approximately a 100:1 ratio between idea and actual realization, so I'd have to salute the awesome OpenIDE API's for making this possible spending just a few late nights and taking just 200 lines of code. Without further ado, I present, my first NetBeans plugin . Special copy/paste The plugin will add a couple of new actions to the context-sensitive popup-menu of the source editor, which will allow you to copy the selected text as preformatted HTML, as well as a CSS version which will preserve the formatting used in NetBeans. Using the "Copy as HTML and CSS" menu as in the above screen dump will result in you being able to paste it directly into a website/wiki/blog and have it display like this: /** * @param args the command line arguments ...

Keurig Platinum B70

Time to try to live more up to the name of this blog. As most developers, I have a passion for coffee and coke and consume it in quantities which are probably not on the healthy side. Anyway, when I saw the Keurig Platinum B70 coffee maker in action, I absolutely had to own one. Why? Take a look below. Yup, it takes 45 sec. for it to brew a large cup (4 sizes to choose from) of fresh programmer oil, has a very gadgety blue light and is ready to serve its master 24/7. It probably isn't the most economical way to get your caffeine dose, but it does allow for a small filter so that you can use normal coffee beans rather than the convenient K-cups. Also, it came with samples of Van Houtte's Kenyan Kilimandjaro roast , so now I know why Stephen Colebourne named his OpenJDK sandbox Kijaro . ;)

Type registry strategy pattern

One pattern that I have often seen applied in Java, is the one where you plug-in and register a handler for a given type of object to thereby supply a specific behavior for it. For instance, this is often used in order to render, edit and validate elements of various visual components in Swing, such as the JTable. I am unaware of any official name for this mechanism, but it appears to be a combination of Martin Fowlers Registry Pattern and the GoF Strategy pattern so I like to think of it as the Type registry strategy pattern. Legacy example Conditional behavior is encapsulated by some common interface, which provides the mechanism for dispatching to elsewhere, responsible for applying a concrete strategy. An example is this format handler, which allows an object to be formatted as a String: 1 interface Handler 2 { 3 String format(Object object); 4 } And an API, capable of associating handlers for various Object types registered and dispatching to these: 5 class SomeAPI 6 {...

@SuppressWarnings values

Image
Meta-data and how to associate it has always been a bit of a confusing topic in Java. For instance, the transient modifier is really a kind of marker annotation, as is the @deprecated javadoc tag compilers are also required to process, as is the marker interface Serializable. Then in JDK 1.5, a dedicated annotation facility was added, probably in light of the success of C#'s attributes. One of the first practical uses of annotations appears to be as a way to suppress compiler warnings. @SuppressWarnings This build-in annotation allows the developer to signal a respecting compiler that it should forgo a particular warning. It can be applied in front of a type, a field, a method, a parameter, a constructor as well as a local variable. It is up to the compiler to make sense of whatever you put inside the String, the only value mandated by the JLS is the "unchecked". Compilers as well as IDE's will typically implement each their own set of warning types, the Eclipse IDE d...

Worst travel experience ever

Friday I was suppose to go to Montreal, the usual route over London Heathrow. Slightly concerned with the recent mishaps of the new Terminal 5, I actually managed to get to the good old Terminal 4 without much trouble. Little did I know, my trouble were just about to start. Canceled flight Yup, just 1 min. after entering Terminal 4 I learned that BA95 to Montreal was canceled. Inquiring at the help desk I experienced the deja-vu of being told that I had to go fetch my luggage, contact the ticket office and expect a layover. I had experienced another layover about 2 years ago so I pretty much knew what has coming... or so I though anyway. Heathrow, JFK or Newark My luggage was nowhere to be found, so I proceeded to the ticket counter and when it was my time to be served I was presented with the option og taking the same flight tomorrow, go to JFK in New York and a very short layover involving an early flight or go to Newark in New York and a longer layover involving a later flight. I t...

Know thy acronyms

Maybe it's caused by the passing of time, maybe it's because of its open nature or maybe it's simply because people like to make them up. In any event, few technologies in computing are as littered with acronyms as Java is. Just for fun, while eating lunch (yeah I know it's bad habit) I compiled a list off the top of my head of what an average developer might be subjected to, when tracking technologies in the Java space. AWT - Abstract Window Toolkit (UI) BGGA - Gilad Bracha, Neal Gafter, James Gosling, and Peter von der Ahe (Closures) CICE - Concise Instance Creation Expressions (Closures) EAR - Enterprise ARchive (Packaging) EDT - Event Dispatching Thread (Lingo) EJB - Enterprice Java Beans (Packaging/technology) FCM - First Class Methods (Closures) JAR - Java ARchive (Packaging) JAX-RPC - Java API for Xml-based Remote Procedure Call JAX-RS - The Java API for RESTful Web Services JAX-WS - Java API for Xml-based Web Services JAXB - Java Archtecture for Xml Binding JAXP...