The 8 Nights of Java – Night 7

Our 8 Nights of Java series is nearly at an end! Tonight we look at Java 7, the first version of Java released entirely by Oracle. Java 7 included many goodies for developers, in the form of Project Coin. In a lot of ways, Project Coin was straight off of most developers Top 10 Wish List. Like Java 5, many of the futures were compile-time enhancements and helped to simplify numerous lines of code down to just one, allowing developers to focus on the important logic in their classes rather than syntax.

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

Java 7 Notable Features
Oracle released Java 7 (codename Dolphin) on July 7, 2011. After 5 years of Java 6 (including 131 updates) and the acquisition of Sun by Oracle, it was finally time to add some new features to Java. Key new functionality included:

  • Project Coin:
    • Strings in switch statements
    • Underscores (_) in numbers
    • Diamond (<>) operator
    • try-with-resources statement
    • Multi-catch blocks
    • Binary literals
  • NIO.2
  • Expanded Concurrency API

From Scott:

I love Java 7. While Java 5 “fixed” Collections by adding generics/autoboxing/foreach loops, Java 7 greatly improved the language by adding things that I didn’t even realize I was missing. The greatest of those (for a database-driven developer such as myself) was the try-with-resources statement. We’ve spoken in the past about finally closing JDBC resources, and to be honest, even we forget to do them sometimes. Could you blame us? The syntax was horrible. Especially because close() throws a checked exception which often must be caught inside another catch block! The try-with-resources statement fixed this not only by designing a syntax that was simple and easy to use, but finally providing a “standard” for all developers to work off of. After Java 7 was released, if I came across another developer opening/closing a connection without a try-with-resources statement, I could instruct them to replace it with one that does, thereby ensuring any possible resource leak is closed.

Project Coin had many other, very useful features. Strings in switch statements had been requested by numerous developers, especially beginners learning Java, for the better part of a decade. The diamond operator, while seemingly simply, greatly reduces assignments involving embedded Collections… such as “new HashMap<String,List<Integer>>” to just “new HashMap<>”. It was a pain to write out the full generic expression on both sides of an assignment! I don’t tend to use binary literatals or underscores in numbers, but I’m thrilled they were added to Java 7 since it makes reading other developers code a lot easier.

So many awesome features for developers in Java, I haven’t even gotten to the improved Concurrency API and new NIO.2. Both are extremely powerful, fully developed libraries that you can use to developer complex applications in minutes. And both got even better in Java 8 with the inclusion of… oops! Guess we’ll have to wait till tomorrow night to finish that sentence!

From Jeanne:

When I was young, the local college built a science building and named it the “New Science Building.” It’s still called that.The problem is what you call the one after that. NIO.2 had the same problem. “New I/O” didn’t take so well and now the name is taken. Luckily NIO.2 is nice! I use it a lot in my coding because I do a lot of file system work. I find myself using Apache Commons for I/O operations very rarely now.

Then there is Project Coin. While some is just semantic sugar like the diamond operator, it still makes the code cleaner and less redundant. The try with resources is great for not having to deal with boilerplate code! I also appreciate multi-catch. Before it existed, I’d often revert to “throws Exception” rather than independently catch two or three exceptions and handle them the same way. This happened a lot with a framework we used that declared two checked exceptions. It also happened a lot with XML parsing and reflection. With multi-catch, I’m more inclined to do the right thing and handle them all in one line.

The 8 Nights of Java – Night 6

Continuing on our 8 Nights of Java series, we move on to Java 6. Java 6 was about making Java “more”. As a result, a lot of the changes were important, but didn’t affect a developers day-to-day tasks. For example, annotations affected tool and library developers but were mostly unused for regular developers. Java 6 was initially released by Sun Microsystems, and later taken over by Oracle as part of the acquisition. This was also the last version of Java in which the Professional certification (SCJP renamed to OCP) could be completed with a single exam. Starting with Java 7 and continuing in Java 8, two exams are required to obtain an OCP certification.

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

Java 6 Notable Features
Sun released Java 6 (codename Mustang) on December 11, 2006. Notice they dropped “.0” from the version number, going from Java 5.0 to 6? This would be the last version of Java released by Sun, with Oracle taking over the Java 6 updates in 2010. Of all the versions of Java, version 6 was out there the longest, with 5 years (and 131 updates) before the release of Java 7.  Key new functionality included:

  • Renaming J2SE to Java SE
  • Common annotations support
  • JavaScript Rhino support
  • Performance improvements
  • JDBC 4.0

From Jeanne:

I have no memories of Java 6. I remember using it. While it was nice to finally ditch the “2” from the name of J2SE, I can’t think of a single thing that was new in it that I cared about. That said, the commons annotations support was a big deal. It let libraries like JUnit and Spring use custom annotations to be more expressive and easy to use. I do appreciate the feature and know it came from language updates. But since I used it when the libraries came out rather than when Java 6 came out, I don’t intuitively think of it as a Java 6 feature.

This does seem like a good place to reflect on the change in stewardship. We’ve been hearing about Oracle’s takeover spelling the death of Java since at least 2009. That’s right. The worries started even before Oracle acquired Sun. The rumors are still with us and stronger. They’ve moved more to the Java EE space more than in the core Java space. Oracle did rename the certifications from things like SCEA (Sun Certified Enterprise Architect) to OCEA (Oracle Certified Enterprise Architect). No surprise there. They also controversially added a requirement to take a class to a few certs to be more consistent with the database cert. Luckily, this requirement does not exist for the certifications Scott and I have written books about!

From Scott:

I have to agree with Jeanne on this. While Java 6 was a maturing release, with lots of new methods and features built on top of existing APIs, it paled in comparison to the Java 5.0 release in terms of scope. In other words, there wasn’t a compelling reason to go out and install Java 6 on all of your servers and desktops. As Jeanne started, the biggest change was really about Oracle’s acquisition of Java and handover of the platform and staff (remember Sun employees overnight became Oracle employees!). Java 7 was delayed almost 5 years because of this transition. As I said on Night 1, people have been predicting the death of Java since the first year it existed and the acquisition by Oracle was no different. While Oracle did make changes to Java, especially to the certifications, it’s fair to say they kept most things intact, helping Java to continue to thrive today.

One other important note. Java 6 had the most number of updates and patches, in part because so many “zero day” bugs were discovered. I’m not sure this was a deficit in Java, so much as this was Java spreading as a server platform across the web. Any server technology must be constantly kept up-to-date, as exploits are discovered all the time in the wild. As of April 2015, Oracle no longer publicly supports Java 6. Any servers running Java 6 must be updated and any that are not are prime targets for hackers.

Announcing: Our NEW Java OCA / OCP 8 Practice Test Book!

pt-cover

Jeanne and I are thrilled and excited to announce that we are nearly done writing a brand new book for the OCA / OCP Java 8 Programmer exams!

The new book, OCA / OCP Java SE 8 Programmer Practice Tests, includes over 1000+ hand-crafted and peer reviewed questions. We’ve also created a new permanent Practice Tests OCA / OCP 8 book page on the blog to keep track of updates and news about the new book.

Jeanne and I wanted to say how thankful we are to our all of our readers of our first two books. Without your invaluable feedback and positive reviews, we never would have been offered this opportunity to expand our OCA and OCP subject matter. We promise to make this next book our best yet!

We are expecting to ship the book in March 2017. Stay tuned for additional news about the book!