Java


I wrote a program a little while ago that draws a Hilbert Curve. Really all I did was adapt the Java source code that’s on the Wikipedia page talking about the curve. That Java source used a class called SimpleGraphics that I’m not familiar with. I wanted to use SDL in C++ for my program. It was easy enough to convert the Java code to C++ but to do the drawing I decided to just implement a SimpleGraphics class in C++ that uses SDL to perform the actions that the program needs.

Since then I revived my interest in integrating scripting with C++ and pulled a Lua interpreter in to that project. Now my program loads a Lua script and executes it. The Lua script has access to the SimpleGraphics class that I wrote. Now that the script interpreter works and can call the drawing methods I decided to take the algorithm for drawing the Hilbert curve and implement that as a Lua script. It was actually pretty easy. The resulting source code works as a sort of Rosetta stone for the three languages.
Read the rest of “The Hilbert Curve in Java, Lua and C++”…

I took a little break today from the C++ and Lua stuff I’ve been doing to have a look at Google’s new phone platform. I followed the installation instructions and had some demos up and running pretty quickly. I also grabbed the source and poked around to see whose shoulders they stand on. I saw QEMU source, SDL source and they distribute the source for the Linux kernel that they’re running.

The installation instructions worked fine for me on my Linux box, running OpenSuse 10.3 and Eclipse 3.2 that I installed via Yast. I ran in to one hiccup, when I first installed the ADT Eclipse Plug-in the extra options for it didn’t show up in the Preferences Dialog where they should. I had to check a couple times to make sure that I had installed it correctly but it showed up where it should in Help -> Software Updates -> Manage Configuration.

I started looking at the other options for building projects then realized that I didn’t have an Ant view in my Eclipse. So I went looking for where that comes from and I decided I needed to install the JDT Plug-in via Yast. Most Eclipse users probably already have the Java Development Tools (JDT), I think it’s part of most installations, but I haven’t been using Eclipse on this machine yet. After that I had the Ant view and the Android plug-in showed all the options it should. I set the SDK location and was able to create Android projects just like the directions describe.

It’s easy to get excited looking at this SDK. I tried out a couple of samples in the emulator. The connection to Google Maps is pretty impressive. I also see configuration options for XMPP. I’ll have to see if I can talk to a Jabber server on my machine and do something interesting. Maybe I could try a little Java game, I’ve done some SDL. It’s hard to choose what direction to go in but I feel like it’d be a shame not to build something of my own with all this great code to start from.

Funny I mentioned just yesterday not to confuse Apache Foundation with the high-profile Apache HTTP Server Project. I say it’s funny because I started looking today at trying out Tomcat. Once I started surfing around the site, it occurred to me that I never had gotten to testing any of my SVG examples in Batik.

Batik, if you haven’t heard of it, is a toolkit for working with SVG in Java. So the funny part is that I kept skipping around the instructions trying to figure out what I would have to do in my httpd.conf to use this thing. While I’m sure there are lots of ways to use Batik on a server, and I still intend to, it works just fine with the JVM on any old home computer.

After I grabbed Batik 1.6, all I did with it was a simple test with the rasterizer demo application to render and slice up an SVG image, but Batik ran like a champ. It can’t crank out a PNG as fast as Adobe SVG Viewer can pop it up in a browser, but finally it’s a simple way to produce a high-quality raster image from an SVG. I’ve used ImageMagick and the Gimp for this now and then but they don’t handle SVG lighting filters at all.

SVG on the web is great, but you have to wait for end users to adopt it. With Batik, I can use SVG as a tool in the development chain for any project where I see it fit. I see this in the same way as I see XML in general being applied. There are plenty of sites out there (mine included) using XML and XML-derived languages being used out there behind the scenes. It doesn’t have to be delivered to the end user to be useful.

If you want to see how well Batik does then have a look at these demos - delivered via Java Web Start.

In which we wander around the various software stacks and find out what Rob knows and doesn’t about building web applications.

I recently moved this site (Late Night PC Service) and my travel journals (On Beaches) to a new server. I went from shared hosting to a virtual private server (VPS). So I now have a lot more horsepower at my disposal and I want to try some cool stuff.

One thing I’ve been on about recently is Eclipse and Java development. So I thought maybe I could look at developing with J2EE and what kinds of interesting things I can build. I have a lot of goals:

  • build a good framework for developing casual games
  • learn how to apply standards that I find interesting or intriguing
  • build interesting webstites
  • have some fun

This is the short list and I reserve the right to deviate whenever I feel like it.

Application development on the web can be done by hand on an as-needed ad hoc basis. That’s fine for experimenting and for building an application as a one-time event. For ongoing development and building applications that can be the foundation for the next big leap, you have to have a good set of tools. I’ve divined that this is what people are calling your application stack, your software stack, or maybe your superplatform.

If you were walking into the Web 2.0 Shopping Mall, you’d find the stores selling three major name brands of software stack. They are .Net, Java, and LAMP. I run a Linux server and only have any real experience with Apache servers (unless you count the old personal web server on Windows 98). That excludes me from the .Net product line, so I don’t find it very interesting or know very much about it. Here’s what I’ve surmised through my totally informal and accidental trip into the Web 2.0 Shopping Mall.

(this is gonna be a long one) Read the rest of “Of LAMP, Java and .Net”…

I was looking for a way to sort data in a JTable today and I very soon came upon this section in Sun’s docs. TableSorter.java is so easy to use that all I had to do was literally this:

  • press the new class button in Eclipse,
  • choose javax.swing.table.AbstractTableModel as the superclass (parent),
  • fill in TableSorter as the class name
  • click Finish
  • replace everything but the package statement at the top of the new java file with the contents of TableSorter.java

Voila. Took way longer to type this description than it did to actually do the work.
After that I changed the few lines of code as they describe. I ran it and tested it out, then I went back to figure out what I’d done. If you read the Sun documentation you’ll get a lot of what I did. I also had the GoF (Design Patterns: Elements of Reusable Object-Oriented Software) next to me though. So I looked up the Decorator Pattern.
To paraphrase (I don’t have it next to me now), the Decorator Pattern allows the developer to add functionality to a class without subclassing. Instead you write a sort of intermediary that exposes the same interface as the class you want to augment but with a couple extra features or methods.
Read the rest of “The Decorator Pattern and the JTable”…

That took way too long to figure out. Sometimes the information you need is right in front of you but you can’t recognize it. I just figured out that the TableModel and the TableColumnModel are next to each other in the Swing heirarchy. The way I was looking at it I thought they should overlap somehow.
Read the rest of “Fooling with a JTable”…

I’d forgotten how much I like Java. I’ve been playing with Eclipse lately, so this inevitably leads down the path to Java development. Really Eclipse is the Swiss Army Knife of Integrated Development Environments. It’s built with the same philosophy as Java. It’s built with that same mindset that permeates the Java community. I’d sum it up with a simple maxim: Why should I create an object of type X then do all that work of customizing that one object when I can customize a subclass of X? If you don’t know what I mean, I’m talking about the practice (and I think this is great) of subclassing, for example, JButton to make your own XyzButton. Then XyzButton has all the features you need in it. The other approach is to create a single instance of a JButton and do the specific work inside that object’s code.

Read the rest of “Tying it All Together”…