Calling Java Constructors with ColdFusion

I mentioned yesterday that Sam posted some great code that lets you upload files to ColdFusion without using CFFILE. His code can be shortened considerably with the use of the init() method:

fileAsString = “”;
fileReader = createObject(“java”, “”);
bufferedReader = createObject(“java”, “”);
try {
   do {
      fileAsString = bufferedReader.readLine();
   } while (true);
} catch (coldfusion.runtime.UndefinedVariableException e) {
// this indicates end of file, ok to ignore error

Basically, you use the CreateObject() function to get a Java object. At that point, you can call static methods on the object or you can use the init() method to call the constructor of the Java object, which I’ve done above, ie:

// get a FileReader object
fileReader = createObject(“java”, “”);
// call the FileReader object constructor

If you’re curious about this kind of stuff, you should check out the article on Java, ColdFusion MX and Lucene integration I wrote for the July issue of ColdFusion Developer’s Journal, due to hit the stands anytime now.

Uploading files with ColdFusion

Sam posted some CF code that gives you the ability to upload a file to a web server without using CFFILE (ie: he uses Java instead): Handling file uploads without CFFILE.

On a related note, Oreilly has an article (Using the Jakarta Commons) that (will) introduce(s) each component in the Jakarta Commons library. Probably would have been better to use the tried and tested FileUpload component from the Commons lib, but that would have required the jar file be present in ColdFusion’s classpath.

Built-in simple task manager

From the Handango newsletter in my inbox today:

Built-in simple task manager for Series 60 devices
Press and hold the Menu button located on the left side of the display. You will be presented with a list of all applications currently running in your system. You can quickly switch to any of the running tasks by selecting it and pressing the joystick. You can also close a task by selecting it and pressing “C”.

More Series 60 tips

Nokia Developers Suite for J2ME

I installed the Nokia Developers Suite for J2ME today and was able to get the Nokia Series 60 Emulator up and running a MIDlet I’ve been working on for the last couple weeks, which you can see at the right. The Series 60 SDK, still in beta (version .3 as I understand it) supports both Windows & Linux and can integrate with Borland JBuilder Mobile Edition, Sun ONE Studio and the Sun J2ME Wireless Toolkit, which I’m using.

I haven’t been able to hack with the Nokia UI package yet, but apparently it gives you the ability to control lighting and vibration from the package… Lots of MIDP 2.0 specific stuff, which doesn’t help me as I’m using the 3650 (which is stuck on MIDP 1.0). I don’t see anything about being able to control the camera (although I guess that’s specific to the phone and not Series 60). More later on the toolkit.

One of the difficulties with J2ME is that while a J2ME app will hypothetically run on almost any J2ME compatible device, not all devices map the same button to the same Command. For instance, as I’ve been working on this app, I’ll create 2 buttons. On the WTK Emulator, I’ll see the two buttons next to each other, when I deploy the same app to my phone via Bluetooth, I get a menu selection with 2 options. In the listening I’ve done on KVM-Interest, it looks like can do one of three things: a) develop your application for a specific phone, b) don’t worry about where the buttons show up on each device, or c) develop your own custom UI components, rather than using the MIDP 1.0 UI components. I need to download and use more MIDP apps to find out what the majority of people do, although I’d be interested in hearing what you have to say!

Hackers & Painters

Paul Graham wrote a fascinating essay based on lectures at Harvard and Northeastern. Couple things that resonated with me:

Big companies want to decrease the standard deviation of design outcomes because they want to avoid disasters. But when you damp oscillations, you lose the high points as well as the low. This is not a problem for big companies, because they don’t win by making great products. Big companies win by sucking less than other big companies.” — working at a company that writes software for other companies (read: I work as a consultant), I see this tendency alot. We’ll have ideas that we think could really be something, but end up getting shot down becuase you can’t stray to far from the beaten path for fear of sucking.

… a concept known to nearly all makers: the day job. This phrase began with musicians, who perform at night. More generally, it means that you have one kind of work you do for money, and another for love.” — how true!

and … “It seems surprising to me that any employer would be reluctant to let hackers work on open-source projects. At Viaweb, we would have been reluctant to hire anyone who didn’t. When we interviewed programmers, the main thing we cared about was what kind of software they wrote in their spare time. You can’t do anything really well unless you love it, and if you love to hack you’ll inevitably be working on projects of your own.

[via Tim Oreilly]

Modular Reconfigurable Robotics

Modular Reconfigurable Robotics, “… an approach to building robots for various complex tasks. Instead of designing a new and different mechanical robot for each task, you just build many copies of one simple module. The module can’t do much by itself, but when you connect many of them together you get a system that can do complicated things. In fact, a modular robot can even reconfigure itself — change its shape by moving its modules around — to meet the demands of different tasks or different working environments.” [via]