external motivation on unpleasant tasks

Main menu:


Recent Posts


December 2014
« Nov    

Past Posts

Java/Java EE



external motivation on unpleasant tasks

December 21st, 2014 by Jeanne Boyarsky

I’m usually good at being intrinsically motivated. Once in a while I hit a scenario where I know I have to do something and don’t really want to.  I was talking to a co-worker about how I handle this and realized I use a similar technique for the rare occasions this happens at work and when working on the book.

I’ve only needed to do this a handful of times over the years. But it has really helped when I did need to.

Step 1 – Pick someone technical that I respect a lot

For work, I picked a co-worker that I work very closely with. For the book, I obviously picked my co-author Scott. It would have worked with our tech editor Ernest as well though.

The key is to pick someone who I’ll be embarrassed to tell that I didn’t do what I said I was going to do. It can’t be a manager. Because the point isn’t really to be accountable to the person. It’s to feel accountable. (I’ve only done this in advance of the due date so I don’t procrastinate. IF I waited for the deadline, I’d actually be accountable, but then I’d be more stressed.)

Step 2 – Figure out a way to feel accountable

The next step is to figure out a way that I would be embarrassed if I didn’t do the work. Sometimes this is just mentioning it. When I was really stressed, I asked my co-worker to send me an email reminding me to work on it. That way I could look at the email as a reminder. I haven’t needed this in a while. Lately, I’ve been able to just imagine it.

Step 3 – Do the work

The whole point is to do the work before it is due so it is off my plate. And strangely this approach has worked for me.

why I like regular expressions + who says they aren’t readable

December 7th, 2014 by Jeanne Boyarsky

Scott and I are working on our second book (OCP 8). I’m excited that I get to write the part about regular expressions as that is one of my favorite programming topics. Why, you ask? Because it lets you write clear and efficient code.

The scenario

For the book, I wrote an example showing how validating a simplified phone number is so much easier with a regular expression. The rules for the example were:

  1. a phone number is exactly 10 digits
  2. a phone number may contain dashes to separate the first three digits and next three digits, but not anywhere else
  3. no other characters are allowed (no parens around the area code in this example)

For example, 123-456-7890, 123-4567890 and 123456-7890 are valid. In real life, the third one wouldn’t be; we allow this typo here to be nice.  However dashes aren’t allowed in random positions. 12-45-67-890 is not a phone number.

Without regular expressions

This isn’t in the book, but i tired to write the code “the long way” to ensure it was annoying long. It was. I tried to write the code in a readable way and the best I could think of was:

private static boolean validateLong(String original) {
   String phone = original;
   // remove first dash (if present)
   if (phone.charAt(3) == '-') {
     phone = phone.substring(0, 3) + phone.substring(4);
   // remove second dash (if present)
   if (phone.charAt(6) == '-') {
      phone = phone.substring(0, 6) + phone.substring(7);

   // validate 10 characters left
   if (phone.length() != 10) {
      return false;

   // validate only numbers left
   Set<Character> digits = new HashSet<>(Arrays.asList('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'));
   for (int i = 0; i < phone.length(); i++) {
      if (!digits.contains(phone.charAt(i))) {
         return false;
   return true;

This is a lot of code. And to those who think regular expressions are unreadable, what do you think of the above? I don’t find it easy to see what is going on even though I wrote it. There’s just too much logic and too much detail to ensure is correct. (And no, it didn’t work on my first attempt.)

With regular expressions

Re-writing to use regular expression gives me this:

private static boolean validate(String phone) {
   String threeDigits = "\\d{3}";
   String fourDigits = "\\d{4}";
   String optionalDash = "-?";
   String regEx = threeDigits + optionalDash + threeDigits + optionalDash + fourDigits;
   return phone.matches(regEx);

Even if you don’t know the regular expression syntax, it should be obvious what is going on here. We look for three digits, an optional dash, three more digits, another optional dash and a final four digits.

It’s a tiny bit longer in the book version because {3} isn’t on the exam so that part is:

String threeDigits = "\\d\\d\\d";
String fourDigits = "\\d\\d\\d\\d";

Still. Way easier to read and faster to write than the original code without regular expressions. I consider regular expressions like a hammer. They aren’t the right tool for every job, but they are quite helpful when they are the right tool.

finding out when Oracle changes the certification objectives

November 29th, 2014 by Jeanne Boyarsky

As Scott and I noted in the introduction of our book, Oracle tends to fiddle with the duration, number of questions and passing score of their certification exams. They also fiddle with the exam objectives themselves on occasion. And as you might imagine, these aren’t well publicized.

First attempt

I originally thought that I would use the ChangeDetection service to subscribe to receive an email when the relevant certification pages changed. This turned out not to work as the HTML is always the same. Oracle uses AJAX to fill in the data. For example, the objectives page for the OCA 8 is rendered using the XML on this page. My next thought was that I’d use the ChangeDetection site to monitor the XML page. No such luck, they don’t support XML.

Writing something myself

A differences program isn’t hard to write, so I created my own in a public github repository. It stores a copy of the “current” data for each exam it follows and checks for differences. (I have it running as a Jenkins periodic build so it checks for updates once a day.) I considered using Travis CI since it supports Java/Maven. However, Travis doesn’t yet support periodic builds. There is a third party site that can trigger your builds for you, but CodeRanch has a perfectly good Jenkins server. And since one of the goals of this project is to be able to announce certification changes on a timely basis in the forums, it seems reasonable to run it there.

How do you find out if there is a change?

For significant changes, we tend to mention them in the relevant certification forum. For the OCA 8 exam, we will also list objective changes on the book page. You can also look at the text files for each exam on github. The last modified date shows the last change. You can also click on the file to see the history/diffs to see what changed and approximately cool. You could even use the ChangeDetection service on the github pages since they aren’t XML. For example, this page is for the OCA 8.

If there is an exam you’d find useful to be tracked and isn’t already, please add a comment on this blog post.

Technologies used

  1. Maven
  2. Selenium (a tiny bit)
  3. HTML Parser
  4. JUnit/Parameterized test