Don’t Be That Developer

Back in April of 2005, I came across a strange syntax in some java programming I was doing for work.


Back then, there was no convenient free StackOverflow site to quickly find an expert who would know off the top of their head what that syntax meant. And searching for “[” on Google certainly wasn’t a winning solution since square braces weren’t even indexed characters. How do you search for something that you don’t know the name of?

It took a while to find the answer. It turns out, it was a tricky way, using reflection of saying the same thing as short[].class

Really? Who would have guessed? It certainly wasn’t clearly documented anywhere, especially not in the code where it was used. And where it was used, there was absolutely no reason it needed to be using reflection and using some sneaky syntax.

Had the developer just kept it simple and written so much as a comment, or used a more straightforward, well-documented syntax the code would have been easier to maintain. We’re not playing Code Golf here (though even if we were, the non-reflection version still comes out shorter)!

Java Interview Topics

Here’s a list of common topics I’ve encountered on technical interviews pertaining to Java:

  • inheritance
  • polymorphism
  • multi-threading (locks)
  • interfaces
  • pass by reference/pass by value/pass by pointer
  • data structures/algorithms – eg: return top N duplicate results from large data set
  • set vs list
  • object vs non-object data types
  • internationalization – eg: utf-8 vs utf-16

It is a good idea to be prepared to discuss as many of these as you have experience with.

Java’s GregorianCalendar

Who would have thought up a calendar where the month starts at 0-11 but the days of the month run 1-31 (or so)? Its nice having full featured calendar utilities…but they could be slightly more intuitive to use, or at least consistent.

Dates in Java

how to get a non-deprecated time in java:

Date dateFromMessage = new Date(msg.getTimeAsMillis());
String expectedDateString = “1/19/05 2:50 PM”;

DateFormat d1 = DateFormat.getInstance();

String dateFromMessageAsString = d1.format(dateFromMessage);

dateFromMessageAsString + ” == ” + expectedDateString

Commenting Out Code

I think I scared myself, when in normal conversation(and by normal, I mean normal for a software engineer), I used the word OBERON. Yep, that’s right [the bane of my existence back in compilers class in college]. And not only did I say it, I was complaining that Java is not more like Oberon.

“If only Java allowed nested comments like oberon…”

Because, as it seems, Java does not appear to have any embedded language features that let you quickly and non-destructively comment out a large block of code which includes /* c style comments */, function headers, and does not necessarily compile where you are teleporting it to. If it were C, I could just add a #if(0) around it. Two short lines, and the entire function is commented out, non-destructively.

The only way I’ve successfully commented out entire functions is the macro and/or search and replace beginning of line technique to slash-slashify every single line. But that’s ugly ugly. ESPECIALLY when the file already contains //ified code, which is NOT my doing…and you can’t tell them apart. So then you start having to do something really ugly like //JRW// as the prefix for each line. Couldn’t I just if-zero it all out of my hair? I don’t want to be spending my time right now figuring out what includes I need, and what to do with these paramaters, and local variables I don’t have here…

or if only you could do nested c-style comments like oberon. (* cuz comments like this (* could be nested and *) that made everything happy, cuz you could comment out code with comments in it…and easily and cleanly… *)