The 8 Nights of Java – Night 5

Java 5.0 was the biggest change to the language syntax since it came out. The designers of Java managed to complete this impressive feat without removing any existing syntax and by keeping everything backward compatible. They accomplished this by leveraging compile-time enhancements. A compile-time enhancement is a language rule that a developer can use to write and build software with, but that gets stripped out of the compiled file. For example, Generic notations like List<String> are actually removed from a class when it is compiled, resulting in just a List of Objects. This technique allowed the authors of Java to thrust it into the future, with minimal impact on existing implementations.

Jump to: [Night 1 | Night 2 | Night 3 | Night 4 | Night 5 | Night 6 | Night 7 | Night 8]

Java 5.0 Notable Features
Sun release Java 5.0 (codename Tiger) on September 30, 2004.  Notice we went from 1.4 to 5.0? That’s right. Java finally dropped the “1.X” from the name with Java 5.0! Sun realized that they were far out of beta testing of Java (with millions of businesses around the world using their software) and rather than go from 1.4 to 2.0, they decided to just drop the 1. prefix. Key new functionality included:

  • Generics
  • For each loop
  • Autoboxing and unboxing
  • Varargs
  • Enums
  • Static imports

From Scott:

In my opinion, Java 5.0 helped saved Java as a modern development platform. Other languages with more advanced features were coming out, many that were far easier to write with. As I said on Night 2, Collections were powerful, but not particularly easy to use. Dynamic Lists with primitives were such a pain… I mean take a look at this before and after code:

Before Java 5.0:

List data = new ArrayList();
data.add(new Integer(1));
data.add(new Integer(2));
data.add(new Integer(3));
Integer sum = new Integer(0);
for(int i=0; i<data.size(); i++) {
	sum = new Integer(sum.intValue() 
			+ ((Integer)data.get(i)).intValue());

With Java 5.0:

List<Integer> data = new ArrayList<Integer>();
Integer sum = 0;
for(int value: data) {
	sum += value;

It might not seem like a lot, but when you have to write thousands of lines of code that use Collections and other generics, it makes a big difference! The syntax got even shorter in Java 7 with the Diamond (<>) operator!

At the time of it’s release, these changes were quite controversial. Some felt they shouldn’t be stripped out during compilation and should be made part of the JRE. After all, the two code samples above compile to nearly the same thing (except possibly with an iterator), but Java has always been big about backwards compatibility. I think part of what helped to settle the issue is that the drastic improvement and availability of multi-core processors, which made any theorized performance hit negligible compared to the huge benefit of writing simpler, more maintainable, and easier-to-read code. Being the “old man” that I am, I still sometimes call intValue() on an Integer. If you were writing in Java before 5.0, the variable can feel naked without it!

From Jeanne:

I still have my copy of “Java 1.5 Tiger: A Developer’s Notebook” and the stuffed tiger Sun gave out is on my desk at work. This was a great change to the language. Generics made the code so much cleaner and safer. Autoboxing made the code cleaner as well. Enums are awesome too. While I use static imports a lot, I have mixed feelings about them. It’s a bit like the debate on whether to use a wildcard in regular imports. Are static imports clearer than typing the class name in each place. Well, like many things in programming, it depends.

I was looking forward to varargs so much that I designed a class to use them before they were written. I remember writing a class in Java 1.4 with methods taking 1, 2, 3, 4, 5 and 6 String parameters (along with an array version) and a comment to refactor it in Java 5.0 to use varargs. I also remember the feeling when I could get rid of all that crud when we upgraded!

Looking back, I have trouble deciding which is my favorite new feature. I’m torn between generics and autoboxing. Generics makes the code safer, but autoboxing makes the code easier to read. Decisions. Decisions.

The 8 Nights of Java – Night 4

Continuing The 8 Nights of Java series, tonight we focus on one of the single most important releases of Java. Java 1.4 was released a time when many businesses were starting to look to Java as a foundation for their software systems. After years of licensing proprietary or difficult to use software, Java was seen as a breadth of fresh air for many software engineers. It was helped, in part, by the decline of Windows-based computers and explosive growth of Mac and open-source Linux systems in the workplace and in homes. After all, if all of your developers are using different operating systems, then you need a software development platform that works on all of them and in that, Java was a success. So many business adopted Java 1.4 during this time and stayed on Java 1.4 for over a decade. In fact, many large enterprise systems still rely on Java 1.4 to this day. Hopefully, someone will be hired to update them soon!

Jump to: [Night 1 | Night 2 | Night 3 | Night 4 | Night 5 | Night 6 | Night 7 | Night 8]

Java 1.4 Notable Features
Sun released Java 1.4 (codename Merlin) on February 6th, 2002. Key new functionality included:

  • Regular expressions
  • Assertions
  • NIO Version 1
  • XML/XSLT support

From Jeanne:

I love regular expressions. They are one of my favorite language features because they are concise and expressive when written well. I was excited when they came out. While I started programming as a full time job after Java 1.4 was released, we were still using 1.3 as we waited for the application servers to support Java 1.4. This meant I was already employed and got to teach my teammates about regular expressions. I’ve actually given that presentation a number of times since.

I don’t use assertions because I write a lot of unit tests and the unit tests tell me about the type of problem that an assertion would. Tests help me design my code in a way that I don’t need assertions to tell me about the state of affairs. And then there is poor New I/O. I really like Java 7 NIO.2. New I/O “1”, not so much. It served it’s purpose in getting us to NIO.2 though.

From Scott:

I started programming professionally around the time that XML/XSLT were seen as the “new hot technology” to use on build enterprise systems. Having built-in support for XML transformations made Java look cutting edge at the time. While a lot of what is now done with XML is instead done by JSON, XML is still the core of many data-based systems. In fact, numerous web and mobile frond-end languages still use XML for their layouts, even if the developers using them rely solely on a GUI-based editor. Either way, Java 1.4 demonstrated that new technologies could be integrated into the JVM quite rapidly. That said, I’m still waiting for a JSON parser to become part of the standard Java runtime environment!

Java 1.4 also introduced NIO version 1, or NIO.1 for short. While NIO.2 is a quite powerful, if not commonly used framework, NIO.1 is basically dead weight at this point. The NIO.1 API never really caught on and today, very few people rely on file channels and the like. Since a key part of Java is keeping backwards compatibility, it remains part of the JRE, albeit rarely used.

The 8 Nights of Java – Night 3

Continuing The 8 Nights of Java series, tonight we focus on one of the most monumental, enormous, earth-shattering… no wait, we’re talking about Java 1.3 aren’t we? Java 1.3 has a number of important implementation and JRE changes but from a developer standpoint, very few new features. In retrospect, Java 1.3 was important as helping to make Java more stable and set up some of the hooks that later versions of Java would tie into, but in and of itself, was kind of a minor release.

Jump to: [Night 1 | Night 2 | Night 3 | Night 4 | Night 5 | Night 6 | Night 7 | Night 8]

Java 1.3 Notable Features
Sun brought in the new millennium with Java 1.3 (codename Kestrel), released on May 8, 2000. Key new functionality included:

  • JNDI
  • Hotspot JVM

From Scott:

I’ll be honest, there’s not much in Java 1.3 that find particularly interesting. Yes, JNDI is important but it’s not very exciting and wasn’t really relevant until J2EE servers started becoming commonplace years later. The Hotspot JVM was also important for production and deployment, but did not change how developers wrote code since the change was on the JRE side of things. In other words, Java 1.3 was a bit of a bore. Luckily the next few “nights” of Java more than make up for it!

My personal experience with Java 1.3 wasn’t completely uneventful, though. I took my first database applications course, CS433, back in college around this time. Our task was to design a database-driven web-based system. Because my school had been extremely heavy on theory, it was the first time we could really ‘cut loose’ and build something fun that people could use. We chose to build an toy auction website powered by Java 1.3, JSPs served by Tomcat, and an IBM DB2 SQL database. My two other teammates and I had so much fun in the course! For extra credit, we decided to integrate our search functionality into eBay, parsing their results and transforming them with XSLT so that our results and their results appeared side-by-side. It was a wonderful time and in hindsight, probably set the foundation for the rest of my Java career!

From Jeanne:

I was still in college when this was released. In fact, I had just started learning Java in 1999.. In summer 2001, I had my first paid job (internship) that used Java. (It was my second internship, but the first used C++.) My main task was using XSLT to generate webpages. I got a fast appreciation for JSPs from that job. Using XSLT added another level of abstraction and another way of thinking while trying to make web pages.

While there wasn’t anything new I cared about at the time, that was because I didn’t know enough. I’m thankful for it though. JNDI is really useful when writing code that runs on a server. I can’t imagine not being able to register a DataSource or JMS queue through JNDI. I imagine some other standard would have arisen to fill the gap if JNDI wasn’t invented.