My Other Sites

Friends

Eclipse Plugins Are Bizarre August 1st, 2009

It’s been a while since I’ve posted anything. However, you can be rest assured that I’m not dead.

My job has been an interesting experience so far. There are company-wide changes being rolled in and I get to watch the company mature, so to speak. I finished the first assignment I was given (it took a month!), and although I went way over schedule, I blame 3rd parties for the hassle it took to get the feature underway. In any case, no one predicted that what I needed to implement wasn’t directly supported. Oh well.

The bad part is that working on that feature didn’t make me any more familiar with the Eclipse RCP. Staring at Eclipse’s plugin architecture for the first time is daunting at best. The API is rather shaky, and information about how to manipulate it is hard to come by. My task requires me to delve deep into the way the plug-ins are loaded, how the UI commands and actions are integrated, and how the views are added to the Workbench. It is not the most intuitive architecture, and Eclipse does try to hide a lot of its underlying classes, which adds to the frustration.

Fortunately I’ve made a lot of headway and have finally wrapped my head around a lot of what Eclipse has to offer. In a way, it is quite the powerful platform, once you’ve discovered what you can and cannot do and how to do it. I will be making sure to post about anything cool I’ve discovered for manipulating Eclipse and how to use the RCP as time allows. Stay tuned.

Java Scanner Weirdness May 11th, 2009

The most common problems I see in Java amongst newbies to the language is the use of the Scanner class. This particular class was created in order to make reading in data input from the command line easier for those new to the language. However, I fear it only half worked. Scanner is still a big pain to use.

First of all, do not even ATTEMPT to mix data types with the same scanner. It will not work. Having a Scanner read in a line of text and then read a single integer will cause an exception to be thrown, and then the person first learning Java gets a big headache and hasn’t a clue about what is wrong with the code. The fix for this by the way is to simply have different Scanners work over System.in, making sure each one reads the data in only one format.

The next biggest problem with Scanner that I see is the use of the hasNext() method. You cannot use the hasNext() method effectively when reading keyboard input from the command line. Usually I see this kind of code:

while (input.hasNext()) {

System.out.println(input.next());

}

If you cannot see the problem with this while loop, it’s because you have not realized that in this case, input is a scanner looking at System.in . The only way this loop will stop is if the end of the file is reached, and well, the command line can never reach the end of the file. This means the only way to stop this loop would be to input the EOF representation into the keyboard, which most people do not know.

Scanner has its problems, and if you want to advance as a programmer, I highly suggest using a BufferedReader. It’s a little more complicated but much less of a hassle later on, especially when you begin getting into much more complicated streams of data.