Collections Framework

This week my college class is doing the chapter on the Java Collections Framework. The textbook was very confusing. It looks like there are some interfaces to get familiar with. Then there are multiple classes that implement the interfaces. Other interfaces are involved as well. Initially I was overwhelmed. Now I am trying to focus on a few classes at a time.

I found that Wikipedia has a good overview on the collections. The first class I got familiar with was the HashSet. This thing is a generic class. You need to pass in the type of the items that are stored in the collection. HasSet implements the Set interface. As such, it can only hold unique items in the collection. You add() items to the set. You can also check whether they are already ikn the set with a call to contains().

The second class I played with is HashMap. Do you see a pattern forming here? This class implements the Map interface. You store key/value pairs with this thing. You need to specify the types of the key and value when you create the generic class. Then you put or get key/value pairs.

Most of these collection-related items seems to be in java.util. Let's see if I can figure out all the other classes and interfaces. I am studying it hard.

James Gosling Makes a Move

I just read a post about James Gosling quitting Google corporation. He has moved on to work at Liquid Robotics. What a name for a company. The guys is going to be chief architect there. This is surprising. I thought Google would have been keeping him happy and well paid. Perhaps sometimes you need to make a change, or work for the little guy.

In the rare instance that you do not know, James Gosling is the inventor of the Java programming language. He did that back when he worked for Sun Microsystems (which has since been acquired by Oracle). Poor Google. Gosling only lasted 6 months there. Is there more to this story?

Advanced Java

I have been away from the Java programming language for almost the whole summer. There was an app I wanted to write. But I needed it to work quick. So I fell back to using C++. Now I want to get back into the Java swing of things (no pun intended). This week I signed up for a community college course on Advanced Java.

I was a little shocked by the price of the class. It rang up to around $800. That does not even cover the cost of the book. I thought community college was supposed ot be inexpensive. It might be worth it though. We are supposed to cover topics such as collections, multithreading, generics, database programming, network programming, and Java Server Pages. Dang. That's quite a list.

To get my Java skills back, I decided to read the first chapter from the class textbook. It is on recusion. The Java syntax for recursion is simple enough. Understanding the technique of generating a recursive algorithm to solve a problem is hard. With the new Java class coming up at the end of the month, I think I will be more chatty on my blog about Java points of interest.

Deployment Options

I got a new idea for a computer program I want to write. First I need to walk the thing all the way through to completion. I need users to be able to run this program on their own machines. I am thinking about using Java for the coding, but want to ensure a smooth user experience.

To run the Java bytecode on their machines, the users will need the Java Runtime Environment. What if they do not have it on their machine? Or what if they have the wrong version? I need my software to work the very first time, and every time after that.

I did some research on the subject. I can package up my files as a jar. However this still requires the JRE to be installed. Or I could go the web way and use Java Web Start. That would require me to set up a web server to host the apps. Then they will get downloaded to the user machine. That might require too much infrastructure for me.

I could also distribute the program as an applet. Then the whole thing runs in the browser. This also requires some infrastructure. But it will just be a web page. I do not have a lot of experience with applets using Java. That is a consideration.

Finally there are some compilers that produce executables that run directly on the user's native machine. This is the next best thing to developing with a language like C++ and compiling a version for the target machine. I need to play with ohe of these programs that produces a stand alone Java executable before I make a final decision.

Back to Java

I have been spending time learning JavaScript over the past year or so. However now it is time to return to Java. Later this year I plan to take an advanced Java class in school. However for now I am writing some small utlities in Java.

I was surprised at how rusty I got. You need to use your skills to keep them current. I coded a simple switch statement. Being a good developer, I tried to use some constants in the labels of the switch statement. They did not work. Ooops. I forgot to make those constants "final".

There was something that surprised me a bit. I put together a switch statement that initialized a variable. I included a default label in the switch clause. So all paths through would get the variable initialized. However the compiler still gave me a warning that the variable might not be initialized.

It was a small thing. But I don't want any warnings in my code. So I had to blatantly initiallize my variable. Not so clean.

Java Micro Edition

Oracle seems to be standing behind Java Micro Edition (Java ME). The mobile market relies heavy on Java. It is good for developers too since Java lends itself to cross platform development.

There are three layers to Java ME: (1) configuration, (2) profile, and (3) packages. The configurations are further divided into two flavors. You have connected and connected limited configs. The difference is how powerful the target device is.

Java ME supports "over the air provisioning", or OTAP. This allows you to install Java apps over the wireless network. Java ME also provides things such as security, UIs, and offline support.

JavaScript Forms

I am working on development a web app game. It is being written in JavaScript. I had learned how to do forms, so I made the game use a form. The majority of the screen is a big select area. I was going crazy because my JavaScript code was generating errors. The browser kept complaining that document.forms[0].mySelect was either NULL or not an object.

This was troubling because I had coded successful projects that used this technique. Googling the web also showed many examples of this working. To get by I hacked some getElementById calls instead. It still troubled my. I was running Internet Explorer 8. This stuff should have been working.

Near the end of my game development cycle I had to add more items to the form such as a status message. That is when I found the root cause of the problem. The select element was not within the form tags in the HTML. Ouch. No wonder JavaScript could not access the select object. It was just not part of the form. Now I got an action item to go back and use the familiar technique to access the form data in JavaScript code.