The 8 Nights of Java – Night 2

Continuing The 8 Nights of Java series, tonight we focus on Java 1.2. While Java 1.0 and 1.1 were about establishing a strong base and creating a set of classes that directly interfaced with operating system components, such as threads, Java 1.2 was focused on building on top of that base with convenient and reusable classes. For example, you could create your own dynamic array using the built-in primitive arrays, but do you really want to? Java 1.2 answered this by showing that Java was more than just a language, it was a useful set of reusable tools written by software developers, for software developers.

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

Java 1.2 Notable Features
Sun released Java 1.2 (codename Playground) on December 8, 1998. This version included:

  • Collections framework
  • Swing
  • Java Applet browser plug-in

From Jeanne:

Hard to believe the Collections framework has been with us for so long. It works. There’s lots of collections and opportunities for extension. And I’m thankful we don’t have a Collections2 or Collections3 framework. Something this core is useful to last unchanged. There have been Collection implementations added over time, but that makes sense because it is a framework. Even in Java 8, Oracle added static and default methods so they could leave the interfaces backward compatible.

As for the others. Well. I’ve written exactly one Swing program professionally. And I only did it because Console.readPassword() wasn’t available yet at that time. Unfortunately it is still with us. The wonders of “legacy code.” The Java browser plugin served its use. More recently, its contributed to feelings of Java being insecure though. It also contributed to some confusion between Java and JavaScript. I’ll never forget the day the help desk told me to reinstall Java to “solve” a JavaScript browser problem. Needless to say, I declined. And the problem was not related to Java after all. Gasp!

Fun fact: my very first Java program for school used Java 1.2.

From Scott:

I have to agree with Jeanne on this one. Although the Collections framework was a little difficult to use until generics were added in Java 5.0, they were from the start very powerful. I remember studying linked lists, hash maps, tree sets, and sorting in school. While all software developers should know these concepts and be able to implement them… in production software engineering it’s far better to go with a feature-rich implementation that has been written and tested by hundreds of developers than your own piecemeal solution (aka a “square wheel”).

As for Swing, I’ll be honest and say there was never a time I enjoyed programming in Swing. Even “back in the day” the Swing UI already looked quite dated. It was very difficult to write Swing code that looked good without relying on a number of often proprietary plugins, which required licenses to use. I remember registering for courses online (pilot program at the time, previous students had to do so in person) and a Swing app popped up within the browser, then promptly crashed 4-5 times in a row. I don’t know if the Swing apps I had the misfortune to use were just poorly written, poorly designed, or the underlying technology was just flawed. The one thing I do know is that I have never looked at a Swing app (either one that I’ve written or used) and thought it looked “beautiful” or was “easy to use”.

The limitation of Swing, as well as other Java UI languages, still holds true today in professional software development. While many people use Java for back-end systems, most use some flavor of Javascript (Angular, Node.js, Ajax) or mobile design tool (xib, storyboard, view, layout) for the majority of their front-end work. Even JavaFX, which was later billed as the “greatest Java UI language since Swing” was never able to gain much ground, in part because so many developers carried over a dislike of Swing. I do wonder how Java would be different today, if Swing had been easier to use and looked nicer.

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 
}