J2ME/JavaME Visited Again

It seems like an eternity since I last tried J2ME or JavaME as its known now. It was Sept 2003, when I was working at a product development company and was building a component using J2ME. I even managed to get an article published at http://my.advisor.com/articles.nsf/aid/12697.

When I tinkered with Android a few weeks back, I got the urge right then to revisit JavaME. I wanted to try out a JavaME example again and see if anything has changed. I still believe that JavaME will eventually die out in favor of a more full featured platform (whether it is Java SDK or something else I dunno). For a primer on JavaME stacks you can check my article on advisor above. It surprising how little has changed.

In this example I will build a JavaME application using Netbeans. The application will present the user with a screen to enter a ISBN number for a book. It will then make a remote web service call to validate that the ISBN number is valid or not. When I tried a similar webservice example in 2003, web services was not yet in the optional stack. Now it is. Previously I was using ksoap. Now I do not need to. I can use the built-in libraries (if the device supports that… and that is the big headache with either JavaME or Android….device capabilities).

Create a new NetBeans MIDP project named as ISBNValidator, using CLDC-1.1 and MIDP-2.1 configuration. The IDE will create a ISBNValidatorMidlet. Netbeans will throw you into a page flow designer. I switched to the source code view.  Change the code to:

In the method validateISBN you can see I do the web service call. Now you must be guessing how I got the stubs created. Netbeans has made that easy for us. Right click on the project and select “New JavaME Web Service Client”. Provide the WSDL URL webservices.daehosting.com/services/isbnservice.wso?WSDL and you are done.

For sake of completeness here are the other 2 classes I coded. I put the forms in two independent classes.

Class EnterISBNNumberForm

Class ISBNValidatorResultForm

If you run the project an emulator should pop up and you can launch the application. Following two images show the application in action: