Sunday, September 30, 2007

Medical Marijuana Still Illegal?

Just read a story about Federal agents in California shutting down "a factory that made marijuana-laced barbecue sauce, chocolate-covered pretzels and other 'enhanced' snacks intended for medical users of the drug."

The article has one sentence that I found especially surprising. It reads "Federal authorities contend that marijuana is an illegal drug, no matter how it used or who uses it, and they don't honor the state laws."

I don't care much about pot but I am interested in government issues like state's rights and this statement didn't sound right. I did some searching and discovered that in 2005 the Supreme Court ruled in Gonzales v. Raich that the federal government can ban marijuana even in states where it is approved for medical purposes. So even though California "legalized" medical marijuana it is still illegal by federal law which supersedes state law.

The case and the rational for this decision was well described on its wikipedia article.

Thursday, September 27, 2007

Java ME Challenges

Over the last year I have transitioned from developing mostly desktop applications (Java SE) to mostly mobile applications (Java ME).

I describe here some of the unique aspects and challenges of Java ME development and some of the ways in which it differs from Java SE. I hope that it might be interesting to developers who are curious about Java ME.

I refer multiple times to MIDP 2.0 which is, at the time of this writing, the version of Java ME that is installed on most new phones.

  • Many phone manufacturers provide entire IDEs for Java ME development. These are usually custom versions of Eclipse or Netbeans that come bundled with emulators for their devices. The problem is that these IDEs don’t play well together. The IDE from manufacturer X will not work with the emulators from manufacturer Y. This of course makes it difficult to build & test apps across platforms.
  • To remain neutral I use the standard Eclipse IDE with the Eclipse ME plug-in. The Eclipse ME plug-in is a free project run by Craig Setera and it does a pretty good job interfacing with most of the vendor tools / emulators.

Limited Resources
  • The obvious difference between the desktop and the mobile is the limited resources available to the latter. A MIDP 2.0 device can have a screen size as small as 96x54 and may have as little as 128K of heap space. Many phones have a strict limit on application size (128K is common) and wont even allow you to install a jar file larger than it. Java ME developers use several techniques to minimize jar file size. Two common methods are:
    • Obfuscation
      • An obfuscator is a tool that analyzes your jar file, removes unused classes / methods and renames the remaining ones. A class called “HighScoreManager” for example might get renamed to “a” and its method “updateHighScore()” might get renamed to “b()”. Obfuscation is used in Java SE primarily to make it more difficult to decompile. It is used in Java ME primarily to reduce jar file size. They can do a surprisingly good job at both.
      • The obfuscator I use is Proguard.
    • C-like Code
      • Every class file has overhead so Java ME developers try to limit the number of classes they write. Unfortunately this encourages writing non-object-oriented C-like code. Most Java ME games today are implemented in just a few classes that contain thousands of lines of code.
  • One of the biggest challenges in mobile development is balancing good software design with small code size.

Limited APIs
  • The Java ME APIs are basically a very small subset of the Java SE APIs plus some phone specific stuff. This means that lots of useful classes and methods you have grown to love and depend on just aren’t available. As an example, MIDP 2.0 includes just 9 classes in the java.util package. If you want to use a StringTokenizer or TreeMap you will need to implement your own.

Java Fragmentation
  • The term “Write Once, Run Anywhere” isn’t used in Java ME circles for even the cheap joke.
    • Unfortunately the Java ME specs leave much up to interpretation. The look & feel of the UI widgets for example differ greatly across phones. One example is the MIDP 2.0 “Gauge” object. I've seen it rendered as a progress bar, an hour glass, and even as Duke (the Java mascot) waving at you! This inconsistency has led Java ME developers to ignore these widgets and implement their own from scratch.
    • Early versions of Java ME didn’t support things like accessing the phone book or controlling the camera. As a result each manufacturer began to introduce their own proprietary & incompatible libraries to support such features. Things have improved in this area with several industry-standard APIs (as JCP JSRs) but these remain optional and are only found in a subset of MIDP phones.
    • The Java ME runtime is different on every phone and each one has bugs. Since people generally don't update the firmware of their phones these bugs exist for the lifetime of the device. If one of these bugs affects your application you must either live with it, find a workaround, or drop support for the model.
  • These problems are so pervasive that solutions exist that enabled preprocessor support and the use of #ifdefs in Java code. I have thus far been able to avoid this path.

  • The way you install an application can differ greatly depending on the phone manufacturer, model, and even carrier.
    • The standard installation mechanism is called “over the air” (OTA). This is done by placing your application on a website and downloading it wirelessly (“over the air”) via the phone’s data network. This can be slow and depending on your data plan very expensive. Also if you are testing on multiple phones you will need service on each (or in the case of GSM models you will need to manually swap SIM cards which is tedious).
    • Some phones allow you to install applications over USB but the software and cables required vary greatly from phone to phone. I currently have at least 6 different desktop applications that can install apps on various phones and right now I have 5 different USB cords, all with different end connectors, plugged into my PC.
    • Some phones allow you to install over Bluetooth but this too can be slow and the Bluetooth drivers on the PC still have a habit of crashing.
  • Each time I want to test on a new phone I must first spend (waste?) time just figuring out how to install!

  • Debugging on mobiles can be extremely difficult. Only some phones allow you to see output from System.out and only some support “On Device Debugging”. (On Device Debugging allows you to run a debugger on a PC and debug, over USB or Bluetooth, an application running on a phone).
  • I have seen cases where an application runs perfectly on an emulator but crashes immediately on the real device. Try debugging that without System.out or a debugger!

  • On most phones many of the interesting APIs, e.g., phone book, camera, and Bluetooth are considered “protected” and their use requires that the application be signed.
  • Unfortunately getting your application signed can be an extremely difficult hurdle to pass (especially for small companies and hobbyists).
  • The signing process and the cost vary greatly across phones and carriers. Some carriers require that your first develop a “business relationship” with them. This can be as simple as paying a yearly fee or as complex as convincing them that your product is unique and worthy and then signing a revenue sharing deal with them.

Many of the challenges of mobile development are so very frustrating because they feel like old problems that we have already solved or outgrown years ago. Who today wants to deal with the problems of limited memory or spend time re-implementing a BufferedInputStream?

However annoying and frustrating it can be all of the challenges described are being solved quickly and mobile development is an area with lots of new interesting problems and enormous potential. It is becoming increasingly clear that we are entering a mobile development boom so the next few years in this industry should be an interesting and exciting time.

Tuesday, September 18, 2007

The Early Numbers Are In

Google has an amazing tool called Google Analytics which lets you monitor the traffic you get on your website. Click the above image to see how I'm doing so far. Good thing I don't have advertisers!

Monday, September 17, 2007

Einstein Biography

I recently finished reading the Albert Einstein biography by Walter Isaacson.

I really enjoyed this book and learned a ton about the most famous physicist of our time.

His character, personal life, politics, and religious thoughts were fascinating to read. The physics was interesting too but was difficult to follow at times. At around 600 pages though this book might not be for everyone.

To give you a taste, here are a few interesting things that I learned:

  • As a patent clerk in 1905 he published four papers that revolutionized physics. These included descriptions of special relativity and the equation E=mc^2. It was not until a four years later that he finally got his first job in academia as a junior professor at the University of Zurich.
  • He did not believe that man was naturally monogamous. He made this known and acted accordingly. He had many relationships while single and while married.
  • Einstein was a workaholic who struggled maintaining close personal relationships.
  • He had a daughter he never met.
  • His son Eduard suffered from schizophrenia and was institutionalized several times.
  • Einstein was an outspoken pacifist for most of his life (until WWII). He believed that the way to prevent war was to have a single world government. It would arbitrate disputes and enforce its decisions through a monopoly on military power.
  • He was a determinist. He believed that the actions of all objects are determined only by the laws of nature. If we could understand these laws and could know the current state of all objects then we could exactly predict the past and future states of all objects. This includes the actions of human beings! He believed that human beings have as much free will to determine their own actions as a star sitting in the sky does.
  • In 1938 Freshman at Princeton University, where Einstein was working, were given a survey which asked them to name the "greatest living person". Einstein (a Jew) ranked second behind Adolf Hitler.
  • At the urging of his colleagues Einstein wrote a letter to President Roosevelt warning that the Germans could be developing technology for a bomb of unprecedented power. This letter led to the development of the Manhattan Project, the atomic bomb, and the bombing of Hiroshima and Nagasaki. After the bombings Time magazine put an image of Einstein on the cover with a mushroom cloud and the equation E=mc^2. This is somewhat ironic due to Einstein's pacifist beliefs.
  • Einstein worked until the night he died. The final thing he wrote before going to sleep for the last time was a set of incomprehensible equations.
  • The pathologist who performed Einstein's autopsy was a Quaker named Thomas Harvey. Without asking for permission Thomas decided to keep Einstein's brain for himself! He embalmed it and stored it in two cookie jars. For years after he would occasionally send pieces to researchers for study.

Sunday, September 16, 2007

Use a Feed Reader

Everyone who browses the web should also be using a feed reader yet most people have not yet even heard of the term!

I can’t help but feel that these people are missing out and I should know since until last year I was one of them.

A feed reader is a software program that is as useful and important as your email client or your web browser.

Here is how many of them generally work:

  1. It looks and feels a lot like an email program (but you will only receive messages).
  2. In it you subscribe to various websites (feeds) that you enjoy reading.
  3. When the site (feed) is updated with new content (a new article for example) it will show up in your inbox as a new unread item.
  4. You click on the item, view it, and mark it as read. Often times you never even need to visit the site.

It is very simple but amazingly useful. Say goodbye to checking and rechecking your favorite sites for updates. Any new content just magically appears in your inbox.

This makes it possible to read far more sites in far less time. I used to read about five web sites on a daily basis but now that number is well over 100! I'm much more informed and entertained as a result.

The feed reader I use and highly recommend is Google Reader but others exist too.

Click on the screenshot above to see Google Reader in action.

Saturday, September 15, 2007

Technical Vs General Posts

By trade I’m a Software Engineer so much of what I find interesting will simply be unreadable or deathly boring to my non-technical friends!

To help with this I will label each post as either general or technical.

In this way you can easily view only the types of posts you want to:


My name is Mike, I live in Boston, Massachusetts, and this is my new site.


I’m not entirely sure how I’m going to use this or even for how long but time will tell. Mostly I think I’ll be linking to news articles or websites that I find interesting. On occasion I may also post original material like random thoughts, personal stories, or book reviews.

Hopefully you will find some percentage of my posts interesting also.

Hello World

According to Wikipedia, as of August 2007, there were over 94 millions blogs out there.

We can officially add one more to the list.

Hello World!!!