Archive for the 'Java' Category


Installing Java 1.5/5.0 on Snow Leopard

Most people are pointing to the OneSwarm instructions for installing Java 1.5 on Snow Leopard (it has been saved 100 times in Delicious.) While they do work, the following instructions (saved only 24 times in Delicious) here at chxo internets are much easier, and work just as well. It also feels safer and cleaner since the Java install is coming directly from Apple.

Rails on Glassfish

There’s an interesting article on running Rails on Glassfish and why this could make sense for you. And it’s an easy sell to me: one of the things that bother me most about Rails is resource usage, so database connection pooling is an instant winner in my book. But I’d love to know more about the performance characteristics of such a setup.

Ideally I’d have a few hours on a weekend to play around with Glassfish and Rails, but the coursework for my Masters is starting to bite. Maybe in a couple of months…

Java thinking in a Ruby world

Occasionally I find myself thinking with my Java hat on. Today was one such day. Looking at a legacy Order model from a Java system that we’re rebuilding in RoR, I noticed that it had two status columns — perfect for acts_as_state_machine! Or so I thought. But acts_as_state_machine isn’t really made to track multiple states on one object, and so I found myself with a little problem. How was I going to make this work?

Once I’d snapped out of thinking in the Java mould, it was obvious. These status fields could be broken out into separate models (with other relevant information, of course), each of which uses acts_as_state_machine. Thus I use the association mechanisms of Rails to help me, and work can keep trundling on nicely.

Then later this evening, reading the transcript for a Bruce Tate interview on the Ruby on Rails Podcast, I came across this relevant quote — describing similar thought processes:

I talked about the object-relational mappers that Java has, and all the inheritance modeling that you can do on the Java side, and trying to shoehorn my Java thought process into the Rails model. That took me to a sad place [smiling] and we don’t want to be in a sad place, we want to go to the happy place. So I learned to stretch the way that I think about various problems, like, for example, instead of trying to build a whole inheritance model, sometimes I’ll use polymorphic associations.

So instead of saying: “OK, everything on my website is content,” well, if I were to follow the Rails inheritance model, then everything would be crammed into a content table, and all the sub-classes of that would be with different properties. That’s clearly not a manageable solution. One of the things that I can do, though, is break out a small content descriptor that I can then add to a class with polymorphic associations.

Rails not a ghetto

I am a Java developer, a C# developer and a Rails developer. When the “Rails is a ghetto” blog post came about a few weeks ago, it got out of hand really quickly, with a few people who have never used Rails, sticking the boot in. I could have written a response, but I hardly have the profile to really make a dent. One guy who does have a high profile and is seriously talented is Obie Fernandez (formerly of ThoughtWorks) who has written an excellent take on a mythical “Ruby Backlash”:

They want to keep Ruby (and by extension Rubyists) in our proper place! What is that proper place I wonder — perhaps it is out of the mainstream, out of the limelight, out of the enterprise, out of the places where we threaten the status quo!

All I can add is my voice: I will never build another standard database backed website in Java or php. I’ve done both, and Rails leaves them for dead. Plus, right now, programming in Ruby is pure joy. I’d be delighted if another language and framework came along to displace this, but I’m sold on this combo for the time being.

I can understand that many people have invested a lot of time in their Java careers, but some of the opinions out there are the stuff of witch hunts.

Java, Ruby and Closures

I hate linking when I can’t add any value, but here is a great little read on Closures and Java:

Tim Bray on Closures and Java

My argument is simple: Java worked so well because it hit the 80/20 point; for my money one of the loudest, cleanest 80/20 technology victories ever. Subsequent attempts to fill in the 20% were, well, mostly harmless. Until generics, which are a disaster; they have made Java harder to learn and to understand, and you can’t avoid them.

I could not agree more with the general gist of this (even though Tim refrains from drawing a conclusion).  I’ve never felt completely comfortable with generics, I don’t feel they added to my Java code in any meaningful way, and I can’t see closures being a natural fit either — though I haven’t really looked at the proposed implementations.

Closures in Ruby on the other hand are simple and beautiful, and they’ve been there from the start.  I don’t have any experience with Scala however, but I’m keen to have a little dig into how they handle closures over in that world.

Remote Debugging: Tomcat 5 + Eclipse

I can’t remember how many times I’ve had to set this up, but I always end up wasting time googling an answer, which is mostly good, but sometimes misses the mark (Jon Eaves’ remote debugging solution is closest to the mark, but his is a Windows solution.) For the record, here is how I just did it in OS X:

  1. Make sure normal Tomcat environment variables (CATALINA_HOME, JAVA_HOME etc) are set.
  2. At the command line:

    $ export JAVA_OPTS= "-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
    $ startup.sh
  3. Note: I didn’t have to include “jdpa start” arguments
  4. Go to Eclipse, then Run->Debug…
  5. Then create new “Remote Java Application”, rename it and run (the defaults should be fine)

For the record, it’d probably be better to run Tomcat directly from Eclipse, but I don’t have time to set that up right now — so tried and tested it is.

Terrence Parr on ANTLR at SJUG

Atlassian have published videos of Terrence Parr’s ANTLR presentation at SJUG.  And there is the back of my head right in the middle of the camera (actually, more bottom right.  Second row back, dark sweater).

Very interesting presentation, now I just need to get my hands on the new ANTLR book.  Thanks Terrence!

Java Bytecode

Just reading about Java Bytecode manipulation in Ted Neward’s article on The Server Side, something I haven’t really made any investigations into before. Having done a little assembly in my past, it seems fairly straight forward. I guess the key points are:

  • javap is a bytecode disassembler
  • constants are defined in the constant-pool
  • opcodes manipulate operands from the execution stack
  • the execution stack is populated with operands
  • categories of opcodes:
    • stack manipulation
    • branching and control flow
    • arithmetic
    • object model instructions (creating arrays of objects, setting fields, invoking methods, casting)
    • block synchronization
  • exceptions are handled by an exception table that handles ranges of bytecode
  • there are 212 current opcodes, with room for 46 more (all documented in JVM specification)
  • Bill Venners book “Inside the Java Virtual Machine” would be a great place to start if I wanted to look into this further.

EJA Forums Sydney – October 19th 2006

On Thursday 19th October I visited the Sydney edition of the Enterprise Java forum at the MLC Center. From what I understand EJA forums have been running in Melbourne for longer, and there’s an event down there monthly, whereas they are just establishing themselves in Sydney, and the events are only quarterly. The Melbourne program was slightly more extensive, but Sydney’s program was pretty busy too, with six speakers spread over half a day.

Firstly, my notes on the speakers:

Jim Webber, Geurilla SOA — was engaging and humourous, made a good case for his expertise and expounded a sensible rationale for adopting SOA. The main thrust of his argument was that Web Services alone are robust enough to provide the benefits of SOA, without having to rely on vendor solutions and the lock-in they entail. A useful analogy for this proposition was comparing the telecommunications network to the internet, where the internet has won because of its ignorance and simplicity, compared to the complex routing and domain knowledge of the telecomms networks.

Peter Evans-Greenwood, The Boundaryless Organisation — Peter’s speech was largely strategic, and I suspect was over the heads of most of the mainly technical attendees. Certainly from a purely Java perspective there was little of value. Probably it was just the wrong forum for this type of talk.

Ben Alex, Next-Gen POJO Architecture — Ben’s points were largely that while architecture has improved in recent years, it could be better with some simple tweaks that can vastly improve the success of new systems. Firstly he wants us to get the terminology right, some of the patterns being used commonly are being incorrectly labelled. More importantly, the idea of “domain driven design”, with a better separation of concerns and a longer shelf life was promoted. He referenced the book “Domain Driven Design” several times, and its been on my reading list for a while, so I should get to it soon.

Paul Scott-Murphy, Architecting Event Driven Systems — I’d mostly seen this talk before (at a TIBCO event), but with some future projects in mind, this was particularly interesting. Paul demonstrated TIBCO products and how they can help create an event driven system, using Confluence and the events it generates as an example.

Cristina Cifuentes, Java on Wireless Sensor Devices — interesting from a hobby technology point of view.

Mike Cannon-Brookes, Pragmatic Clustering — Mike spoke about Tangosol, and lessons learned from Atlassian’s efforts in clustering Confluence. Most of all it was interesting to see his thought process in reaching the decision to use Tangosol… they started off not knowing much about it, and so we got to learn from the mistakes they made along the way. I wish I’d taken better notes during this (update: the presentation is here).

As for the rest of the event. The networking opportunities seemed limited at first glance. There were a couple of consulting companies, and the bulk of the audience was from the Reserve Bank of Australia. But aside from these there wasn’t much on offer. As with all technical talks the crowd was a little shy and geeky, but ready to chat easily enough. Also, the food was great!

Bitter XML

I’m far from the first to make the point, but on reviewing Bruce Tate’s still excellent Bitter Java, I came across this reason for the success of Java:

In C++, cascading include files were very difficult to maintain, understand, and debug.

Surely I’m not the only one out there feeling we’re heading in the same direction (or already there!) with XML configuration files — I’ll stop myself from mentioning specific frameworks.

Next Page »