The Source for Java Technology Collaboration
User: Password:



Qusay H. Mahmoud's Blog

April 2007 Archives


Networking MIDlets and blocking operations

Posted by qmahmoud on April 18, 2007 at 12:41 PM | Permalink | Comments (0)

I get many email about the application featured in the article MIDP Database Programming with RMS. The application locks up the screen as the MIDlet tries to establish a wireless connection. This article was developed back in 2000 and back then everything worked perfectly. However, when developing networking MIDlets, pay special attention to blocking operations (e.g. methods that establish a connection to the network) which can lock up the screen, leaving the user frustrated with the application. To prevent this, all blocking operations should be performed in a separate thread. A more detailed explanation of this can be found in Preventing Screen Lockups of Blocking Operations in which I provide a detailed example of a network time MIDlet client.

To fix the problem in the Stock Quotes MIDlet from the MIDP Database Programming article, edit the QuotesMIDlet.java file, and:

  1. Create a new method as follows:
    public void makeConnection() {
       try {
          String userInput = input.getString();
          String pr = getQuote(userInput);
          db.addNewStock(pr);
          ticker.setString(tickerString());
       } catch(IOException e) {
       } catch(NumberFormatException nfe) {
       }
       mainMenu();
    }
    

  2. Replace the following piece of code:

    } else if (label.equals("Save")) {
       if(currentMenu.equals("Add")) {
          // add it to database
          try {
             String userInput = input.getString();
             String pr = getQuote(userInput);
             db.addNewStock(pr);
             ticker.setString(tickerString()); 
          } catch(IOException e) {
          } catch(NumberFormatException se) {
          }
          mainMenu();
       } 
    }
    

    with:

    } else if (label.equals("Save")) {
       if(currentMenu.equals("Add")) {
          Thread t = new Thread() {
             public void run() {
                makeConnection();
             }
          };
          t.start();
       }
    }
    

And this should solve the screen lockup problem. :-)

There will be lots of Java ME cool stuff at JavaOne this year. To get an idea of what's planned for then, take a look at Terrence Barr's Java ME Guide to JavaOne 2007. Q.



Java ME and BlackBerry wireless devices in the classroom

Posted by qmahmoud on April 17, 2007 at 10:07 AM | Permalink | Comments (3)

In Fall 2006, I have successfully integrated the use of Java ME and BlackBerry wireless devices into two programming courses at the University of Guelph-Humber in Toronto. The courses are Computer Programming I (a first semester course) and User-Centered Programming (a third semester course).

For each course, I had about two weeks of lectures (4-6 hrs) and two weeks (6-hrs) of labs. That was enough to get students started with Java ME:

  • Computer Programming I: Part of the final assignment was to develop a Java ME mortgage calculator for the BlackBerry
  • User-Centered Programming: The final assignment was to develop: (a) a quiz (marked on the fly) for the BlackBerry, and (2) another Java ME application that interacts with a Per CGI script for retrieving students marks based on their student ID#s.

Students in User-Centered Programming worked on a project to develop a system for linking doctors and pharmacists. Two groups were able to develop fancy clients for the BlackBerry for an extra 3.5% towards their final grades.

In summary, teaching computer programming in the context of simple mobile applications using Java ME provides a motivating and inspiring framework for students, and raises the level of excitement and satisfaction. I encourage everyone to integrate Java ME into their courses to introduce students to a programming model different than the desktop. In the desktop market, the application is deployed on a platform similar to the one on which it was developed, but in the Java ME space, the application is developed on a desktop platform and deployed on a totally different platform.

If you'd like to learn more about this experience, please see the poster and slides from my talks at ACM SIGCSE2007 and ACMSE2007 available at http://www.uoguelph.ca/~qmahmoud/javame. The full paper is available on the ACM Digital Library.

The system for linking doctors and pharmacists is based on a personal story. One evening I walked into a Wal-Mart pharmacy with a prescription for my wife, but the pharmacist wasn't able to decipher the doctor's writing and asked me to go back the next morning as he needs to call the doctor's office. Instead, I decided to go to a Shoppers Drug Mart pharmacy (they charge exorbitant dispensing fees!) and the pharmacist there wasn't able to decipher the doctor's writing either, but she asked me to tell her some of the symptoms that my wife is having and she'll try to guess the name of the medication. :-) So I did, and her reply was something like, well I know the medication prescribed but the dosage is too high so she still needs to call the doctor the next morning. Wouldn't be nice if there is an electronic system for linking doctors and pharmacists to securely manage prescriptions and other patients information? Q.

My very first blog

Posted by qmahmoud on April 16, 2007 at 09:46 AM | Permalink | Comments (5)

As my very first blog entry, I thought it would be appropriate to introduce myself. My name is Qusay H. Mahmoud. My first name is pronounced "Kosai", but everyone calls me "Q". Yes, there is a Q in Star Trek, and another Q in James Bond, but this Q is from Palestine. :-)

I have been working with Java ever since it was first released to the public. My first tutorial on "Sockets Programming with Java" was published on JavaWorld in 1996: http://www.javaworld.com/javaworld/jw-12-1996/jw-12-sockets.html.
A year later, my master's thesis system implementation "A Web-based Distributed Computing System" won the third place (Bomber Jacket) in the ACM/IBM Quest for Java 1997.

My first real-world Java application was a client-server system I developed in 1997 for the School of Computer Science at Carleton University in Ottawa, Canada. The system, which I believe is still in use today, automates the process of creating students accounts on a WindowsNT platform.

I started teaching Java in the classroom in 1998 at Etisalat College of Engineering in United Arab Emirates, and a year later I trained hundreds of Java developers at Nortel Networks in Ottawa. Along the way, I have published two Java books (Distributed Programming with Java and Learning Wireless Java), and many articles published on Sun Developer Network. I am interested in all Java technologies, but especially Java ME.

For more information about me and my work, please visit my homepage: http://www.cis.uoguelph.ca/~qmahmoud.

I enjoy going to JavaOne, and I look forward to meeting as many Java developers as possible this year. Q.





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds