OCA/OCP 8 Programmer Practice Tests AVAILABLE NOW!

Jeanne and I are really excited to announce that our new book OCA / OCP Practice Tests: Exam 1Z0-808 and Exam 1Z0-809 is now shipping. In fact, we just received our copies today! The book is available in both print and digital formats from Amazon and other major book retailers. In addition, purchasing this book grants the holder access to Sybex’s interactive test bank!

This book serves as worthwhile companion to our previous two books, now available as set, The OCA / OCP Certification Kit. With this book you are really getting two books in one, as Jeanne and I packed over 1000+ questions into this text, covering both the OCA and OCP exams. To better prepare you for test day, we also threw in two simulated OCA/OCP exams. Whether your taking the OCA exam now and thinking about the OCP exam down the road, or taking the OCP exam and need a refresher on the cumulative material, this book has got you covered!

This book covers 100% of all exam objectives in these practice tests, which means you’ll be ready for:

  • Java basics, class design, and data types
  • Using decision and loop constructs
  • Building and using arrays
  • Methods, encapsulation, and inheritance
  • Mastering Java Streams
  • Working with the Date/Time API and Localization
  • Understanding design patterns and principles
  • Writing Lambda expressions and functional interfaces
  • Exceptions and assertions
  • Java File I/O (NIO.2)
  • Concurrency and localization
  • JDBC and database applications

Jeanne and I put a lot of time, energy, and planning into this new book and we really hope our reader enjoy it!

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 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());
}
System.out.println(sum);

With Java 5.0:

List<Integer> data = new ArrayList<Integer>();
data.add(1);
data.add(2);
data.add(3);
Integer sum = 0;
for(int value: data) {
	sum += value;
}
System.out.println(sum);

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.