Category: Geek

JavaOne Day 1

By , May 7, 2008

Today was the first day of JavaOne proper and it was packed! There are so many people here! I arrived for breakfast at about 8am and already a queue was forming for the opening keynote general session. By the time I joined the end of it it had stretched the length of the Moscone Center. When I got inside the massive hall it was more like a rock concert. Loud music was pumping and some awesome break dancers were performing on stage. Then just before the keynote was to start James Gosling started firing t-shirts into the crowd using a giant slingshot held between two other people.

So the first general session was on the theme of the whole conference; “Java + You”. There were lots of demos of how Java is being used on the “four screens” of your life (I think these are your PC, phone, TV and car). Probably the coolest demonstrations were of JavaFX, used for creating rich internet applications similar to Adobe’s flex and AIR. You can make some cool applets using JavaFX but the coolest thing is you can drag these applets off the web page and onto your desktop and they continue to run. In fact you can then close the web page and keep the applet locally to be run on its own whenever you want. That’s cool!

The first technical session I attended was on IBM’s WebSphere sMash and ProjectZero. This is a “commercial project with a transparent development process” and is a rapid application development environment that is geared around developing RESTful mash-ups and Web 2.0 apps. It supports PHP, Groovy and Java and contains a PHP interpreter written in Java. At the moment this interpreter runs an intermediate representation of the PHP code but in future they plan to compile it to byte code. It contains its own web-based IDE and the application that is produced contains its own web server. So you can have a number of these applications running and they are started and stopped using an inetd type service. It looks like it is targeted at the enterprise developer who wants to throw something together quickly for internal use.

Joshua Bloch, Chief Java Architect at Google, gave an interesting talk on ‘More Effective Java’ which was a selection of points from his new book. He spent quite a bit of time on hints for using enums. For example, replacing bitfields with enums. There are lots of problems with bitfields: not typesafe, no namespaces, printed values are cryptic, eg ’12′, don’t scale – if number of constants grows beyond 64 you’re screwed. A solution is to use EnumSet and you end up with nicer code like text.applyStyles(EnumSet.of(Style.BOLD, Style.ITALIC)).

Rod Johnson from Spring gave a session on new features of Spring 2.5. He listed a whole heap of new features like:

  • overhaul of Spring MVC
  • enhanced testing support with JUnit4
  • extended SQL error code mappings for popular RDBMSs
  • integration with latest versions of JavaEE 5 APIs (Servlet 2.5, JSP 2.1)

but he focussed mainly on annotations.

Using annotation based DI can reduce the external config required and is more concise but downsides include:

  • per-type not per-instance
  • won’t work for legacy code
  • need to recompile java code to change configuration
  • not suited to externalizing simple types

Even so, Rod suggested fairly extensive use of annotations. You can use the @Autowired annotation which is Spring’s own syntax and uses the default autowire by type behaviour. This is the same as using autowiring in xml files but by using annotations you can be more selective. Of course the downside is you are using a spring specific annotation. If you don’t like this you can use the @Resource annotation although it is not as powerful as @Autowired so is not a best practice.

Rod also went through some of the other annotations like @Component which allows component scanning (where Spring scans your classpath for annotated classes). I can see how annotations are nice but it also means you lose your ‘application blueprint’ when all your beans are defined in xml.

Bill Pugh gave a really interesting talk on “Defective Java Code: Turning WTF Code into a Learning Experience”. Bill is responsible for the cool FindBugs static analysis tool and he had good tips for some common errors. He spent quite a bit of time discussing the equals method which can be trickier to implement than it might seem. The following must be true when implementing the equals method:

  • equals(null) returns false
  • if x.equals(y) then x.hashCode() == y.hashCode()
  • equals is reflexive, symmetric and transitive

Symmetry is very important as non-symmetric equals can produce confusing and hard to reproduce results. He also discussed the debate of using instanceof or getClass() when implementing equals. Basically, both have problems. if you use instanceof and override equals you may break symmetry. If you use getClass then you cannot have a subclass equal to superclass. However you only need to worry about this when designing with subclasses.
Bill described different types of equality:

  • Object equality (the default and useful more than you would suspect)
  • Value equality (eg ArrayList and LinkedList representing {1,2,3} are equal)
  • Behaviour equality (objects are equal if you can’t distinguish them based on behaviuor) – more subtle

Use of getClass will cause any subclasses to break equality. Also, use of getClass in hibernate objects will cause failures. However, if you use instanceof and override it you must not change the semantics of equals – all you can do is use a more efficient algorithm or instrument for debugging/performance monitoring. getClass is sometimes used in abstract base classes (eg BasicPermission class). If you use instanceof consider declaring the equals method final. Basically the moral is you should document your equals semantics. FindBugs can detect common problems with equals methods, for example, there are two equals methods in the JDK and four in eclipse that always return false plus one in eclipse that always returns true.

After the Rails stuff from yesterday I was interested to hear Guillaume Laforge talking about Groovy and Grails. This is a cool platform that uses Groovy in a Rails-type framework. What’s interesting is that it makes use of such projects as Spring and Hibernate yet simplifies their use so there is much less configuration required. For example, you don’t need to create hibernate mapping XML files.
The syntax is very Java-like (unlike Ruby) and integrates tightly with Java at every level. You can reuse legacy code and while Grails comes with jetty for development it is simple to package it as a war file for deployment on tomcat or some other app server.

Java University

By , May 6, 2008

Today was the Java University day. It was a long day. There were three sessions, each of three hours duration which meant a twelve hour day (including breaks).

My first session was Developing Enterprise Applications With the Spring Framework with Chris Richardson, the author of POJOs in Action. He was a good speaker although he had one of those slightly mutant delicately nuanced accents that Brits seem to get after spending a long time living in the US. The session was interesting although he spent most of the time on all the dependency injection stuff I was quite familiar with and seemed to run out of time toward the end and had to rush a bit over the Hibernate stuff. But he went into some detail over Spring’s AOP support as well as the annotations that can eliminate a lot of the XML. While annotations can reduce the amount of XML required I’m not sure this is entirely a good thing as then your POJOs become more tightly coupled to the Spring framework. I think I prefer keeping it all in XML then your POJOs don’t need to know anything about Spring. He also described configuring the Application Context using JavaConfig which is pure Java but this looks even worse than annotations to me.

After lunch I attended a session on Using the Power of JRuby and Rails to Develop Robust Applications. This was a joint presentation by Brian Leonard and Sang Shin of JavaPassion fame. I found this really interesting. Brian gave a (brief) introduction to Ruby and JRuby in the first hour and the next two hours Sang went through a hands-on lab building various Rails applications.

The ability to create a working CRUD application using the Rails framework in about five minutes is amazing and it definitely looks like a fun language/framework to learn. An interesting Rails feature is the database migrations which manage the evolution of database schema. The transformations are described in self-contained ruby classes that have up and down methods that are called in sequence when migrating between versions of a database schema. Eg:

class AddSsl < ActiveRecord::Migration
    def self.up
        add_column :accounts, :ssl_enabled, :boolean, :default => 1
    end
 
    def self.down
        remove_column :accounts, :ssl_enabled
    end
end

You can put any ruby code you want in these up and down methods.

It’s interesting that when you generate a new model class it actually contains no real code, eg:

class Message < ActiveRecord::Base
end

Rails actually makes extensive use of ruby’s metaprogramming features here to create dynamically generated classes and methods.

The neat thing about JRuby (a ruby interpreter that runs on the JVM) is that you can call all your java code from your ruby program, eg:

include Java
 
import javax.swing.JFrame
 
frame = JFrame.new("Ruby SWINGS!")
frame.set_size(640, 480)
frame.show

I’m definitely going to have a play around with this and Netbeans has some awesome ruby/rails support now.

After the reception I stayed for a session on Netbeans 6.x. This covered quite a few features of the latest Netbeans but particularly interesting was the profiling tools. This uses JVMTI and lets you specify “root methods” which will only add instrumentation to those methods. This saves adding any profiling overhead to other areas of your application. You then run the appserver in profiling mode and take a “snapshot” which shows methods called, the number of invocations and the time spent in them, including “self time” which doesn’t include time spent in methods called by that method. You can then view this output in a few different ways and jump to the code. It looks really useful.

They also covered Netbeans’s new support for scripting languages like Ruby and JavaScript. Both the ruby editor and the javascript editor have support for refactoring and code completion. The javascript editor also has code completion support for frameworks like JQuery, scriptaculous and yui. A nice touch are the little icons that indicate browser compatibility. I also scored a Netbeans USB drive which includes an early access release of the new PHP suport in Netbeans.

This morning It had been lovely and sunny when I left at 7.30 but it was quite chilly when I emerged at 9pm. A sea fog had started to obscure the tops of the tallest buildings and the air was damp. I stopped for a while to listen to a loud three piece band playing on the corner of O’Farrell St and Powell.

It was a long day but a good start to what looks to be a busy week.

My First JavaOne

By , May 5, 2008

Today I arrived in sunny San Francisco ahead of JavaOne 2008. Tomorrow is the Java University day before the main conference starts on Tuesday.

I’m staying in the Sir Francis Drake Hotel on Powell Street. This is an interesting hotel, built in 1928, with lots of quirky touches like doormen in Beefeater uniforms and a cool “Cutler Mailing System” which seems to be a chute that runs down the elevator shaft. Presumably you can drop a postcard in and it will shoot down to a big bin somewhere in the bowels of the hotel.

Conferences

By , April 17, 2008

The 2008 conference season is in full swing and I’m a little sad I couldn’t make it to the MySQL conference this year as I had a great time in 2007 – but not that sad because the reason is I’m going to JavaOne in May and don’t think I could have got approval for two conferences in as many months. :-)

Still, I can live vicariously through all the people blogging the event. Artem Russakovskii’s notes on the Scaling MySQL – Up or Out? keynote have some interesting numbers:

Question One: Number of MySQL servers
Facebook 1,800 (900m/900s)

Question Three: Number of Web Servers
Facebook 10,000

Question Four: Number of Memcached servers
Facebook 805

That is one hella memcached! This post from last year by a facebook engineer lists their number of servers at 200 giving a total of 3TB of cache. If we assume they are using the same kind of kit then they now must have a memcached size of about 12TB!

Scaling is something I’ve been investigating at work recently and we will potentially be dealing with big numbers ourselves so it’s encouraging to know open source applications like MySQL and memcached can scale so massively.

Old Computers

By , October 23, 2007

This site has some beautiful images of old computers including an amazing picture of a Cray CDC 6600 that seems to have huge glowing green eyes. This was the world’s fastest computer from 1964 to 1969 and looks like something from the set of Blake’s 7.

They also have a picture of the Neiman Marcus Kitchen Computer(!) from 1969. According to wikipedia:

It sold for $10,000, weighs over 100 pounds, and is used for storing recipes (but reading or entering these recipes would have been very difficult for the average cook as the only “user interface” was the binary front panel lights and switches). It had a built in cutting board and had a few recipes built in.

There is no evidence that any Honeywell Kitchen Computers were ever sold.

No shit.

Update: The images are from Mark Richards’s book Core Memory – A Visual Survey of Vintage Computers.

Tomcat & SSL

By , August 13, 2007

Tomcat has quite a good page in its documentation about getting SSL working and it does a reasonable job describing how to generate a self-signed cert. However, when it comes to what must be a fairly common use case of importing an existing key/certificate pair into a keystore it avoids the subject with phrases like: “For more advanced cases, consult the OpenSSL documententation.”

The problem is really java’s keytool. It does a good job generating self-signed certs, importing existing certificates you want to trust or importing a certificate received from a CSR generated by keytool. But when it comes to importing both the certificate and key into a keystore things get a little messier. For example, say you already have a certificate you are using on your apache web server and you now want to use it in your Tomcat server. You might think you can do something like:

keytool -import -alias tomcat -keystore <your_keystore_filename> -file <your_certificate_filename>

but that just won’t work. It turns out the only way to import an existing key/certificate pair is to do it programatically. Get the details on my wiki.

Oh, another thing to watch out for is to make sure you always use the genuine Sun Java keytool. The thing that comes with gcj and is probably first in your $PATH will only make you cry.

Facebook mirror

By , August 11, 2007

While I was doing a yum update today I noticed it was trying mirror.facebook.com. It turns out they mirror a lot of open source projects there.

They also have a public svn repository where you can grab the source code of Thrift which looks interesting.

Zen ADSL

By , July 7, 2007

I just found another good reason to like Zen ADSL. I logged into my customer portal and discovered that I can change the reverse mapping of my static IP address through a simple form on their website.

I’ve been using Zen for years now and I can’t see myself changing in the near future. Certainly not to Virgin Media who, incidentally, phoned me a couple of days after I lodged my complaint with the CISAS and offered to refund the money they owed me straight away. Of course it could take up to twenty-one days to receive the cheque…

Openads 2.3 Beta released

By , July 5, 2007

Yesterday, after months of hard work, we released Openads 2.3 Beta.

Afterwards, we celebrated at the Oxo Tower and Andrew has some pictures on his blog.

Unix humour

By , June 18, 2007

This guy has a great name for a sysadmin:

Daley’s view was backed by Tim Chown, systems administrator for the University of Southampton’s school of electronics and computer science and a member of the UK’s IPv6 taskforce.

Panorama Theme by Themocracy

SEO Powered by Platinum SEO from Techblissonline