Skip to main content

Java developers sure do like making things from scratch

Posted by asj2006 on June 19, 2006 at 9:53 PM PDT

You'd think that after 10 years - an entire DECADE mind you - that Java developers would have a treasure trove of pre-built components that they could use to quickly cobble together their otherwise home-brewed apps.

Alas, perhaps there are just tons of examples of this in the bigger world of Java SE and JEE, but at least in the world of small Java, trying to code some of the simplest functionalities can cause some people who are stingy about buying books to go into a real google frenzy.

Take this MIDP app that I recently started coding as a side hobby. I needed to have the thing talking to Java servlets on the server, and I figure this'll be a cinch. As a Java developer, my first impulse was to simply use some code from a book, and admittedly, the code snippets to do POSTs that I found are pretty straightforward:

 try {
         hc=(HttpConnection)Connector.open (targetUrl,Connector.READ_WRITE);
         hc.setRequestMethod (HttpConnection.POST);
hc.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
c.setRequestProperty("Content-Language", "en-CA");

         dos=hc.openDataOutputStream();
         byte [] req_body=theData.getBytes();
         int size=req_body.length;

         for (int i=0;i < size;i++) {
                dos.writeByte (req_body[i]);
         }
        
         dos.flush();
        
         // receive response
         dis=new DataInputStream(hc.openInputStream());
   
         int ch;
         while ((ch=dis.read()) !=-1) {
                 b.append((char)ch);
         }             
    } finally {   
              if (hc !=null) hc.close();
              if (dis !=null) dis.close();
              if (dos !=null) dos.close();
      }



But then I have to worry about session management (where parsing requests and response headers becomes a fulltime job) and all the other tiny details that are needed to make it into a robust functioning unit (saving multiple sessions to the RMS for example), and I got to wondering why some good soul who had done this before hadn't simply packaged the entire functionality into a nice, shiny new component that I could plug into my Midlet suite and thence say et voila!

Given such a huge library of Java ME components, even relative newbies should be able to assemble together a functioning suite in no time flat. Imagine some newcomer to the world of Java who starts up Netbeans Mobility, uses the really cool Midlet Visual Mobile designer tool to quickly create the needed MIDP forms by dragging and dropping screen commands, list items, textfields and whatnot, then imports pre-built components into the Midlet suite, again by dragging and dropping instead of going to the source.

Sound good, right? I did my googly thing but the sites I found were sorely lacking in actual meat. So, if anybody knows of any places for Java ME developers to acquire basic components such as these, please feel free to tell me, and everyone else here. If there aren't any such places, perhaps I could add it to the To-Do list of the Java ME group that was set up for just such problems?



Related Topics >>