Re-kindling Java Skills

I have now worked on several PHP web-based projects and have learned how the Joomla API works as well as how to build custom components for Joomla. I have even done some minimal work on C#/.Net. However, I haven’t once touched java in about 5 years. So, several days ago I began re-kindling the Java “flame”. So far things have been going along quite smoothly. I have (much like PHP) noticed some major changes in Java. Mainly the IDE’s (again, much like PHP) that are available to develop with. When I worked heavily with PHP the IDE’s were not nearly as well developed as they are now. There was no Eclipse PHP or Eclipse Java. There was nodebugging PHP. Even syntax highlighting was JUST starting to become popular. Now all of these concepts are well and established and it seems like it is a lot easier to work with.My Java project… I decided that the time tracking software that I currently use could use a few changes so I figured a time tracking project would be a good re-kindling project for my Java experience. It might even be nice to have as a product on my webpage… So the first thing I did was installed Eclipse JAVA. This went about as smoothely as the Eclipse API IDE installed. The major difference is that there seems to be many plugins available for the Java IDE and in this case I think they would actually serve a purpose. For example, by default it doesn’t appear that the Eclipse Java IDE has any built-in dialog/window/form designer. There seems to be many available on the Eclipse Java plugin page though: http://www.eclipseplugincentral.com/.

Installing the plugins was a bit difficult at first. When it boils down to it though, manual installation of the plugins is as simple (generally) as drag-and-drop (or copy-and-paste or extract-to) to the eclipse plugin folder. The key there though, was that you have to create a sub-directory for the new plugin and keep all the plugin’s files in that sub-directory. I got confused on this because of some random google article I read that said you have to merge the plugin.xml files with the “main” plugin.xml file which gave me the impression that the plugin.xml file they were talking about was the one in the root plugin folder. It turns out that each plugin has it’s own plugin.xml file which makes complete sense when you think about it. Oh well.

Automatic installation of Eclipse Java plugins is even easier. Most plugins have a reposoitory/installation URL that you can tell the Eclipse Java IDE about. All you have to do is go to Help->”Software Updates” and tell Eclipse about the new plugin’s URL and you are pretty much good to go. Then you just select the plugin versions you want to install and the IDE takes care of the rest. Voila!

The entire purpose of investigating the IDE’s plugins was because I wanted a way to visually design my dialogs/windows/forms for my new Time Tracking project. The first plugin that I installed ended up having a trial period and cost something like $200. I don’t have $200 right now to spend on an IDE plugin and I don’t really want to anyways. The second plugin I installed didn’t even work (although I can’t remember what the name of the plugin is), but the third plugin that I ended up installing seemed to do OK.

Java DOES resemble C# quite a bit (or perhaps I should say “C# resembles Java quite a bit” instead)… The language’s syntax is almost entirely the same with only a few minor differences such as:

  • You have to explicitly specify the classes that you want to import (instead of “using” you “import”). If you don’t want to specify each class to import, then you have to specify * as a wild-card to include all classes in the namespace. Although, it seems that some IDEs (Eclipse) seems to not like the wild-card and ends up refactoring the code to import specific classes (although I believe there is an option to turn that off somewhere under code formatting).
  • Properties are not treated the same. In C# the compiler automatically handles converting the properties’ getters and setters to get_XXX() and set_XXX(x) methods, but Java does not. So, there is more work when creating data objects because you have to write out each of these get and set methods for each of the fields that you want to publicly expose. Again though, the Eclipse IDE goes a long way towards helping make this process more efficient by providing refactoring tools to automatically write these out.
  • Because Java does not handle properties the same way that C# does, events aren’t handled the same either. Instead of seeing SomeClass.SomeEvent, you will see SomeClass.addSomeListener(handler). I also see that it is very popular to write a lot of in-line delegate methods in Java, where you see stuff like: addListener(AWT.Show, new Listener() { public void EventHandler(Event ev) { // Do something } });

Working with databases in Java is a lot more complex than I remember as well. Perhaps because there is so much open-source in Java that it muddies up what “the right” database to use actually is. Trying to identify a good embedded database to use for my Time Tracker project was very difficult because there are just SO MANY different database options.

I ended up using Apache’s Derby database product for my Time Tracker project. Derby, like many other databases, follows the same basic SQL principals with just a few minor differences. The big one that I struggled with is how to retrieve the newly generated ids of auto incrementing unique id fields. It ended up being that I just needed to call “stmt.getUniqueId()” (or something of the sort) after I have executed the statement. In previous experiences I have had to call two statements in my execute to get the new id (one for the insert and one for the select, separated by a semi-colon so that the database recognized that they were two separate statements). Trying to do this in Derby just ended up causing exceptions to be thrown because Derby doesn’t like multiple statements in one execution (still not sure why).

Creating unit tests were as simple as ever (particularly with the Eclipse IDE). Eclipse has built-in JUnit support, so when you go to create a new document/item in your project there is an option for a JUnit test. When you do that it inherits the appropriate JUnit test case class and you’re off to writing your unit tests. The only complex part for me about unit testing is that if you want the tests to be run in a certain order you have to specify it with a “unit test suite”. However, running tests in a certain order doesn’t really make much sense because the test classes are re-created between tests. So, if you initialize a local field in the test case class with method1() you cannot expect the field to be set when you get to method2().

The core of Java is no harder (for me) to work with than any other language I have encountered… There are just minor differences that you have to learn (or in my case re-learn). Writing this Time Tracker project has been like riding a bike: Sure, bikes may get more technical and they make look more fancy, but you never forget how to ride. It does seem to me that “standards” and “patterns” aren’t as heavily focused on (at least not as heavily talked about) in Java. I have been looking for patterns on creating applications in Java for a while and have never really found any. Enterprise applications just don’t seem to exist in Java. In fact, when I talked to a buddy of mine (who happens to be an once-upon-a-time Java guru) about the same concept and he almost laughed when I used “enterprise” and “java” in the same sentence. As far as I can tell, C# is definately leading the way for the new age of software development (although maybe I’m just re-stating the obvious).

 

Posted in: Uncategorized

Leave a Reply

Your email address will not be published.

Humanity Verification *Captcha loading...