What I’ve learned about Java today

So it turns out there are a lot of different levels at which Java can be used, and it’s not immediately obvious which one you’re using at the time.  Nor is it really clear what the differences are between them.  This morning I tried to reintegrate the code that I wrote into the big project and discovered that there are a lot of things that Java has learned to do that it wasn’t always capable of doing when the original project was made, so I have to stop using those things.

You can’t declare lists with types.  So no ArrayList<String>, no no, you have to have an ArrayList and cast every single thing in it to a string.  (This is fixed in a later Java version.)

No type conversion between primitive things and their Object wrappers.  So no boolean to Boolean or vice versa, etc.  The end result is a lot of “new Integer(int)”s being created, which feels like it’s wasting a lot of memory by the time we’re done, since you basically have two versions of all the objects, one Double and one double.  You can’t even cast Double x = (Double) doubleVersion.  (This is also fixed later.)

For each loops are out.  In later Java versions you can say “for (Object obj : objList) and it would automatically iterate through the list for you; the equivalent of saying “for each Object obj in objList”.  In the earlier version, though, that’s out, so I wound up with a lot of “for (int i=0; i<objArray.length; ++i)” and whatnot.

On the subject of casting, I don’t think any form of Java has primitive casting.  I don’t know if this is a “feature” or a design decision, but either way it makes for some interesting work-arounds.

I have discovered the EXTREMELY useful Double function “byteValue()”.  It basically casts the double to a byte.  I was looking for something like this for parsing an array of doubles as a byte array (for image comprehension) and I kept typing “toByte” so I never found “byteValue”.  😛

Let’s see… if you have an abstract class that has a method that returns, say, an Object, it’s not good enough to have the subclasses return subclasses of Object.  So if I have, in AbstractClass, “Object createThing()”,  and then in  your SetClass implements AbstractClass you have “Set createThing()”, that’s not good enough.  You have to have “Object createThing()” in SetClass, even though a Set is an Object.  This is also fixed in later versions.

As always in Java, Strings are immutable.  Don’t try to edit strings in place, you’ve got to use StringBuilders or char[]’s for that.

A note about IDE’s, while I’m at it.  I’ve used quite a few, I’ve used Eclipse, Net Beans, Dr Java, IntelliJ, and straight-up text editing, and I must say that my favorite by far is IntelliJ.  Admittedly it’s the last one I used, so it’s possible I’ve just learned more about Java by now, but overall the UI is excellent.  There is a very easy-to-nagivate pane on the left, breakpoints are the easiest things ever, if you want to have two files up in the same window there are very easy ways to do that, it’s really good at finding the functions you want to use when you start typing, the text-coloring scheme makes sense… all in all I like it a lot.  The only off-putting thing is that there is infinite whitespace off to the right of your text, but you can turn that off easily or (as I did), adapt to it.

(Fun IDE trivia: Net Beans was created by Sun  Microsystems.  Eclipse, which came after, was named Eclipse because it was meant to “eclipse” the Sun product.  Source: my mom, who worked at Sun before it was acquired by Oracle, and who now works for Oracle.)

While we’re at it, text editors.  Most folks here at the workplace use Notepad++.  It’s okay, but I prefer SublimeText 2 in terms of UI.

And now, part TWO!  Things I’ve learned about SalesForce today.

Allow me to start by saying that WOW, SalesForce has quite a learning curve.  In fact, I have illustrated the learning curve I have experienced today and put it in this handy chart.


The only way I managed to send a query off to the database was to go down the hall and ask Wendy (who is writing the SalesForce version of what I did with MongoDB) to run the query for me.  I’m sure it’ll get better in the next week, but MAN it’s not easy to pick up.

Screen Shot 2013-07-11 at 7.47.57 AM

Anyway, we’ll say how tomorrow goes.



Leave a Reply

Your email address will not be published. Required fields are marked *