Back to Java

I did a bunch of analysis on my last project. The customer wanted more project management. So another guy on the team had to take over, My boss told me to work on a prototype for some data input screens from a legacy system.


Some of the screens are huge. And they have complex validation logic. I fired up my text editor. Wrote some HTML and JavaScript to get the first screen done. That intro screen was small, but it had a ton of validation.


My boss called me up and checked on my progress. He clarified that he wanted me to use Java, Derby, AngularJS, REST, and JBoss EAP.  He said some acceptable alternatives would be Oracle, HTML5, and Eclipse/Tomcat. I went with his recommendations.


I got JBoss Dev Studio with EAP installed on my new laptop. Then I started going through a tutorial from JBoss called Ticket Monster. I was following a pretty detailed tutorial. Things got vague when I was instructed to deploy the H2 console. Err what?


H2 is an in memory database. I went over to the JBoss Developer Materials page. Downloaded the zip file with the H2 console. Unpacked it and found the "h2console.war" file. Dropped that in the \runtimes\jboss-eap\standalone\deployments folder. Now here I am.

JBoss Developer Studio

At work I am starting to spend half my time on a new project. It is an effort to create a web version of our system. It will use the same Oracle back end. However the front end will be developed in Java using JBoss Developer Studio.

JBoss Dev Studio is a rebranded Eclipse IDE. I know Java. However I always use a text editor to force me to learn the syntax and member functions of classes I use. So I am not well versed in Eclipse. This is going to be a long learning curve.

One thing I found out is that if you have a workspace open in one instance of JBoss Dev Studio, you cannot open it in another instance. Makes sense I guess. But I fought with that for a while before I figured it out.

I also learned that you may need to refresh your source tree for any changes in packages that your source supports. Go figure. Finally I found that I installed my software in the wrong order. I initially installed JBoss Dev Studio first. It then made me choose a JRE. Then I installed the latest JDK I wanted to use. Unfortunately I had to figure out how to reconfigure JBoss Dev Studio to use the JDK of choice.

Foiled by MySQL Connector/J Again

All right. I dumped a lot of emails from Amazon to a text file. I parsed that file and have a lot of thousands of Amazon Kindle books that I own. Now I want to add them to a database. I want to stick them in MySQL specifically. So I call on JDBC to do the deed.

I run into the dread error "java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/". Now I have received that error before. I thought the solution was to stick the JAR file with the MySQL JDBC driver in the class path. Nope. That did not do the trick.

For a while I was pulling my hair out, trying to figure this out. Then I went back to an old project where I got this working. Turns out you need to explicitly path the JAR file in the classpath. I had thought you only needed to specify its directory. No. You need the fully qualified path including the JAR filename in the classpath. Go figure.

At least I got a boatload of book titles inserted into a MySQL database table. Now for the really fun part. Time to write a program to find the books on Amazon's web site and scrape some details out.

Web Scraper Revived

Previously I had written about my web scraper project. Well now I am coming back to it. I got a couple thousand eBooks in my Kindle reader. It is tough figuring out what book I should read next each time I finish a book. I manually go through a lot of books, looking up their pages on Amazon. Wouldn't it be nice if I had a program that could help me decide?

First order of business was to get a list of the books. At first I thought I might be able to hack the AZW file format and extract details from the books themselves. Nah. Too hard. Instead I remembered I had an email from Amazon for just about every book I bought. The emails were in Microsoft Outlook 2010. Turns out I could just save the emails as a text file.

Now my first job is parsing this file. I was hoping to get the links to the books on the Amazon site. Nope. That is not stored in the text file output by Outlook. That is okay. I can get the book name. Next I need to figure out how to take that name and programmatically search the Amazon web site for details on the book.

I plan to store my data in a MySQL database I got running on my machine. Right now I extracted all the book names to a text file. Next steps is to instead stick them in a database table. Maybe I will also record when I ordered the book. Then I will want to find and scrape the Amazon page for the book. Good things to grab from Amazon would be book price, date published, author, average customer rating, number of customer reviews, etc. All these goodies could be stored in my database.

Eventually I want to write a function or program that could score the books, predicting which books I should read next. Ahh this is going to be a very fun project indeed.

Pacman Progress

I am nearing the end of my summer project. This is a clone of Pacman written in Java. I think I will stop implementing new features. Just clean up the code. Fix some bugs. Package the thing and call it a summer.

Recently I did a bad thing. I deleted all my Java files. I wanted to delete all my class files. That will teach me to try to compile from the command line. Damn. At least I had a backup that was a week or two old. It still irked me.

Some buggy object code had the game crashing when exceptions were thrown. Now we still need to hunt down the root cause of those bugs. However I managed to keep things running by validating parameters passed into my functions. Prevents evil access problems.

Next thing I might try to slip in there is better timing for the action in the game. Right now I just sleep a hard coded number of milliseconds based on how much processing I figured I expended to render a frame. However I really should just poll the clock to figure out how long to sleep.

Hot Technology

I read an article that surveyed what technologies Java developers were using. Hey. I want to keep up with the Jones. So I am keeping an eye on the top tech in a number of areas. I write them down here so I don't forget.

JUnit for testing.
Eclipse as your IDE.
MySQL or Oracle for the database.
Hibernate is your ORM.
MongoDB for NoSQL.
Jenkins for CI.
Maven to build.
SonarQube/FindBugs/Checkstyle for code analysis.
Nexus to hold artifacts.
Tomcat app server.
Spring MVC is your web framework.
Scala is your next language.
Java8 is coming up.

Okay. Time to get busy making sure I got these technologies under my belt. You got to work with the best, or at least the most popular. Shout out to the makers of JRebel, who I assume came out with the report ranking the technologies.

Wakka Wakka

This week we are taking our video game to the next level. The prototype works good. I decided to make a number of noteworthy additions, including sounds. I had used sampled clips before in Java. I even knew the libraries I needed to include.

So Pacman chomps on a pellet. The game is supposed to make this wakka-wakka sound. I got an audio file that has the sound. Just got to play it each time Pacman goes over a pellet. The first time I tried it out I heard nothing. I figured this could not be right. I played sounds before for my last game.

Then I looked at my game loop. For now we are settling for choppy animation until we get all the mechanics down tight. To prevent the game from running too fast, I sleep() for a second each iteration through the game loop. Turns out you cannot play a clip and sleep immediately afterwards. Drat.

When I finally implement the full animations, hopefully the sound will play fully. For now I just moved my sound playing earlier up in my game loop, giving it some time to execute before the thread sleeps. Next up my partner has to add more AI to make the ghosts "smarter". Currently Pacman can outsmart them and leave them lost.

MySQL Connector J

My latest project is an Amazon web page scraper. I have almost 5k eBooks in Kindle format. Every time I finish reading a book, I have a hard time choosing the next one to read. I do a lot of searches on Amazon to figure out which of the books I own is the next best.

I figured I should be able to let the computer choose a book for me. To do that, the computer needs to have a lot of stats on the books I own. Time to mine the Amazon web pages for those books to get the data I need.

So I am working on a scraper to grab the data I need from Amazon web pages. Then I plan to store this data in a MySQL database. With all the facts on hand, I am sure I can write a function that ranks the books in order from best to worst.

Writing the scraping portion turned out to be a big pattern matching exercise. Check. Next I need to store the scraped data in the database. I thought I had coded some Java that accessed a MySQL database. Turns out it was Java that accessed a Java DB.

No problem. How hard could it be. Well I kept getting exceptions stating that there was no suitable driver found to access MySQL using JDBC. Err it turns out I need the MySQL Connection J jar file in the classpath. Who knew?

Pacman Fever

I partnered up with a friend of mine from school to work on some projects together. At first we did some database web apps in PHP. Now we are getting to the real fun. We are writing a Pacman clone.

Now I believe in starting small. Therefore I got Pacman to be drawn to the screen. The guy chomped around a rectangle nicely. My friend took on the task to get a ghost drawn. It drew, but ran off the screen initially. Bugs have since been fixed and the ghost bounces around inside the boundaries.

Next step is to draw a rudimentary maze and have the Pacman and ghost obe the walls of the maze. I think we got this.

Custom Tools


I was called by my boss to work on a tough problem. The previous developer spent a week on it and got nowhere. Great. Now the pressure was on. I was given a day to figure things out. So I got down to business. Had to try many things to replicate the problem in a development environment.

Sometimes I needed to update configuration data in the database. Most of the time I had to run some queries to figure out which values needed to be updated. Or I needed to run some specific pieces of some jobs, which turned out to be stored procedures. I figured there had to be a speedier way to do all this.

There is a better way. Create a tool to automate what I need done. What better language to implement this tool than Java? Figured I would use the easiest database access method I could think of. That would be JDBC. Unfortunately the last time I played with JDBC, I used it with a MySQL database that was running on my computer. Now I needed to access an Oracle database running on some huge server.

Luckily most of the ideas in JDBC transcend specific database choice. Just had to figure out the connect string. Turns out I could use an OCI driver that made use of a TNSNAMES alias. That was sweet. Took a while to get it working though. The real breakthrough came when I read the release notes for my Oracle 11g client that was installed locally. Turns out I needed to ensure a JDBC jar file was in my classpath.

My initial cut was a little slow for each action. That's becuase I was creating and closing out a session every time a task needed to be executed. Instead I need to refactor this to reuse one database connection that gets established when my tool starts up. That should be an easy enough fix. I wonder whether it is time to share my little tool with the other developers on my team?

Right Tool for the Job

I am dealing with this game system that cannot handle too many views to the ranking system. Sheesh. What is a developer to do? Scrape the screens, reengineer the data, and put up some new pages. That's what. I already grabbed the HTML output from a bunch of ranking screens. Now I need to parse through the heavy HTML and extract the raw data. Java is my tool of choice for this task.

I got a bunch of files. And I have studied them to learn the pattern of how the web pages are laid out. Now I need to go through the HTML, line by line, and grab the raw data. Luckily each page seems to fit a pretty well defined pattern. I just need to teach my Java code to read for the data like my own eyes can now.

Heck. Maybe I will even write the new implementation using Java. The original product was written in PHP. I suspect they have a MySQL backend database. For my first try, I plan to grab the data and stick it in an Oracle database. However it could just as easily work with a MySQL database.

The only question is that once I have an optimized replacement system, what language will I use to serve up the data? PHP? Java? Or maybe something else. For now Java seems best. I actually don't know PHP. So that is a main consideration.

Calendar Ease

I have been writing some toy programs to relearn my Java skills. This time around I decided to write a calendar app. Nothing fancy mind you. I just put out a text calendar to the console.

Initially I had visions of computing all kinds of dates. I thought I could start with a known day falling on a certain day of the week. Then I could compute all relative dates with some formulas. Sure I would have to deal with leap years and such. But that would be a great project.

I found that the Calendar class in java.util was almost all I needed. No need to compute the day of the week the first day of the month falls on. I just set up a Calendar object with that date. Then I interrogate it to figure out which day of the week it is. Same thing with determining the number of days in a month.

This exercise was quite useful. I got some practice. I also learned some details of a new class. Calendar feels like a nice API. You just have to learn some of its constants. Then you can get() or set() to your heart's content. I banged out my calendar app in about 50 lines of code. Given that I am a bit wordy with my code, that is not too shabby.

Case of the Blank Screen

I decided to continue my Java graphics programming with a simple program to draw a sprial. This should have been a cake walk. I kept in mind that the Math functions took angles in radians. My mind thinks of angles in degrees. The Math package can convert between the two units. For some reason, my graphics were not showing up on the screen. This was frustrating. A good developer know how to debug these things.

I output my coordinates to the console. Everything looked fine. Coordinates were getting further and further away from the center. Looked like the drawLine funciton was just not producing any output. I did all my drawing in a loop contained in the paintComponent function. I tried sticking some hard coded coordinates in my drawLine call. No change.

Then I moved over to the Graphics2D world. The draw function there did not work either. I did eventually make a breakthrough. Calls to drawLine outside my loop worked. WTF? Loops should not matter. And the output was good. I saw it on the console. Finally it hit me. I was initializing all my variables in the JPanel constructor. The loop stopped drawing when the lines went off the screen. My problem was that paintComponent was getting called more than once.

The first call to paintComponent worked fine. It also output the correct coordinates to the screen. However the subsequent call(s) to the function erased the screen. By then the variables had incremented past the point where they could be viewed on the screen. I guess I need to learn how to run the code in real time in a debugger. This is a little tricky with graphics programming, as I would need to see the graphics being drawn in real time as well. Sounds like a need for some type of graphics debugger.

Getting Rusty

I spent the last semester learning the basics of JavaScript. I promised myself that afterwards I would come back to the Java programming language. And here I am. I find that I have become a bit rusty in my Java programming. It has only been half a year since I knocked out some impressive Java programs. This was disappointing.

I broke out an old notebook that contained ideas for programs I wanted to write. Figured it would provide some inspiration for some practice Java programs. I started with an Address Rolodex program. It was nothing special. I had to relearn some of the GUI programming tricks I picked up last semester. Luckily I had to look up a few specifics. I recalled some of the tricks after a while. For example, I knew it was easiest to implement the ActionListener interface with my JFrame object. That way I coud just addActionListener(this) to set up my events. Much simpler than separate or inner clases.

The mechanics of storing my addresses were simply an ArrayList. Had to make a couple design decisions, like figuring out where the latest address you added goes in the list (I chose the front). I started getting a prototype down with a FlowLayout that looked terrible. All the controls were all over the place depending on the size of the window. At the end, I decided to use a BorderLayout. It does not look awesome. But at least the rows and columns line up nicely. That's because each part of the BorderLayout is a JPanel containing a GridLayout that does the dirty work.

Now I need to choose project number two. I figure I have all summer to relearn the Java skills I have deep down inside somewhere. I was even contemplating picking up a community college class to use to drive my Java coding. A friend mentioned such a class she is taking next semester. I checked the schedule of classes and found it only meet during the day. Us nine-to-five types cannot register for classes like that which interfere with the work day.

Object Oriented Programming

When I was setting up my game engine, and even when developing my game, I took the time to create a nice class hierarchy. It took a little extra time. I did not go overboard. There may have been 15 classes tops. And some of those were small subclasses.

During a final round of testing, I found some of the text was coming out wrong. That was disturbing as the text worked fine in some scenarios. I traced it back to find some code doing extra work to get the job done right. To fix the global problem, I moved that code to a base class. Then everyone got the fix. I did have to tweak a few instances where the specific code made some wrong assumptions. But I essentially fixed the problem in one location. Bonus.

As an aside, I find the Java Collections Framework very helpful in developing games. Now I cannot imagine how I lived without them. Oh yeah. I used arrays. Painful. Luckily there is no more of that pain in my projects.

JDialog to the Rescue

I had a requirement to display a list of choices in a window. Furthermore I wanted the dialog to be dismissed as soon as the user pressed a key. Turns out the JDialog was the class I needed. Mapped the keys of interest to a listener and I was good to go. But then I needed to handle the display of the dialog.

I must confess that I really did not have that much experience with JDialogs. Found out that it defaults to a BorderLayout. For my application, I needed more of a GridLayout. I surveyed a bunch of code on the web while searching for my solution. Learned that I could call the pack() method to size the dialog with the minimal amount of space required to fit the contents.

I had one hiccup where I wanted to map the keys with the JRootPane. Thought I needed to do that when I created the JRootPane in createRootPane(). Unfortunately that method gets called from the superclass. I could not pass it any data. That's okay. I found I could later call getRootPane() and handle my business.

All About the Keys

I wanted to provide an easy to use interface in my latest program. At times I put up a dialog where the user must choose a value. I want the user to be able to just press one key to make the choice. Initially I tried using the JOptionPane. But it required the user to press enter after making the choice.

I thought I needed to somehow specify an option (no pun intended) for the JOptionPane to just require a keypress. After a while, it felt like I was hacking to much to get this to work. I seemed to need to set some weird user interface options, then set up some maps, and I was still struggling to figure out which key got pressed.

Then I researched some mneumonics. Turns out those require you to press the Alt key along with the choice you make. No good. Finally I figured I needed some custom code. I forgot about the canned JOptionPane and started concentrating on a straight JDialog. Got an assist from the Java2s web site. A map plus a listener was all I needed. Now I am going back to the basics of drawing some user choices on the dialog. That should be a snap. I wish I knew to go straight to the JDialog in the first place. I been spending most of the day on this issue.

Anatomy of a Framework

I have known for a while that I was going to use Java to develop a game to enter this years 7DRL contest. The last time I tried using Java to compete in such a contest was disastrous. I did not know how to do any graphics. That puts a cramp in your game development abilities. This time I was going to be prepared for a strong showing. Therefore I started working on a gaming engine well in advance. You could call it a framework.

I figured I could just use a toy app to develop, mature, and test my framework. That worked out pretty well. I got some good code written and tested. The problem was that the framework became highly coupled with my sample application. Now that I am trying to make use of the framework for the real thing, I find myself ripping out the example code to get at just the engine.

Note to self: create an API that is truly separate from any demos. That way I will be ready for reuse. I guess I need to put that to the test early as well. I should have created a second sample app that tried to use the framework. The issues would have been clear from the beginning.

Acronym Hell

I just saw a massive blog post on developing a web app. Not only was the length of the blog post long, the list of related technologies was large. The post is going to hit JSF, CSS, EJB, DAO, JPA, JAAS, MVC, and MySQL. I have done a little bit of web application development. But I did not recognize all these terms. I guess you got to keep up.

So far I have only checked out the first piece of this blog post. I plan to go through the whole thing. This just seems like a lot to take in to do web programming. Then again this makes web developers more in demand if the skill list is huge.

The question I keep asking myself is whether I want to get into all this. The pain would be that the technologies would become obsolete or replaced just as soon as I master them. Such is life I guess.

Move to JavaScript

I have been sick for the last few weeks. So my Java roguelike game engine has been put on hold. That's okay. I shall enter a contest around March of this year to develop a game with the engine. I suspect I shall be doing a massive amount of Java coding that week. The engine will get some bug fixes and updates as a results.

The Spring school semester is just about to start up. I am taking an intro JavaScript course this time around. I plan to stop my Java learning for a few months to concentrate on the JavaScript. By summer I should be back in full swing with Java develoopment.