Interview with Johnathan Rentzsch

Behind the Red Shed with Jonathan Rentzsch is a good interview with Jonathan Rentzsch. He makes some interesting comments regarding Webobjects.

WebObjects is only relevant if you’re on the hook for writing lots of web applications fairly quickly. There’s an definite escape velocity however — the learning curve is steep, so it really only makes sense if you are currently or planning on becoming a professional developer.

Comparable vs. Equals

Agylen: Comparable vs equals has a nice discussion of how compareTo is used in Sets.

If you don’t understand how Java is going to use your compareTo and your equals methods you can run into a problem with Sets. Basically you shouldn’t have a compareTo() method that returns 0 unless equals() returns true.

Since a Set only allows once instance of each object, it will ignore the addition of any objects it already contains. If your object implements the Comparator interface the Set will check the compareTo method not the equals method.

It is common to write compareTo methods that only look at one field. For example, you might want to sort Person objects by their last name and then first name. If you only check the last and first name field, then comparing two John Smiths would return 0 even if they were different objects. This would cause the Set to evaluate them as the same object and prevent you from adding the second John Smith to the Set.

Simple Introduction to Reflection

Reflection is a mechanism in java that allows to to get information about a class without needing to know the type of the class. The program below takes a java class name as a command line argument and shows you all of the methods and field names that are in the class.

You call the sample program like this:
java ReflectionTest java.util.Calendar

ReflectionTest takes the string you pass in on the command line and attempts to find a class by that name. If it finds one it gets an array of all the fields and displays their name and their values. It then gets an array of all the methods and displays their name and their return type.
Continue reading “Simple Introduction to Reflection”

CheckStyle

I’ve been using Eclipse and it is a very nice IDE. I’m very impressed with the number of plugin’s available for it. One of the plugins I’ve been using is called CheckStyle. Basically it can check your code for errors whenever you save it. The errors are configurable and it comes with a default implementation of the Sun Java coding style. It can be very annoying to apply it to code that you have already written, but if you use it as you are writing code it makes it much easier to make sure you are coding in a consistent way.
Continue reading “CheckStyle”