why I love the windows experience

Posted by Jonathan

Ok, this is not Microsoft's fault, but it is a perfect example for the windows experience.

While working on a nasty IE JavaScript bug in my windows VM I kept getting an annoying popup saying: "SUN Java - Update available".

After clicking it away several times, I though "heck let's install it so it keeps quiet" and I clicked on the icon. After waiting several minutes for the installer to load data and seeing some of the nice progress bar, I got this wonderful message:

Warning: Operating system not supported! - Thank you for choosing Java (TM) ...

So the VM is running XP SP1 and Sun's update requires SP2. When I clicked away the failed installation, I got a nice error window saying:

Installation failed due to user aborting

Thanks for annoying me, keeping me from work for 15minutes, and in the end blaming me for not be able to install ...

Java 5 now default VM on OS X

Posted by Jonathan

With the newest Java update (Java 2 Standard Edition 5.0 Release 4) Java 5 is finally the default VM on the Mac:

After installing J2SE 5.0 Release 4, J2SE 5.0 becomes preferred over Java 1.4.2, which will still be installed on your Mac. Applications run with J2SE 5.0 unless they specifically request Java 1.4.2

No need for hacks like this anymore.

Tool support vs. simplicity

Posted by Jonathan

Even I do not really want to program in Java anymore after discovering the beauty of Ruby over a year ago, I am a regular listener of the Java Posse.

Python, Ruby and especially Ruby on Rails are common guests on this show as they unsettled the view of many Java Programmers. Every time the guys talk about dynamic scripting languages the story goes:

A: “I really like the features, the productivity gain and the dynamic capabilities. It is amazing what you can do with 10 lines of code.”
B: “Yeah, but Ruby still lacks good tool support and IDEs like Eclipse or IDEA.”
C: “Yes, that’s true.”
A: “Yeah with Java you do not have all these features but you have fabulous tools like Creator, they are just amazing. I can’t imaging working without such an IDE.”
B: “So let’s forget about these until they got an Eclipse.”

And every time I hear this I could just scream that the whole point of having such dynamic and expressive languages is that you can actually do some coding without having to rely on an IDE.

David Heinemeier Hansson gave a similar quote in an recent interiew at uk.builder.com:

Ruby attacks the productivity problem by making the core elements as expressive as possible, so the programmer doesn’t have to rely on IDEs and other tools on top of the language to get stuff done. Few programmers today would even consider doing Java without Eclipse/IDEA or C# without Visual Studio, but lots of programmers happily write Ruby code in good text editors that aren’t born with specialization for one particular language, like TextMate for OS X, which is the big hit in Ruby/Rails circles.

AMEN

Another common one goes like this:

A: “We often read about the so called complexity of Java programming, especially with J2EE.”
B: “I think this comes from people who are used to write their code with Vim.”
A: “Yes, you do not write deployment descriptors or Hibernate configuration files with Vim, you have to use a modern IDE like Eclipse or IDEA, they will generate the code and configuration for you.”
B: “We definitely recommend to use NetBeans, Eclipse, IDEA or Creator, this will ease a lot.”

Dynamic languages like Python and Ruby make programming much simpler as opposed to an IDE which only takes over control and hides the complexity.

Hiding is not the same as removing.

The IDEs bring their own complexity and learning curve. There are whole books published about how to use Eclipse!

How often do you see a novice despairing while just trying to edit a bunch of files in IDEs like Eclipse without creating a workspace or a project. Compare this with Textmate, just drop a folder or a file on its symbol in the Dock and boom, you get a tree view of all the files and you can just start the edit them and get productive.

Java 5 on Mac OS X Tiger

Posted by Jonathan

As I always forget how to enable Java 5 as the default VM/JDK on OS X I thought I should document it here.

First you need Java 5. Apple does not ship it with Tiger, you need to download it from connect.apple.com after a free registration. After you install it, the Java 5 JDK is available but is not configured as the default VM.

In order to archive this, open the Java Preferences application in /Applications/Utilities/Java/J2SE\ 5.0/. There you can set the VM version for applets in the browser and other Java programs.

But the default JDK on the command line is still Java 1.4.2. If you also want Java 5 as your default command line Java JDK, you need this trick. In /System/Library/Frameworks/JavaVM.framework/Versions there is a symlink called CurrentJDK that controls which JDK is used.

# cd /System/Library/Frameworks/JavaVM.framework/Versions
# sudo rm CurrentJDK
# sudo ln -s 1.5 CurrentJDK

Now if you test it on the command line you get Java 5:

# java -version
java version “1.5.0_05”
Java™ 2 Runtime Environment, Standard Edition (build 1.5.0_05-81)
Java HotSpot™ Client VM (build 1.5.0_05-48, mixed mode, sharing)

Great case study on Rails versus Enterprise Java

Posted by Jonathan

Rick Bradley posted a great case study about a big “Enterprise” Java project and their change to Ruby on Rails.

So, bottom line from where we sit: the guys complaining that reported 10:1 savings over Java was bullsht were right on target: 10:1 is way too low from what we’re seeing.

Make sure to read it and show it to the Java guys who still claim that Rails is not enterprise ready and does not save you much development time in the long run.

Even as many people in the Java community start to admit that EBJ 2 is a mess and XML may not be the Golden Hammer, one of their new favorite pseudo-lightweight tools, JBoss+EJB3+Hibernate, is still not much better:

Note that I haven’t even mentioned to this point the app server (JBoss),
which includes a few lines of XML complexity of its own:

& Mon Oct 10 10:49:57 jrbradle <at> rick
~/svn/phoenix/srv$ find . -type f -name ‘
.xml’ | xargs wc -l | grep total
44472 total

I just can’t agree enough with Rick, especially since I’m working on a Java5+EJB3+JBossHibernateEcho2 project and progress is very slow.

Test Frameworks NG

Posted by Jonathan

I’ve stumbled over a nice comparison of test frameworks for Java on TheServerSide.com. It compares JUnit 3.x, JTiger, and TestNG. Further it has a look at the next version of JUnit that will use new features of JDK 1.5. Also Frank Westphal has a good article on JUnit 4 (german, but the code is self-explanatory).

What is apparent from these articles is that the new trend for test frameworks is to disband the habit of forcing naming conventions like setUp(), tearDown(), testXXX() and ClassTest. Instead JDK 1.5 annotations are used:

public class ClassTest {
 @before public void init() {
  ...
  ...
 }
 @Test public void emptyList() {
  ...
  ...
 }
 @after public void clear() {
  ...
  ...
 }
}

Further the various assert* methods are expanded and more complex tests are possible. Make sure to read the articles if you are interested in Unit Testing even if you have no interest in Java as these features are interesting for every Unit Test framework.

Currently Ruby’s Test::Unit is built in style of JUnit 3.x. Are there any efforts to create a JUnit 4.x style Unit Test framework for Ruby?

Review: Better, Faster, Lighter Java

Posted by Jonathan

In their book Better, Faster, Lighter Java, Bruce A. Tate and Justin Gehtland argue against heavyweight architectures and approaches like J2EE, EJB, and CORBA. This book is aimed at advanced Java programmers who feel that the “industry standards” for Enterprise Java are inflexible and too complicated. Bruce A. Tate and Justin Gehtland present in 11 chapters and 242 pages more “lightweight” and non-invasive frameworks like Hibernate and Spring as an alternative.

Better, Faster, Lighter Java

The book is organized into two main parts. The first part (chapter one to six) examines existing enterprise solutions like J2EE and EJB and shows why they often do more harm then they help to develop better applications. Further five principles for fighting the “bloat” are presented. The second part (chapter seven to eleven) shows how to apply those principles and presents existing frameworks like Hibernate and Spring that adhere to those principles.

Chapter 1 introduces the “bloat” and develops the principles:

  1. Keep it simple
  2. Do one thing, and do it well
  3. Strive for transparency
  4. Allow for extension
  5. You are what you eat

Then chapter 2 to 6 cover each principle in detail and show where existing Java enterprise solutions violate these rules. The resulting hindrances for development, extension, and change are examined. Further agile techniques and principles like Unit Testing, louse coupling and Inversion of Control are introduced. Many problems are supported by code examples and are quite convincing.

Not only the bad examples are given, also more “lightweight” frameworks and approaches are described in each chapter and more agile solutions to the problems that the “heavyweight” methods are attacking are presented. A nice side effect is that by reading this you will get a good overview of existing approaches and solutions.

After introducing general “lightweight” methods, the second part of the book examines two frameworks in detail and uses these to build an example application.

Bruce A. Tate and Justin Gehtland start by introducing Hibernate, an OpenSource object/relational persistence and query service for Java. With Hibernate your Java objects gets persistence just through configuration, without adding code. Chapter 8 will then introduce Spring, a lightweight container for EJBs that includes an abstraction layer for transactions, JDBC, persistence (through Hibernate, JDO, or iBATIS), AOP functionality, and a MVC web framework.

Chapter 9 and 10 will show you how to use Spring and Hibernate by developing example applications and are successful in given an overview of Spring’s capabilities. The book ends with chapter 11 and an outlook challenges and interesting techniques.

My impression is that the book is really helpful in order to convince you of the advantages of “lightweight” approaches and to learn the drawbacks of common technologies. If you already know that EJB 2 is horrible, don’t worry, you won’t be bored as enough alternatives are presented. Especially the second part of the book gives a good overview on the most popular alternative, Spring in combination with Hibernate.

Apart from the technology centered view, Bruce A. Tate and Justin Gehtland teach general principles that apply to every software development process.

Review: Hardcore Java

Posted by Jonathan

Hardcore Java by Robert Simmons, Jr. is targeted at intermediate to advanced Java programmers who want to learn some advanced techniques and underused concepts of Java. The book is organized into 12 chapters over 324 pages.

Harcore Java

The book begins with a brief review of Java’s core concepts like references, runtime type identification, and iterators. Not so popular features like break, continue, labels, and assert are covered before constructors and initialization are discussed. The chapter ends with common mistakes like overuse of System.exit(). Also access issue are covered. Personally I liked this review as most of the visualized items are often not used or misused in Java like using private accessors for instance variables and therefore prohibiting extension of a class.

Chapter 2 is completely devoted to the final keyword. Final constants, parameters, methods, classes and variables are covered. This may sound boring but instead useful hints and concepts are taught. For example Rober Simmons, Jr. shows how to archive conditional compilation in Java.

Chapter 3 covers immutable types and immutable collections while chapter 4 examines the various collection types that are supported in Java. What I didn’t like were the performance hints like using temporal variables to hold query results instead of calling the query inside a loop or using StringBuffer instead of String for appending long Strings. I just read Martin Fowler’s “Refactoring” some days before and he argues that such performance optimizations cost readability and maintainability and I tend to agree. Apart from that chapter 3 and 4 give you a strong background on immutable types and collections and on when to use which collection.

The next chapter is about Exceptions and on how and when to use Exceptions and RuntimeExceptions. The presented advices are sound and useful as many programmers either over- or underuse Exceptions (including myself, I tend to overuse them).

Chapter 6 examines Java’s nested classes like inner class, limited-scope inner class, anonymous inner class, and static inner class. This also a part of Java that is often not clear to many novice programmers and Robert Simmons, Jr. succeeds in clarifying it.

Chapter 7 covers how to use constants in Java. It begins by explaining bit fields and why they are evil. Constant Objects are proposed as an better alternative.

The next chapter, “Data Modeling”, is about how to attack a bigger problem. Gathering requirements, modeling and object relationships are covered briefly. Then mutable objects and constrains are explored. The beginning of the chapter was a little bit too “Waterfall model” for me as I tend to favor agile methods. Then Robert Simmons, Jr. tries to build a framework for decoupling and programming for bigger projects and I liked his approach apart from the design phase.

The book then continues with Java features and patterns that are not so known. Chapter 9 is all about Reflection. Not a very deep API discussion but more a discussion on why to use Reflection and how the main approaches are used. Chapter 10 uses Reflection to build Proxies and introduces their idea. Chapter 11 discusses the lesser know references in Java; weak references, phantom references, and soft references. An overview of ReferenceQueues, Garbage Collection and practical applications make this a very good chapter on references in Java.

The book ends with a preview on JDK 1.5 Tiger and the new features like autoboxing, generics, and for each loops.

In summary this is a very good book on advanced Java features that introduces many patterns that are assumed in J2EE or EJB books. The chapters on the final keyword, on references, and on constant objects should be read by every Java programmer.

More effects in prototype.js

Posted by Jonathan

Thomas Fuchs, who is involved in Ruby on Rails and protoype.js, published a demo site with some new effects in prototype.js.
protoype.js is a object-oriented Javascript library for dynamic web applications. This library is responsible for the presentation of the AJAX effects that are supported in Ruby on Rails.

If you do not know his older demos, be sure to check them out.