The 8 Nights of Java – Night 1

Given the holiday season, we thought it would be fun to share our favorite (or least favorite) features from all 8 versions of Java that have been released to date. Some features, like generics and autoboxing/unboxing, were met with a lot of fanfare and have since changed the way we as developers write code. Others, like NIO.1 and RMI, are not nearly as popular today as originally envisioned. With that in mind, we’ll be posting one entry each night on a different version of Java, starting tonight with Java 1.

Oh, we want to wish all of our readers a Happy and Healthy Holiday, as well as a Wonderful New Year!

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

Java 1.0/1.1 Notable Features
Sun introduced Java 1.0 (codename Oak) on January 23, 1996, with a more stable Java 1.1 released in February of the following year. These versions included:

  • Compiler and JVM runtime environment
  • JDBC
  • The beginnings of reflection
  • Inner classes
  • Thread class

From Scott:

Java 1.0 released.. well, Java! We all take for granted the ability to execute Java code on nearly every platform but back when Java was first released the idea of compiling source code into byte code and running inside a virtual machine was absolutely revolutionary. It was one of the first languages to allow developers to work freely in any environment and deploy to any other environment. Before Java, programmers tended to use the same operating system, same IDE software, and same compiler to write software that often could only run on a handful of environments. Java helped foster the open source movement allowing developers to work in Linux, Windows, MacOS, etc and deploy to any system. At a time when hardware and software systems were much more heterogeneous than they are today, Java helped improve productivity and sharing across a wide variety of landscapes.

Of course, early on there were some problems. Microsoft released Visual J++ alongside Sun’s implementation which contained only a subset of Sun’s features, as well as additional features Microsoft wrote themselves. These differences almost splintered the Java landscape within the first few years, since Visual J++ was so different from Sun’s implementation. Luckily for us, Sun intervened, successfully suing Microsoft on the basis that it violated Sun’s license agreement by releasing a version of Java not compatible with other versions of Java, helping to solidify Java as a standards-based language. In hindsight, articles like “Microsoft’s J/Direct called death of Java” written in 1997 (and comical now) would be the first of many (including a famous interview with Steve Jobs) to incorrectly predict Java’s demise. Today, Java is used in over 3 billion devices worldwide.

My favorite part of Java 1.0? The fact that the Thread class was included right away. Multi-threaded programming was still somewhat new, especially since multi-core processors were still in their infancy. Providing a new language in which developers could process tasks in parallel was pretty forward thinking, even if our thread-base implementations weren’t always perfect. Today, we tend to rely on the Concurrency API given its feature-rich convenience and stability, but never forget it’s is built entirely upon the Thread class.

From Jeanne:

Version 1.0 included Vector. While we no longer use Vector for new code, it paved the way for ArrayList and the Collections framework. JDBC is one of my favorite libraries. I use a mix of raw JDBC, ORM and Spring JDBC template these days, but JDBC started all of this. And then we have the parts of the language that stood the test of time. Plus since Sun/Oracle find it hard to actually get rid of anything from the language, we also have such fond deprecated memories such as Date’s getHours() methods. I was still in high school when Java 1 launched. I never actually worked with it directly as Java 1.2 was out before I started even reading about Java. When Java turned 10, it was cool to read Hello World(s) – From Code to Culture and see how Java got started. Or should I say how Oak got started?

emotional intelligence after 7 years

Yesterday I had an interesting discussion with a teammate who recently attended a course on Emotional Intelligence. He asked me if I had read about Emotional Intelligence. I said no, but this turned out to not be true. In 2009, I read Emotional Intelligence 2.0. I gave it 5 stars and called it a very accessible soft skills book. I even took the online rating test. At least my review says my self of 7 years ago found it interesting.

Changes in 7 years

Since I have no memory whatsoever of this, I took the test again today. Luckily, the book contains a passcode so I could see my old and new scores. I found my scores interesting. In particular, I think I rated myself lower BECAUSE I have more awareness of these things now than I did when I first read about the topic. Meaning I’m more aware of my weaknesses. In 2009, I wasn’t even particularly interested in the topic. I just got a free book at JavaRanch in exchange for writing a review. I’ve done a lot of things in this space since so I know I’m stronger now than in 2009! All that said, they recommend re-taking the test after 6-12 months, not after 7 years.

Category Change Comment
Self Awareness Exactly the same Weird! Wonder what are the odds of an exact same score.
Self Management Scored 10 points lower I definitely think knowing more affected my score. Because knowing what I’m feeling means I’m conscious of the small percent of the time where I let a reaction through that I didn’t want to even if it wouldn’t be observable to others.
Social Awareness Scored 10 points lower Knowing more definitely affected this category too. I immediately think of the Dunning–Kruger effect here. Seven years ago, I had so much less social awareness than I do know that I would have rated myself higher because of lack of awareness of what I missed.
Relationship Management Scored 6 points higher While I think I’ve always done things in this space, I’m more conscious of it right now because of the conversation I had yesterday that inspired this post. (more on this below)

Small Concrete Things

Flipping through the book, I should read it again. I really liked that it was lots of small concrete things to try. Rather than theory or vague statements like “try to understand people.” I should re-read it cover to cover again too.

Over time, I’ve mentioned some of the things I do without realizing they are related to emotional intelligence. A few examples:

  • Talk to at least three people I don’t know at a work reception (I do this because it is easier to stay with the people you know and this forces me to counter natural introversion and actually build my network. It also gets me away from my team to talk to the people I see less often.)
  • Introduce myself to anyone I don’t know on the floor. (Again counters feelings of being introverted)
  • Know in advance external forces will affect my emotions, so I can compensate in various ways. (Obviously you can’t always know in advance, but many things are known before work starts).

My mental model

“Dealing with people and feelings” stuff has never come naturally to me. So while I’ve tried to work on these compensating techniques, I’ve never felt good at it nor do I expect I’ll ever feel good at it. And that’s ok. I’m great at tech stuff and explaining things and mentoring people and many other things. And yes, I realize the oxymoron in there – mentoring people is part of “dealing with people.”

Also, continuous improvement is important. Time management is a soft skill I’m excellent at and do feel strong at. But I still spend time getting even better in that space. So I recognize that as long as my awareness of “dealing with people and feelings” grows at the same rate or faster than my mastery of the techniques I want to do, I’ll keep getting better without every actually feeling good at it.

Because “dealing with people and feelings” doesn’t come naturally I try to algorithim-ize it. If I can identify something I want to do that is concrete enough, I can consciously practice it until I can do it without thinking about it. The tricky part is identifying those things. (Which is one of the reasons the book is a good format for me – it is about specific things.)

The conversation that inspired this post

Anyway, finishing up, I IMd my teammate after we talked:

sharing: i can’t believe you had so many examples of me being effective in the space of communication/reflection/stuff from your class. i feel so weak at it. i think b/c none of it comes naturally

And he replied:

Understood. I think it’s the more remarkable because of that.
And you invest in it, because you value it. You could just be satisfied with “being bad at it.

His quote is great. I do value it. I also value continuous improvement in technical stills, soft skills and process. Whether it is something where I feel good, bad or medium, anything can get better. So I asked if I could use that IM quote in a public blog post and he said yes.

 

OCP 8 – working with autocommit vs savepoints

You might want to know more about JDBC than is covered by Chapter 10 of our book, OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide: Exam 1Z0-809. This blog post teaches you about autocommit and savepoints and assumes you have completed reading chapter 10 of our OCP 8 book and are looking to learn more. (Note: we’ve heard rumors this topic is in fact on the exam. It wasn’t when we took the beta but was on the Java 7 exam. So either the questions are left over or it was added back.)

In the book, you saw how to run one statement at a time and have the database automatically see the changes right away. This is called automatic commit or auto-commit for short. A commit updates the database. JDBC provides options for more control by running your code in transactions. A transaction allows a group of statements to go together.

Rollback/Commit

By default, auto-commit is set to true which means each statement is committed in the database as soon as it is run. You can set it to false so statements and prepared statements do not automatically commit data.

The following example gives that control. If anything goes wrong update either of the rows, the entire transaction is rolled back and the database doesn’t change either row. If both are successful, the database sees both.

conn.setAutoCommit(false);
String sql = "update species name = ? where id = ?";
PreparedStatement ps = conn.prepareStatement(sql);
try {
  ps.setString(1, "Elephant");
  ps.setInt(2, 1);
  ps.executeUpdate();
  ps.setString(1, "Monkey");
  ps.setInt(2, 4);
  ps.executeUpdate();
  
  conn.commit();      // send data to database
} catch (SQLException e) {
  conn.rollback();    // don't update database
}

Let’s rewrite this example to focus more on the commit/rollback code:

conn.setAutoCommit(false);
String sql = "update species name = ? where id = ?";
PreparedStatement ps = conn.prepareStatement(sql);
try {
  updateRecord(1);
  updateRecord(2);
  conn.commit(); // send data to database 
} catch (SQLException e) {
  conn.rollback(); // don't update database 
} 

Setting a Rollback point

JDBC has a type called a Savepoint which is like putting a bookmark in a book so you can easily get back there.

conn.setAutoCommit(false);
String sql = "update species name = ? where id = ?";
PreparedStatement ps = conn.prepareStatement(sql);
try {
  updateRecord(1);
  Savepoint sp = conn.setSavepoint();
  updateRecord(2);
  updateRecord(3);
  // oops - let's go back like this didn't happen
  conn.rollback(sp);
  // proceed from there
  updateRecord(4);
  conn.commit(); // send data to database 
} catch (SQLException e) { 
  conn.rollback(); // don't update database 
}