Skip navigation
ANNOUNCEMENT: community.oracle.com is currently Read only due to planned upgrade until 29-Sep-2020 9:30 AM Pacific Time. Any changes made during Read only mode will be lost and will need to be re-entered when the application is back read/write.

http://weblogs.java.net/blog/cayhorstmann/archive/cinequest.png

One of the best aspects of my job as computer science professor is that I keep learning new stuff. This semester, I am teaching a software engineering class. Cinequest, the organization that puts on the annual San Jose film festival, approached the CS department, asking for help with their mobile initiative. We jumped at the chance, and now my students are hard at work designing and prototyping a BlackBerry application for festival attendees.

Our job is to put the festival catalog into the palms of the moviegoers so they don't have to browse the paper version, which is not only uncool but may also be out of date. Why the BlackBerry when everyone (except for McCain's staffers) knows that the iPhone is the cool device to support? Well, the BlackBerry is an open system, and you don't have to deal with Apple which has rather rigid ideas who gets to be a developer and who gets to put apps on the device. Also, fortunately for me, the BlackBerry runs Java. I want to learn new stuff, but not that much new stuff :-)

It is the perfect project for a software engineering class. We have a real customer and a real deadline, but the scope is reasonably constrained so that is feasible. And there is great resume value for the students and PR for the university. Now what we really need is some BlackBerry donations for the students, preferably with some air time tossed in. If anyone has useful contacts, please let me know!

As it turns out, BlackBerry programming isn't quite the same as Java ME. While Java ME apps will run on a BlackBerry, they don't have the same look, so we decided to go with the BlackBerry API.

That is easier said than done. We groaned when we found out that the development tools only run on Windows. (Somewhat to my surprise and delight, half of the students prefer Linux as a development platform.) I feel transported into a different world, where archives are distributed as .EXE files and development done in a (rather poor) custom IDE rather than Ant scripts and Eclipse/NetBeans plugins.

Fortunately, there is an Ant task that works on Linux. (It is pretty sad that one needs to hack one of the tools that has hardwired backslashes, but a good lesson for my students who will hopefully never do such an embarrassing thing themselves.) The only thing that doesn't work is the simulator. Some lucky people can run it in Wine, but not me. If you are among the unlucky, here is how you can get it to run in VirtualBox.

  • Install VirtualBox for Linux, using all the default settings. Except, crank up memory. (768K seems to work for me.)
  • Start VirtualBox. In the Devices menu, mount the CD ROM. Install Windows XP. (If you are a student, chances are that your department or student club has an agreement with Microsoft where you get an install disk for free.) During the install, enjoy the rather humorous messages on how great XP is going to be.
  • In the Devices menu, mount the ISO image/usr/share/virtualbox/VBoxGuestAdditions.iso. Run the installer in Windows.
  • Start Internet Explorer. Download and install JDE4.6.0 from BlackBerry. Launch the device simulator. (You need notinstall Java.) The simulator takes a long time when it is launched for the first time. Afterwards, it is quite a bit better.
  • In the VirtualBox Devices →Shared Foldersmenu, share a directory from the Linux host with Windows, e.g./home/cay/shared.) In Windows Explorer (and in file dialogs), you can find that directory as My Network Places → Entire Network → VirtualBox Shared Folders. (This does not work in the My Network Places icon on the desktop.)
  • Write your BlackBerry app on Linux, build with Ant, move the .COD file to the shared folder, and select File → Load Java Program in the simulator. With the 9000 simulator, the app shows up in Downloads.

http://weblogs.java.net/blog/cayhorstmann/archive/bb-simulator-in-vb.png

First I didn't understand why the simulator wasn't just written in Java. But it is able to simulate Bluetooth, so it may be some amount of work to get it to work cross-platform. Looking into my crystal ball, I would think that going forward, it will be increasingly hard to ignore Linux and Mac OS X in the developer marketplace. Maybe one solution is to treat Wine as another flavor of Windows on which your software must work.

If any BlackBerry hacker reads this, I'd be grateful for a tip on how I can render the tabs on the top so that they don't get cut off. Buttons don't seem to be the right thing, but I couldn't find any tabbed pane in the API.

Finally, here is a cool article by fellow Java Champion Qusay Mahmoud, who uses BlackBerry devices in his CS1 course at the University of Guelph in Canada. (He teaches straight Java ME.)

When I traveled to the U.S. as a nerdy teenager, I was fascinated by those laminated reference cards. It seemed yet another example of boundless American optimism that one can cram an entire semester's worth of information into two pages.

chemistry-refcard.jpg

When Jill Tomich from dzone approached me to do a digital version of such a reference card for JavaServer Faces, I remembered that and agreed. Jill did a great job cramming all the tables from David Geary's and my book "Core JavaServer Faces" into a free 6 page refcard. Get it here: http://refcardz.dzone.com/refcardz/javaserver-faces. View as PDF or print it out. Sorry, no plastic laminate.

http://refcardz.dzone.com/sites/all/files/refcardz/covers/4917.png

Being a Linux user, I watched those applet dragging demos with envy when they only worked on Windows. When the release candidate of JDK 6 update 10 (now there is a product name only a mother could love...) came out, I was eager to try it out on Linux. Initially, I was held back by a factor entirely beyond my control, i.e. my cluelessness and unwillingness to read the docs. Thanks to Aaron Houston and Ken Russell for helping me out. Here are the steps:

  1. First off, you need to make sure that the new functionality is actually enabled. The Linux installer for JDK 6 update 10 doesn't do that for you. You must remove the symlink to the old plugin from your plugins directory (such as~/.mozilla/plugins) and add a symlink to/path/to/jdk1.6.0/jre/lib/i386/libnpjp2.soFor example, 
    ln -s ~/jdk1.6.0/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins/libnpjp2.so
    
    This is explained here.
  2. The applet drag gesture is Alt + click, which unfortunately conflicts with the Gnome gesture to drag a window. As explained here, you can write code in your applet to have a different drag gesture, but that seems daft—how are you supposed to know what goes on with the window manager of the person viewing your applet? Maybe Sun could have done a better job here and identify suitable gestures for each platform? At this point, the easiest way around the problem is to reconfigure Gnome. Select System → Preferences → Window, then pick some other key than Alt for window dragging:
    Screenshot-Window Preferences.png
  3. Finally, keep in mind that this doesn't work automatically for all applets. You need to go to the applet code and add a parameter
    <param name="draggable" value="true">
    
    Try it out: Point your browser hereand use Alt+Drag to move the applet anywhere you like:
    Screenshot-Draggable-Applet.png

This semester, I am teaching the undergraduate programming languages course at SJSU, a required course for CS majors. The course has two objectives:

  • To give students significant exposure to a programming paradigm other than OO
  • To make students understand the process of translating a high-level language into machine (or VM) code

The canonical way to meet these objectives is to teach Scheme, and to build simple interpreters and compilers. It is not the most popular course. Most of our students just don't think Scheme is all that cool. When I want them to admire the elegance of closures and continuations, they are still hung up over parentheses andlet.

http://weblogs.java.net/blog/cayhorstmann/archive/scala_logo.pngThis semester, I am trying something new. I am using Scala as my functional language. The syntax is accessible to the students (they all know Java), and they see Scala mentioned on dzone.com, so it isn't just something of interest to a bunch of pointy-headed professors.

In the first few weeks, I am restricting myself to the functional subset of the language:

  • val, not var
  • No while, just recursion
  • Immutable lists, just with head,tail, and ::
  • The higher-order functions in the List class:map, filter, /:, etc.

I can do exactly the same as in Scheme, except without the parentheses. Does it work? I had a few lectures, and here are my initial observations.

  • The Scala interpreter is great. Students enjoy the immediate feedback.
  • http://weblogs.java.net/blog/cayhorstmann/archive/disgust.jpgStudents need to install the JDK and Scala on their laptops. The worst part was setting up Java on Windows. If the installer must put the JDK intoProgram Files, couldn't it at least add thebin directory to the PATH? It requires superhuman effort to get the less talented students to edit the system configuration or to deal with spaces in file names in the command shell.
  • The DOS shell still sucks eggs, just as it has ever since I first saw it in Windows 3.0. The better students run Linux, Mac OS, or Cygwin with rxvt. Microsoft sends a powerful signal to budding computer scientists. That signal is: "We don't give a !@#$ about you!".
  • The biggest hangup so far has been the strong typing, somewhat to my surprise. x : Int instead of int x, but one quickly gets used to that. However, typing append(lst : List[Any], a : Any) : List[Any] into an interpreter window is no great joy. I expect this will get better when we move to Eclipse, where the IDE can take advantage of the strong typing.

http://weblogs.java.net/blog/cayhorstmann/archive/lab.jpgInterested in following along? Click on the links of this schedule. There are lab assignments in each lecture. If you need a hint with one of the labs, leave a blog comment.

In this blog I reflect on what I learned during my summer vacation, about standards, folding travel beds, and snatching defeat from the jaws of victory.

1. It's About Standards, Stupid

http://weblogs.java.net/blog/cayhorstmann/archive/sim-card.jpgI spent the summer in Switzerland (as a guest lecturer in the international summer school at HEIG-VD) and in Germany. In Switzerland, the visiting students were very cell-phone savvy--they picked up a SIM card at the airport and phoned away instantly. (One of my colleagues asked how he could put a SIM card into his Verizon phone. They looked at him as if he was half-witted and patiently explained that nobody signs up with Verizon or Sprint because then you can't use your phone when you travel.) Mercifully, I had considered this point and came prepared with an unlocked GSM phone.

But what to do in Germany? I crossed by train, and there was no airport kiosk for picking up a German SIM card. No problem, it turned out. I got it in the supermarket: 5 Euro for a card with 5 Euro worth of calls. To refill it, go to the supermarket and buy a refill code, then tap that into the cell phone. (This seems a recent development. My German uncle asked incredulously: "You didn't have to show your identity card?") Other carriers had different schemes, with refill vending machines or internet refills. Amazing. No contract. No two-year commitment. The cost of calling: 9 cents per minute. It is nirvana compared to the hassle that I have with U.S. carriers. (Case in point: I am currently locked in an epic battle with T-Mobile which advertises a family plan with 5 members, when their computer system only takes 3.)

What makes all this innovation possible? A common standard, in this case, GSM. The various carriers build services on top of the common standard, and they compete against each other on their merits. Contrast that with the situation in the U.S. where we have incompatible networks, locked phones, and plans that hold you hostage for years.

It is experiences such as this one that makes me wary of closed operating systems and programming platforms.

2. Rocket Science

http://weblogs.java.net/blog/cayhorstmann/archive/travel-bed.jpgWe traveled with our 20-month old twins--a proven strategy against jet lag. I learned never to be smug again about an elegant or intricate algorithm. We computer scientists may think that red-black trees are pretty clever, but they aren't anywhere near as impressive as those folding infant travel beds. I have folded and unfolded them dozens of times, and I still don't understand how all these metal bars swing into place and collapse into a tiny bundle. How someone can design such a thing is beyond my ability to comprehend.

3. With Apple's Help, I Snatched Defeat from the Jaws of Victory

My Thinkpad broke on the day of my return--a flickering display. No problem, I have an on-site repair contract. Except, after the fellow fixed it, it was worse. Now the display no longer flickers. It is simply black. He'll come back tomorrow, and if he still can't fix it, I'll have to send it in, thereby negating the benefit of on-site repair. I had to do something for today's lecture, so I went to the university bookstore and snapped up a MacBook. Oh, said the clerk, you get a free iPod. And a free printer. How nice.

One of the pleasant aspects of Apple is always how prettily their stuff is packaged. Shiny cardboard, tastefully designed foam packaging, just generally a great out-of-box experience (OOBE). The lecture was in a mere thirty minutes, but no problem. I was on the network in no time, installed Aquamacs and Scala, and ... realized that I had no way of projecting my lecture. The MacBook doesn't have a VGA connector. No problem--DVI is the way to go in this millennium, and of course I have a DVI to VGA converter.

http://weblogs.java.net/blog/cayhorstmann/archive/mini-dvi.jpgBut the MacBook doesn't have a DVI connector either. Instead, it has some bizarre Apple-proprietary Mini DVI connector, and Apple is too cheap to include a converter with the computer. The bookstore was out of converters, and I had to admit defeat. Hello, Apple, if you put a non-standard connector on your machine, and you want people to have a great OOBE, put a converter into the box. It's about standards, stupid.