tag:blogger.com,1999:blog-52097781086925856602008-05-08T03:16:09.304+05:30The Java ME BlogAnoop Engineernoreply@blogger.comBlogger46125tag:blogger.com,1999:blog-5209778108692585660.post-30738852794457308622007-12-13T22:52:00.000+05:302007-12-13T23:03:17.281+05:30Java ME: An Introduction [Presentation]<div style="width:425px;text-align:left" id="__ss_201439"><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=java-me-an-introduction-wwwjavameblogcom-1197507282658934-3"/><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=java-me-an-introduction-wwwjavameblogcom-1197507282658934-3" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object><div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;"><a href="http://www.slideshare.net/?src=embed"><img src="http://static.slideshare.net/swf/logo_embd.png" style="border:0px none;margin-bottom:-5px" alt="SlideShare"/></a> </div></div><br /><br />This is a presentation that I made to explain the Java ME technology to some management guys. As you can see, it doesn't contain Java ME explained in detail, but is just a basic introduction to anyone new to the field. Please comment your opinion.Anoop Engineernoreply@blogger.comtag:blogger.com,1999:blog-5209778108692585660.post-6887939959291301782007-12-13T21:43:00.000+05:302007-12-13T21:55:52.168+05:30How to get the IP Address of a mobile using Java ME?<img style="float:left; margin:0 10px 10px 0;" src="http://bp3.blogger.com/_B0CuCDv4i18/R2FbOnLqc5I/AAAAAAAAAII/LpPnsoeZ-sU/s320/sweethome.jpg" border="0" alt="IP Address of mobile phone using Java ME/ J2ME"id="BLOGGER_PHOTO_ID_5143492556028015506" /><br /><br /><span class="dropcaps">T</span>here are many situations where you may want to know your phone's IP Address. You know that your mobile connects over GPRS which in turn is based on Internet Protocol, so you are pretty confident that the phone has an IP Address.<br />Well then, there is a good news and a bad news for you. The good news is that your phone do have an IP Address. The bad news is that this IP address will be hardly usefull for you. Why? read on.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp1.blogger.com/_B0CuCDv4i18/R2FcqHLqc8I/AAAAAAAAAIc/YOUIU2nhwII/s1600-h/JavaME-NAT.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://bp1.blogger.com/_B0CuCDv4i18/R2FcqHLqc8I/AAAAAAAAAIc/YOUIU2nhwII/s400/JavaME-NAT.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5143494127986045890" /></a><br /><br />The above image shows the network layout of most mobile based IP connection. Your mobile handset will be connected to the service provider's NAT gateway. The IP that your mobile handset get is a private IP, means that this IP can't be reached from external world.<br /><br />There are ways to get both your private IP and the IP Address of the NAT gateway.<br /><br />Getting your IP Address<br />1)The following snippet will give you your private IP Address.<br /><div class="important"><br />ServerSocketConnection scn = (ServerSocketConnection)Connector.open("socket://:1234");<br />System.out.println(scn.getLocalAddress());<br /></div><br /><br />Note: This method may return your IP Address as 127.0.0.1 (the loopback address) if the GPRS link has been idle. So always send some data over the connection before testing this.<br /><br />2)Using the System properties<br /><div class="important"><br />System.getProperty("microedition.hostname");<br /></div><br />This is supposed to give you the IP Address. But for me this returns 127.0.0.1 always. If you had any success with this, please share in the comments.<br /><br />3)This is a bit round about method, but is the most guarenteed to work one. If you are trying to connect to your custom server, have the server tell your ip to you. Implement a handshake protocol, where you say "Hello server" and the server replies "Hello client. Your IP is xx.xx.xx.xx". <br /><br />Getting the IPAddress of the NAT gateway<br /><br />Service like http://whatismyipaddress.com/ or http://www.lawrencegoetz.com/programs/ipinfo/ or http://www.whatismyip.com/ gives the IP Address it sees when you browse their pages. This will be your NAT IP Address. Just parse the page and get the IP.<br /><br />Remember all these works only if you are using GPRS/Wifi. If you want to know the IP address it need to be a IP based network.<br />If all you want is a unique number to identify your mobile, read this post on using IMEI number<br /><br />Post your success stories and failure in the comments. Let me know how much this post helped you.Anoop Engineernoreply@blogger.comtag:blogger.com,1999:blog-5209778108692585660.post-23986498883788102422007-11-06T17:09:00.000+05:302007-11-06T17:33:15.153+05:30How to create serial numbers unique to a mobile. (Using IMEI number)<span class="dropcaps">G</span>ames and most applications in the Windows world come with a<br />trial period, during which you can test the application. If you find the<br />application to your taste, you can purchase the full application, which is<br />usually a simple serial key to unlock the application.<br /><br />There have been several attempts to adapt such a method to<br />the mobile programming world. However, it’s not easy to generate a foolproof<br />method as the computing power required to generate a strong hash (read as<br />serial number) or to verify it, is limited in a mobile device.<span id="fullpost"> The major<br />difficulty lies in generating a number, which is unique to a mobile.<br /><br />But Hey, we don’t want to *create* a new number. We already<br />have a unique number for every device, which is the IMEI number. Why not use<br />that?<br /><br />The only difficulty is that Java ME doesn’t expose any<br />standard API to get the IMEI number of the device. However, most manufactures allow<br />us to get the IMEI number using the System.getProperty() method. Here is a HowTo:<br /><br /><strong>Nokia</strong><br><br />System.getProperty("phone.imei");<br />System.getProperty("com.nokia.IMEI");<br /><br /><br /><strong>Sony-Ericsson</strong><br><br />System.getProperty("com.sonyericsson.imei");<br /><br /><strong>Samsung</strong><br><br />System.getProperty("com.samsung.imei");<br /><br /><strong>Siemens</strong><br><br />System.getProperty("com.siemens.imei");<br /><br />thanks: <a href="http://mobilepit.com/10/how-to-get-imei-number-in-j2me-javame.html">mypapit</a><br /></span>Anoop Engineernoreply@blogger.comtag:blogger.com,1999:blog-5209778108692585660.post-25160250833085313942007-08-31T11:25:00.000+05:302007-08-31T15:27:02.682+05:30Java ME Advanced Tutorial: GUI Programming Part 1<span class="dropcaps">S</span><br />o you are determined in becoming an 31337 Java ME guru, as is evident that you have begun reading the "Java ME Advanced Tutorial" series. If you haven't read the "<a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-introduction.html">Java ME Beginner's Tutorial</a>" series, now would be a good time to <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-introduction.html"> skim through it</a>. By the time you start the advanced tutorials, you should be well versed with <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-wtk.html">using Wireless Tool Kit</a>, <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-java-me.html">Java ME Basics</a>, <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-writing.html">writing code and building it</a> and <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-packaging.html">packaging</a> it. Now we are going into advanced areas of Java ME technology. Let's begin with GUI programming.<br /><span id="fullpost"><br /><h3>Little Background Info</h3><br />The first version of Java released outside Sun was Java 1.0.2. This initial version itself contained <a href="http://java.sun.com/products/jdk/awt/">AWT</a>(Abstract Windowing Toolkit), which was a means to develop Graphical User Interface (GUI) applications. Later came <a href="http://java.sun.com/docs/books/tutorial/ui/overview/intro.html">Swing</a>, which was a better AWT than AWT.<br /><br />Java ME do not use AWT or Swing. Instead it defines its own GUI classes which are part of the MIDP api. Reason for not using AWT or Swing are:<br /><ul><br /><li>AWT and Swing are designed with desktop computers in mind. They are windowing elements for a screen with a higher resolution and capabilities than a mobile phone's screen.<br /><li>AWT and Swing are supposed to work with a pointing device such as a mouse. Most mobile phones however do not have such a pointing device.<br /><li>Most of the features that the AWT and Swing supports, such as the Window Mangement and overlapping windows, are impractical and impossible on a mobile device.<br /><li>AWT and Swing creates event objects during runtime for each GUI event such as mouse-move and button-click. These objects exists only till the event is processed and is later freed during garbage collection. However, the limited processing power and memory of mobile device cannot handle such a heavy process.<br /></ul><br /><span class="pullquote"><br />Classes for GUI programming are defined within the MIDP APIs.<br /></span><br />Due to these reasons MIDP decided to have its own set of GUI APIs. These APIs are classified as <span style="font-weight:bold;">high level</span> and <span style="font-weight:bold;">low level</span> APIs. Both the high level and low level APIs come in the <span style="font-weight:bold;">javax.microedition.lcdui</span> package.<br /><br />Anything that can be displayed is represented by the <span style="font-style:italic;">Diplayable</span> class. The <span style="font-style:italic;">Screen </span>class is a sub-class of the Displayable class and represent screens that occupy the full screen area. There are three types of screens:<br /><ol><br /><li>Screens that have a predefined structure and is indented for a specific purpose. You cannot add any other components to these screens. eg: List, TextBox etc.<br /><li>General purpose screens made using the Form component. You can add other components to this Form creating custom screens of your desire.<br /><li>Screens created using low-level APIs; as a subclass of Canvas, GameCanvas etc. If you are interested in mobile game programming, this is the stuff you need to learn more thoroughly.<br /></ol><br /><br />The first step in GUI programming is to get the <span style="font-style:italic;">display</span> object. Yes, as you might have guessed, the display object represent the display of the mobile device. The general routine in GUI programming is:<br /><ol><br /><li><span style="font-weight:bold;">Get the display object:</span> There is a class named <span style="font-style:italic;">Display </span>in the javax.microedition.lcdui package. We use a static method named getDisplay() to get the display object.<br /><blockquote>public static Display getDisplay(Midlet midlet);</blockquote><br /><div class="important"><br /><span style="font-weight:bold;">Things to remember:</span><br /><br /><ul><br /><li>A MIDlet can have only one instance of display object.<br /><li>Display.getDisplay() can be called multiple times;however, all calls will return the reference to the same object.<br /><li>Do NOT call getDisplay() in the MIDlet's constructor, as the display might not be initialized then.<br /><li>A better approach would be to call it in startApp() method.<br /><br /></ul><br /></div><br /><li><span style="font-weight:bold;">Create a screen object:</span> The different types of the screen objects and their behavior will come later in this tutorial series.<br /><br /><li><span style="font-weight:bold;"> Show the <span style="font-style:italic;">screen</span> on the <span style="font-style:italic;">display</span>:</span>For this we use the setCurrent() method of the Display class.<br /><blockquote><br />public void setCurrent(Displayable nextDisplayable);<br />public void setCurrent(Alert alert, Displayable nextDisplayable);<br /></blockquote><br /></ol><br /><br /><h3>Display class - In detail</h3><br />We have already seen some of the methods in the Display class: getDisplay() and setCurrent(). Some other most useful methods are discussed here:<br /><ul><br /><li><span style="font-weight:bold;">getCurrent():</span> <br /><blockquote>public Displayable getCurrent()</blockquote><br />This returns the Displayable object that is currently being displayed on the screen. If you call this before setting a screen using setCurrent, it will return NULL. <br />If the screen is hidden by a system screen(such as a low battery Alert screen), still getCurrent() will return the Displayable that was last set using setCurrent().<br /><br /><li><span style="font-weight:bold;">isColor():</span><br /><blockquote>public boolean isColor()</blockquote><br />This returns true, if the phone is a color phone. Else, this returns false.<br /><br /><li><span style="font-weight:bold;">numColors():</span><br /><blockquote>public int numColors()</blockquote><br />This returns the number of colors if the phone is a color phone. Otherwise, it returns the number of gray levels supported.<br /><br /><li><span style="font-weight:bold;">setCurrentItem():</span><br /><blockquote>public void setCurrentItem(Item item)</blockquote><br />This is a very useful method when you are using forms. Suppose you have a form with two TextEntries - Name and Password, and you wish that the cursor be in the Name field when the form is displayed. All you have to do is : d.setCurrentItem(name);<br /><br /><li><span style="font-weight:bold;">vibrate():</span><br /><blockquote>public boolean vibrate(int duration)</blockquote><br />This method can be used to enable and disable the vibrator of a phone. If the phone doesn't support vibration or if your display is not in the foreground then this call returns false. Otherwise it returns true. This method returns immediately and is not a blocking call. It accepts the time in milliseconds for which the vibrator should be active. However, the implementation can limit or override this duration. If this parameter is zero, vibrator is stopped.<br /><br /><li><span style="font-weight:bold;">flashBacklight():</span><br /><blockquote>public boolean flashBacklight(int duration)</blockquote><br />This is very much similar to the vibrate() call. It is used to turn on and off the devices' flashlight repeatedly for the duration specified in the parameter. If the parameter is zero the light is turned off immediately. This method is non blocking and returns false if the display is not in the foreground or if the back light cannot be controlled by application. Else it returns true.<br /></ul><br />In the next section, we begin with the high level api.<br /><div style="float:right;"><br /><a href="xxxxxxxx">Next: TOFOTOTO >></a><br /></div><br /><span style="float:left;"><a href="http://javameblog.blogspot.com/2007/08/java-me-advanced-tutorial-table-of.html"><< Java ME Advanced Tutorial: Table Of Contents</a><br /><br /></span>Anoop Engineernoreply@blogger.comtag:blogger.com,1999:blog-5209778108692585660.post-41500827812693486132007-08-31T11:21:00.000+05:302007-08-31T15:24:32.556+05:30Java ME Advanced Tutorial: Table Of Contents<a href="http://javameblog.blogspot.com/2007/08/java-me-advanced-tutorial-gui.html">Chapter 1 : GUI Programming Part 1</a><br/>Anoop Engineernoreply@blogger.comtag:blogger.com,1999:blog-5209778108692585660.post-34251884903334798502007-08-30T14:24:00.000+05:302007-08-30T17:20:13.424+05:30Java ME Beginners Tutorial : Packaging<span class="dropcaps">W</span><br />elcome to the sixth chapter of the "Java ME Beginners Tutorial" series.<br /><br />Success of any software application largely depends on the ease of its installation. There should be a standard way of packaging your application; a form which is easy to send over a network, and one which is easy to install. In Windows there is the .msi packages (setup.exe?) and in Linux we have the RPMs and DEBs.<br /><br />In the Java ME arena, the packages are called "MIDlet Suites".<br /><span id="fullpost"><br />Midlet Suites can contain more than one MIDlets. A MIDlet Suite is not a single file, but a group of two files: JAD file and a JAR file.<br /><br /><h3>JAD File</h3><br />JAD stands for "Java Application Descriptor" and is a simple text file. If you have <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-installation.html">installed WTK</a> and followed the <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-writing.html">exercise in our last chapter</a>, you will find a JAD file in your [INSTALLDIR]\apps\JavaMEBlog\bin directory. Open JavaMEBlog.jad using Notepad and you can see the following contents:<br /><blockquote>MIDlet-1: JavaMEBlog, JavaMEBlog.png, HelloMIDlet<br />MIDlet-Jar-Size: 887<br />MIDlet-Jar-URL: JavaMEBlog.jar<br />MIDlet-Name: JavaMEBlog<br />MIDlet-Vendor: Unknown<br />MIDlet-Version: 1.0<br />MicroEdition-Configuration: CLDC-1.1<br />MicroEdition-Profile: MIDP-2.1</blockquote><br /><br />This is a JAD file that WTK made for us. The contents of JAD file is arranged in the form of property:value. The valid properties that can come in a JAD file are:<br /><ul><br /><li><span style="font-weight: bold;">MIDlet-Name</span>: This is the name of the MIDlet suite (Do not confuse it with name of individual MIDlets contained in the suite).<br /></li><li><span style="font-weight: bold;">MIDlet-Version</span>: Version of the MIDlet Suite.<br /></li><li><span style="font-weight: bold;">MIDlet-Vendor</span>: The name of the person or the company which developed the MIDlet Suite.<br /></li><li><span style="font-weight: bold;">MIDlet-Icon</span>: Every MIDlet Suite has an icon that appears in the phone menu when the suite is installed. This enables the user to easily identify an application. The value of this property should be the name of the icon. Icons have to be stored in the <span style="font-weight:bold;">res</span> folder within the project directory.<br /></li><li><span style="font-weight: bold;">MIDlet-Description</span>: A short description of the MIDlet suite.<br /></li><li><span style="font-weight: bold;">MIDlet-Info-URL</span>: A url that gives more information about the MIDlet Suite.<br /></li><li><span style="font-weight: bold;">MIDlet-<n><n></n></span>: As mentioned, a MIDlet suite can contain more than one MIDlet. For each MIDlet present, there should be a corresponding MIDlet-1, MIDlet-2 etc entry made in the JAD file. The value of this will contain the MIDlet name, Icon for this MIDlet and the MIDlet class name.<br /></li><li><span style="font-weight: bold;">MIDlet-Jar-URL</span>: URL of the JAR file<br /></li><li><span style="font-weight: bold;">MIDlet-Jar-Size</span>: Size of the JAR file in bytes.<br /><li><span style="font-weight: bold;">MIDlet-Data-Size</span>: The minimum number of bytes required for persistent data storage.<br /><li><span style="font-weight: bold;">MicroEdition-Profile</span>: What J2ME Profile is required by the MIDlet.<br /><li><span style="font-weight: bold;">MicroEdition-Configuration</span>: What J2ME Configuration is required by the MIDlet.<br /></li></ul><br /><br />Not all of these properties are compulsory, but the following are :<br /><ol><br /><li>MIDlet-Name<br /><li>MIDlet-Version<br /><li>MIDlet-Vendor<br /><li>MIDlet-<n> for each MIDlet in the JAR file<br /><li>MicroEdition-Profile<br /><li>MicroEdition-Configuration<br /></ol><br /><br /><h3>JAR File</h3><br />JAR stands for "Java Archive". A JAR file is a compressed zip file which will contain compiled class files, icons, images and other resources that the application requires during runtime. Since it is a zip file, you can open and inspect it using any zip utility like WinZip. To create a JAR file select <span style="font-weight:bold;">Project </span>-> <span style="font-weight:bold;">Package </span>-> <span style="font-weight:bold;">Create Package</span> from the menu bar. This will create a new JAD and JAR file in the [PROJECTDIR]\bin folder.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://anoopengineer.googlepages.com/wtk_screen_create_package.JPG"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://anoopengineer.googlepages.com/wtk_screen_create_package.JPG" border="0" alt="" /></a><br /><br />Every JAR file will contain a folder named "META-INF" and file named "Manifest.mf" inside this folder. Manifest.mf is again a text file and if you open it using a text editor, you can see that it very much resembles the JAD file. All the JAD file properties that we used earlier can be added to the Manifest file also. The value of compulsory properties like MIDlet-Name, MicroEdition-Profile, MicroEdition-Configuration etc has to match in both the manifest file and JAD file. Other properties can differ between Manifest and JAD file, but in such a case the values in the JAD file is taken.<br /><br /><br /><br /><!--<h3>Obfustication</h3>--><br /><table width="100%"><br /><tr><br /> <td><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-writing.html">Previous:Writing the first MIDlet</a></td><br /> <td><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-table-of.html">Table of Contents</a></td><br /> <td><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-wtk.html">Next:TODO TODO</a></td><br /></tr><br /></table><br /><br /><br /></span>Anoop Engineernoreply@blogger.comtag:blogger.com,1999:blog-5209778108692585660.post-16688746913031574582007-08-29T17:04:00.000+05:302007-08-30T16:08:08.379+05:30Java ME Beginners Tutorial : Writing the first MIDlet<span class="dropcaps">L</span><br />ets get our hands dirty. In this chapter, we are going to write our first MIDlet. This is the fifth chapter in the 'Java ME Beginners Tutorial' series.<br/><br />By the time you reach here, you are expected to have gone through the <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-introduction.html">introduction</a>, <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-installation.html">installed WTK</a> on your work machine and <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-wtk.html">learned about it</a>. We also had a <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-java-me.html">brief look into the Java ME world</a>. In this chapter we will begin coding.<br /><span id="fullpost"><br />If you remember earlier chapters, it was said that Wireless Tool Kit is not an IDE. There is no facility to edit and indent code. So we have to use a text editor for this purpose. For the purpose of this tutorial, we will use Notepad available in windows (Linux users have a myriad of options: vi, emacs, gedit, kate, kwrite etc etc...).<br /><br /><h3>Step 1</h3><br />Fire up WTK (Start -> All Programs ->Sun Java(TM) Wireless Toolkit 2.5 for CLDC ->Wireless Toolkit 2.5 or [INSTALLDIR]\bin\ktoolbar.exe). Then select "New Project" from the toolbar.<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://anoopengineer.googlepages.com/wtk-screen_new_project.JPG"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://anoopengineer.googlepages.com/wtk-screen_new_project.JPG" border="0" alt="" /></a><br /><br />You will get a dialog box asking for Project Name and Midlet class name, as shown below.<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://anoopengineer.googlepages.com/new_project_dialog.JPG"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://anoopengineer.googlepages.com/new_project_dialog.JPG" border="0" alt="" /></a><br /><br />Provide "JavaMEBlog" as the project name and "HelloMIDlet" as the class name and click "Create Project". You will get a settings page. This is the configuration page where you can edit the settings of your project. The default settings will work for us, so click "OK". If all went correct, a folder named JavaMEBlog would have been created in the [INSTALLDIR]\apps\ directory (INSTALLDIR is the place where you installed WTK). This is the main project folder. It contain many sub directories :<br /><ul><br /><li><strong>bin</strong>:Will contain the binary files: JAD and JAR after compiling the code. (We will see JAD and JAR files later when we discuss "Packaging")<br /><li><strong>lib</strong>:Place the library files(again in JAR format) that the application requires in this directory.<br /><li><strong>res</strong>: Place resources like icons, images, audio, video files etc that the application requires during run-time in this directory.<br /><li><strong>src</strong>:The most important directory for the application developer, as this directory contains all the source code.<br /></ul><br /><h3>Step 2</h3><br />Copy-paste the following code into Notepad:<br /><blockquote><br />import javax.microedition.midlet.*;<br />import javax.microedition.lcdui.*;<br /><br /><br />public class HelloMIDlet extends MIDlet {<br /> public void startApp() {<br /> System.out.println("Hello World");<br /> }<br /> <br /> public void pauseApp() {<br /> }<br /> <br /> public void destroyApp(boolean unconditional) {<br /> }<br />}<br /></blockquote><br />Now save it as "HelloMIDlet.java". If using Notepad, be careful to make the "save as type" to "All files". Otherwise notepad will name the file as HelloMIDlet.java.txt which is not what we intended. You have to save this file in the <strong>[INSTALLDIR]\apps\JavaMEBlog\src</strong> directory.<br /><br /><h3>Step 3</h3><br />Now we can compile the code. Select "Build" from the tool bar. Building is a sequence of two operations: Compiling the code and then preverifying it. If your code was correct you will get the "Build complete" message as shown in the figure.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://anoopengineer.googlepages.com/wtk_screen_build.JPG"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://anoopengineer.googlepages.com/wtk_screen_build.JPG" border="0" alt="" /></a><br /><br /><br /><h3>Step 4</h3><br />Next step is to test the application. We use the Wireless Tool Kit's emulator for this purpose. Select "Run" from the tool bar.<br /><br />Our application doesn't do anything useful. All it does is to print "Hello World" in the WTK console and exit (duh!); so there is no point in installing such an application in an actual mobile device since there is no console in mobile devices.<br /><br />On running the application, the default emulator will be displayed (which will be Default color phone, if you haven't changed any settings). The application name "JavaMEBlog" will be displayed on the screen. Select "Launch". Since out application doesn't have a GUI, you will not notice any difference in the screen. But the string "Hello World" would be printed on the WTK's console.<br /><br /><br /><h3>Understanding the source code</h3><br /><br /><blockquote>public class HelloMIDlet extends MIDlet {</blockquote><br />Every MIDlet should implement the abstract class <strong>javax.microedition.midlet.MIDlet</strong>. This class contains three abstract methods that we have to implement: <strong>startApp()</strong>,<strong>pauseApp()</strong> and <strong>destroyApp()</strong>. Every MIDlet is invoked and controlled by the Application Management System (AMS) residing in the mobile phones. The above three methods are special as they are never called by the developer(application) but by the AMS. Whenever the user wishes to run the application, the AMS invokes the startApp() method. When the AMS wishes to pause the application (such as during an incoming call) the pauseApp() method is called. Finally, when the AMS wants to terminate the application, the destroyApp() is called.<br /><br /><br /> <blockquote>public void startApp() {<br /> System.out.println("Hello World");<br /> }</blockquote><br />The stuff within the startApp() method will be executed when the application is launched by the user. Here, we have given as simple println statement. The System.out.println() will print to the WTK's console area. So it can be used for testing with an emulator only.<br /><br /> <blockquote>public void pauseApp() {<br /> }<br /> <br /> public void destroyApp(boolean unconditional) {<br /> }</blockquote><br /><br />We are not doing anything when pauseApp() or destroyApp() is being called. In actual programming, we will be doing some clean up work (freeing some resources) in these methods. <br /><br />Since we have gone through our first code, now is a good time to discuss the life cycle of a MIDlet application.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://anoopengineer.googlepages.com/midlet_life_cycle.JPG"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://anoopengineer.googlepages.com/midlet_life_cycle.JPG" border="0" alt="" /></a><br /><br />There are three states for every MIDlet: Active, Paused and Destroyed. When the MIDlet object is made by calling its constructor, the application is said to be in the <span style="font-style:italic;">Paused</span> state. Then the AMS can move the application to <span style="font-style:italic;">Active</span> state by calling the startApp() method. From the Active state, the AMS can take the application back to Paused state by calling the pauseApp() method. The thing to remember here is that startApp() and pauseApp() can be called multiple times in an application's life time.<br />When the AMS wants to terminate the application, it calls the destroyApp() method. destroyApp() accepts a boolean parameter. If this parameter is true, the MIDlet has to compulsorily quit, no matter what it is currently doing. However if this is false, the application can survive termination by throwing a MIDletStateChangeException. If any runtime exception occurs within the destroyApp() method, it is ignored and the application is terminated immediately.<br /> <br />Next we will discuss how to package the compiled classes to a package so that other people can easily install our application.<br /><table width="100%"><br /><tr><br /> <td><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-java-me.html">Previous: Java ME Basics</a></td><br /> <td><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-table-of.html">Table of Contents</a></td><br /> <td><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-packaging.html">Next: Packaging</a></td><br /></tr><br /></table><br /><br /></span>Anoop Engineernoreply@blogger.comtag:blogger.com,1999:blog-5209778108692585660.post-17924161271322454722007-08-24T12:28:00.000+05:302007-08-30T09:40:44.726+05:30Java ME Beginners Tutorial : Java ME Basics<span class="dropcaps">W</span><br />elcome to the fourth part of the "Java ME Beginners Tutorial" series. If you haven't read the previous parts you can begin <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-introduction.html">here (Java ME Beginners Tutorial : Introduction)</a>.<br /><br />By the time you reach here, you have <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-installation.html">installed WTK</a> and <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-wtk.html">studied it</a>.So now we have everything we need to get some Java ME gyan. Let’s start.<br /><span id="fullpost"><br />By saying Java ME, we refer to a number of classes, interfaces and a JVM that is needed to run a Java application on mobiles. To make things simple and to bring little peace to this chaotic world, these classes, interfaces and JVM are put into three layers: Configuration, Profile and Optional Packages. Memorize these jargon words; you will not regret doing it when you become ‘the el33t Java ME guru’.<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://anoopengineer.googlepages.com/javamelayers.jpg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://anoopengineer.googlepages.com/javamelayers.jpg" border="0" alt="" /></a><br /><br /><br /><h3>Configuration</h3><br />This is the most underlying layer of Java ME and not surprisingly, it contains the “special” JVM also. Now why do we need a special JVM? Why can’t we reuse the existing JVM that we use in our desktops? The reason is simple: your mobile phone has less computational muscle as compared to a desktop computer. So it simply can’t run the bulky and mighty JVM from the desktop world.<br /><br />I said I was lying when I defined Java ME in the <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-introduction.html">introduction</a>. I said that Java ME is for creating Java programs for mobile phones. Sure!, you can use Java ME technology to develop application for mobile phones, but its scope is not just limited to mobile phones. Java ME is currently used on a multitude device like pagers, set-top boxes, car navigation systems and a number of other embedded systems. The only requirement to use Java ME is that the device should have some sort of connectivity: a powerful Ethernet connection or a weak wireless connection.<br />There are two types of configuration as of writing this:<br /><ol><br /><li>CDC and<br /><li>CLDC<br /></ol><br />CDC stands for ‘Connected Device Configuration’ and CLDC for ‘Connected Limited Device Configuration’.<br /><br /><br />CDC aims at devices that are a little bit more powerful than a mobile phone; devices like a Set-top box or a Car Navigation system. I have mentioned that configuration contained the JVM. The virtual machine in CDC is called CVM (Compact Virtual Machine). <br /><br />Mobile phones use CLDC as the configuration. The VM used in CLDC is termed KVM (K because it runs on Kilobytes of memory).<br /><br /><h4>CVM</h4><br />This VM is a complete clone of the desktop Java JVM. It contains all the power, all the abilities of the former. Only difference is that it can run in a much-restricted environment: restricted memory, restricted computational power, restricted storage facility.<br /><h4>KVM</h4><br />This is a stripped down version of the desktop VM. It is designed for smaller device like a mobile phone and for a smaller memory footprint. It doesn’t support all features of conventional JVM like the object serialization, finalization etc.<br /><br /><br />In addition to the JVM the configuration also contains all the classes, interfaces and exceptions that Java ME subsets from Java SE. A list of all classes contained in CLDC can be obtained <a href="http://java.sun.com/javame/reference/apis/jsr139/">here</a>.<br />The configuration used in mobile phones is CLDC, and hence this will be our area of interest.<br /><h4>CLDC</h4><br />Some of the limitations of the CLDC are given below. A programmer need to be aware of such limitations to avoid serious trouble later on.<br /><ul><br /><li>No floating point support.<br /><li>No object finalization.<br /><li>No JNI support.<br /><li>No reflection.<br /><li>No thread groups and daemon threads.<br /><li>No application defined class loaders.<br /><li>Implementation defined error handling.<br /><li>Class verification is done in a different manner.<br /></ul><br /><br /><h3>Profile</h3><br />A profile extends the configuration. It adds domain specific classes to the core. It is geared towards a specific use of the device. For example, not every device need to have a screen. For devices that have one, the APIs to manage the screen is included in a profile.<br /><br />There are different types of profiles like MIDP, Foundation Profile, Personal Profile, Personal Basis Profile etc. The profile used in mobile phones is MIDP, and hence this will be our area of interest.<br /><h4>MIDP</h4><br /><span class="pullquote"><br />Application created using the MIDP API is called a MIDlet.<br /></span><br /><strong>M</strong>obile <strong>I</strong>nformation <strong>D</strong>evice <strong>P</strong>rofile extends the CLDC configuration. JSR 37 introduced MIDP 1.0, while JSR 118 introduced MIDP 2.0.<br />MIDP 1.0 contained APIs for UI creation, local persistence mechanism, networking and MIDlet life-cycle management. (An application written using MIDP APIs is called a MIDlet). In addition to these, MIDP 2.0 added APIs for a robust security policy, APIS for sound and gaming and extended the networking APIs to include TCP socket streams, UDP datagrams, serial, push-initiated and secure connections.<br />You may not know a lot of things said above. Don’t worry just read along. You will catch up in no time.<br /><br /><h3>Optional Packages</h3><br />At first, when the 'Sun' god created Java ME platform (then called J2ME) there was only configurations and profiles. As the platform evolved, god realized that something was missing. There was no way to support new technology. He knew it was not a good practice to throw everything and the kitchen sink into the profiles. So he created optional packages.<br /><br />Optional packages are similar to profiles as they are also a set of APIs. They do not have an independent existence of their own. They are always associated with a configuration and a profile. An optional package extend the capabilities of a configuration + profile system.<br /><br />An example of an optional package is the MMAPI or the Multimedia API. This API provides support for playing Audio and Video files as well as other features like taking photos using the phones built in camera. However not all mobile phones support multimedia and not all mobiles will be having a built in camera. So only those phones which support these features will contain the MMAPI support in them.<br /><br />An important thing that Java ME developers should know is that application developers have no control over what optional packages are available on a phone. No, we cannot install optional packages in a mobile phone, nor can we bundle our application with an optional package. It is the phone manufactures like Nokia and Motorola that should provide optional packages. If they haven't, then you will have to eat that.<br /><table width="100%"><br /><tr><br /> <td align="left"><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-wtk.html">Previous:WTK Explained</a></td><br /> <td align="center"><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-table-of.html">Table of Contents</a></td><br /> <td align="right"><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-writing.html">Next: Writing the first MIDlet</a></td><br /></tr><br /></table><br /></span>Anoop Engineernoreply@blogger.comtag:blogger.com,1999:blog-5209778108692585660.post-83831079245086773942007-08-24T10:56:00.000+05:302007-08-29T17:00:08.726+05:30Java ME Beginners Tutorial : WTK Explained<span class="dropcaps">T</span><br />his is third part of the "Java ME Beginners Tutorial" series. If you haven't read the previous parts you can begin <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-introduction.html">here (Java ME Beginners Tutorial : Introduction)</a>.<br><br />This section explains in-depth about the Sun's Wireless Tool kit(WTK). We have already discussed the <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-installation.html">Installation of WTK</a>.<br /><span id="fullpost"><br />When you install WTK seven menu entries are made for you. They are:<br /><ul><br /><li>Default Device Selection<br /><li>Documentation<br /><li>OTA Provisioning<br /><li>Preferences<br /><li>Run MIDP Application<br /><li>Utilities<br /><li>Wireless Toolkit 2.5<br /></ul><br /><h3>Default Device Selection</h3><br /><br><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://anoopengineer.googlepages.com/default-device.JPG"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://anoopengineer.googlepages.com/default-device.JPG" border="0" alt="" /></a><br /><br><br />After you write your code and compile it, you will be emulating the behavior of your application using an emulator that's built into the WTK. This avoids the need for a physical mobile device to install and test your app each time you make a modification. Since there are a wide variety of mobile devices on the market each with a different look and feel, WTK provides us with four different emulators each having a different screen size and look and feel.<br><br />The "Default Device Selection" menu entry points to <INSTALLDIR>\bin\DefaultDevicew.exe. It is a simple utility which enables us to make a particular emulator as our default emulator. <br /><br /><h3>Documentation</h3><br />An excellent documentation for the Wireless Tool Kit. It also includes the API reference for CLDC, MIDP and a number of other popular packages. (Don't worry if you don't understand what's CLDC and MIDP. It will be explained later). Go throught the FAQ section in the documentation. It is a must read!<br /><br /><h3>OTA Provisioning</h3><br />The Java ME platform has the ability to download and install a Java application over a wireless network (usually on demand). This is called OTA(Over The Air installation) For this, after developing the application we need to place the application on a special server. Once we have done this, we can use the WTK emulator to download and install the application. If OTA works fine in emulator it ought to work fine in an actual mobile device.<br /><br />The "OTA Provisioning" menu entry points to <INSTALLDIR>\bin\emulatorw.exe -Xjam. That is, it invokes the emulator with a particular command line switch "-Xjam". It displays the default emulator as shown below.<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://anoopengineer.googlepages.com/ota-provisioning.JPG"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://anoopengineer.googlepages.com/ota-provisioning.JPG" border="0" alt="" /></a><br />Select "Apps" and then Menu -> Launch.<br />You will see a text entry where you can give the web address of your application to be installed.<br /><br /><h3>Preferences</h3><br /><br><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://anoopengineer.googlepages.com/wtk-preferences.JPG"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://anoopengineer.googlepages.com/wtk-preferences.JPG" border="0" alt="" /></a><br /><br><br />The menu entry "Preferences" points to <INSTALLDIR>\bin\prefsw.exe. The preferences window allows you to change many configuration settings of the Tool kit. These include the Network Proxy, the heap size available,adjusting emulator performance, enabling memory and network monitoring, enabling profiling, tracing, changing the emulator's storage space etc.<br /><br /><h3>Utilities</h3><br /><br><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://anoopengineer.googlepages.com/wtk-utilities.JPG"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://anoopengineer.googlepages.com/wtk-utilities.JPG" border="0" alt="" /></a><br /><br><br />The "Utilities" menu entry points to <INSTALLDIR>\bin\utilsw.exe. It is similar to the Windows Control Panel as it is a collection of multiple utility programs. It contains utilities like the Database Cleaner which removes all database records in the default emulator, the memory & network monitor, the profiler, midlet signing utility etc.<br /><br /><h3>Wireless Toolkit 2.5</h3><br /><br><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://anoopengineer.googlepages.com/wtk-screen.JPG"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://anoopengineer.googlepages.com/wtk-screen.JPG" border="0" alt="" /></a><br /><br><br />This is the most important one. It points to <INSTALLDIR>\bin\ktoolbar.exe. It is important because we use it to perform all major tasks in Java ME application developing - compiling, packaging and testing (and more).<br /><br><br />An important thing to know is that WTK is not an <a href="http://en.wikipedia.org/wiki/Integrated_development_environment">IDE</a>. It doesn't have any means for code editing. You will have to use an external text editor like notepad for creating .java files. <br><br />We can classify the main window into three parts:<br /><ol><br /><li>Menu Bar<br /><li>Tool Bar<br /><li>Console Area<br /></ol><br />This have been marked in the figure:<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://anoopengineer.googlepages.com/wtk-screen_markings.JPG"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://anoopengineer.googlepages.com/wtk-screen_markings.JPG" border="0" alt="" /></a><br />How to use WTK will be discussed as we begin coding.<br /><table width="100%"><br /><tr><br /> <td align="left"><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-installation.html">Previous:Installation</a></td><br /> <td align="center"><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-table-of.html">Table of Contents</a></td><br /> <td align="right"><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-java-me.html">Next:Java ME Basics</a></td><br /></tr><br /></table><br /></span>Anoop Engineernoreply@blogger.comtag:blogger.com,1999:blog-5209778108692585660.post-65307243921183835372007-08-24T09:12:00.000+05:302007-08-29T16:58:25.006+05:30Java ME Beginners Tutorial : Installation Instructions<span class="dropcaps">T</span><br />his is the second part of the "Java ME Beginners Tutorial" series. If you haven't read the first part you can get it <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-introduction.html">here</a> <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-introduction.html">(Java ME Beginners Tutorial : Introduction)</a>.<br /><br />This section explains about installing Sun's Wireless Tool kit (here forth called WTK) in your computer. Prior to installing WTK , you should have Java SE Development Kit installed.<br /><span id="fullpost"><br />If you have been programming in Java for a while, you may already have it. Otherwise <a href="http://java.sun.com/javase/downloads/index.jsp">download JDK</a> and install it first.<br /><br />The next step is the installation of the WTK itself. Download 'WTK for CLDC' <a href="http://java.sun.com/products/sjwtoolkit/download.html">from the sun's site</a>. As you will notice it is available for both Windows and Linux. This tutorial will be using WTK on Windows, but it will be much similar to use in a Linux machine.<br />Once you install WTK you will get a menu entry in your start menu as shown.<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://anoopengineer.googlepages.com/wtk-menu.JPG"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://anoopengineer.googlepages.com/wtk-menu.JPG" alt="" border="0" /></a><br />The one which we are interested is Start Menu -> All Programs -> Sun Java(TM) Wireless Toolkit 2.5 for CLDC -> Wireless Toolkit 2.5. (In older versions of WTK, the menu entry was named 'ktoolbar'). If you select it the following screen will be displayed.<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://anoopengineer.googlepages.com/wtk-screen.JPG"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://anoopengineer.googlepages.com/wtk-screen.JPG" border="0" alt="" /></a><br /><br />The next section will explain the WTK interface in detail.<br /><table width="100%"><br /><tr><br /> <td align="left"><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-introduction.html">Previous:Introduction</a></td><br /> <td align="center"><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-table-of.html">Table of Contents</a></td><br /> <td align="right"><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-wtk.html">Next:WTK Explained</a></td><br /></tr><br /></table><br /></span>Anoop Engineernoreply@blogger.comtag:blogger.com,1999:blog-5209778108692585660.post-49651639280660625982007-08-23T11:19:00.000+05:302007-08-29T16:57:01.570+05:30Java ME Beginners Tutorial : Introduction<span class="dropcaps">T</span><br />his is the beginning of the 'Java ME Beginners Tutorial' Series. Emphasis has been given to explain stuff in a easy to understand, concise manner. This is intended for novice Java programmers who wishes to enter the 'Java ME' arena. Please send your feedback to anoopengineer[AT]gmail[DOT]com. We will begin with the prerequisites.<br /><h3>Prerequisites</h3><br /><ol><br /> <li>Good knowledge on Core Java a.k.a Java SE.<br /> <li>Sun Java Wireless Toolkit 2.5.1. See installation for details.<br /> <li>A Little grey matter.<br /></ol><br /><span id="fullpost"><br /><h3>What we are going to learn</h3><br />Java ME (earlier known as J2ME) is for creating java programs for mobile phones (I'm lying here as I explains later, but this will help you now). You use an ordinary Windows/Linux desktop computer to write your program, emulate its working using the toolkit, and then transfer it to a mobile phone for installing.<br />For this, you need to install "Sun Java Wireless Toolkit" in your desktop. The current version of the toolkit as of writing this is 2.5.1. How to get the toolkit and install it is specified in the installation section. After going through this tutorial, you will be able to create all kind of mobile applications, limited only by your creativity<br /><table width="100%"><br /><tr><br /> <td align="left"><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-table-of.html">Table of Contents</a></td><br /> <td align="right"><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-installation.html">Next: Installation</a></td><br /></tr><br /></table><br /></span>Anoop Engineernoreply@blogger.comtag:blogger.com,1999:blog-5209778108692585660.post-87962061905606693762007-08-22T23:55:00.000+05:302007-08-31T10:12:04.288+05:30Java ME Beginners Tutorial: Table Of Contents<a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-introduction.html">Chapter 1 : Introduction</a><br/><br /><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-installation.html">Chapter 2 : Installation Instructions</a><br/><br /><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-wtk.html">Chapter 3 : WTK Explained</a><br/><br /><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-java-me.html">Chapter 4 : Java ME Basics</a><br/><br /><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-writing.html">Chapter 5 : Writing the first MIDlet</a><br/><br /><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-packaging.html">Chapter 6 : Packaging</a><br/>Anoop Engineernoreply@blogger.comtag:blogger.com,1999:blog-5209778108692585660.post-84778068900581345372007-08-22T17:00:00.000+05:302007-08-31T18:03:05.107+05:30Java ME BooksThis is a listing of all books that are related to Java ME technology. They are in no particular order.<br /><h3><a name="freebooks" href="#freebooks">Free Books</a></h3><br /><a href="http://www.jasonlam604.com/books.php">J2ME & Gaming by Jason Lam</a><br /><br /><a href="http://www.theserverside.com/tt/articles/article.tss?l=EnterpriseJ2ME">Enterprise J2ME: Developing Mobile Java Applications</a> by Michael Juntao Yuan<br /><br /><a href="http://developers.sun.com/techtopics/mobility/midp/chapters/j2meknudsen2/index.html">Wireless Java: Developing with J2ME, Second Edition</a> by Jonathan Knudsen.<br /><br /><a href="http://www.symbian.com/books/wjsd/wjsd-info.html">Wireless Java for Symbian Devices</a> by Jonathan Allin<br /><br /><a href="http://www.symbian.com/books/j2me/j2me_info.html">Programming Java 2 Micro Edition on Symbian OS. A developer's guide to MIDP 2.0</a> by Martin de Jode<br /><br /><br /><h3><a href="http://www.amazon.com/Beginning-J2ME-Novice-Professional-Third/dp/1590594797/ref=pd_bbs_sr_1/102-2577062-6717731?ie=UTF8&s=books&qid=1188561845&sr=1-1">Beginning J2ME: From Novice to Professional, Third Edition</a> </h3><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://anoopengineer.googlepages.com/bcm.gif"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://anoopengineer.googlepages.com/bcm.gif" alt="" border="0" /></a><b>About the Author</b><br /> Jonathan Knudsen is a Java developer and noted author of several books, including <a href="http://www.apress.com/book/bookDisplay.html?bID=138" target="_blank">Wireless Java: Developing with J2ME, Second Edition</a>, <i>Mobile Java</i>, <i>The Unofficial Guide to LEGO MINDSTORMS Robots</i>, <i>Learning Java</i>, and <i>Java 2D Graphics</i>. Jonathan began his object-oriented programming career in Objective-C on the NeXT OS, soon thereafter suffering through a couple of purgatorial years in Microsoft's Visual C++, before graduating to Java in 1996. He has written extensively about Java and LEGO robots, including five books, a monthly online column called "Bite-Size Java," and articles for JavaWorld, EXE, NZZ Folio, and the O'Reilly Network. Jonathan holds a degree in mechanical engineering from Princeton University. You can find him at <a href="http://www.jonathanknudsen.com/" target="_blank">www.jonathanknudsen.com</a>. Sing Li is a systems consultant, avid open source developer, and active freelance writer. With over two decades of industry experience, Sing is a regular contributor to printed magazines and e-zines, and has a sizable roster of book credits. Sing is an evangelist of the mobile Java, VOIP, and P2P evolution.Anoop Engineernoreply@blogger.comtag:blogger.com,1999:blog-5209778108692585660.post-50703561079812201392007-08-22T16:58:00.000+05:302007-08-31T17:29:45.223+05:30Java ME TutorialsThis page contains listing of all the Java ME tutorials and articles contained in "The Java ME Blog".<br /><h3><a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-table-of.html">Java ME Beginner's Tutorial</a></h3><br />This is a sequence of Java ME tutorial written for pure novice to Java ME field. Special importance has been given to simplicity and ease of understanding in writing this. It begins from giving an introduction to Java ME, goes through the various tools required in the trade and concludes with a guide to building source code using Wireless Tool Kit. You can start with the <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-table-of.html">table of contents</a> or instead, dive directly into action <a href="http://javameblog.blogspot.com/2007/08/java-me-beginners-tutorial-introduction.html">here</a>.<br /><br /><h3><a href="http://javameblog.blogspot.com/2007/08/java-me-advanced-tutorial-table-of.html">Java ME Advanced Tutorial</a></h3><br />This is a sequence of tutorials written for people who have had an introduction to Java ME technology. It has been written as a continuation of the Java ME Beginner's Tutorial. It covers topics like GUI programming, RMS, Multimedia, WMA, Bluetooth etc. You can start with the <a href="http://javameblog.blogspot.com/2007/08/java-me-advanced-tutorial-table-of.html">Table of Contents</a>.<br />Anoop Engineernoreply@blogger.comtag:blogger.com,1999:blog-5209778108692585660.post-42382168320954909422007-08-22T16:49:00.000+05:302007-08-22T16:50:09.595+05:30Java ME- Frequently Asked QuestionsThis is supposed to contain a FAQ. Please give me a little time to compile this.Anoop Engineernoreply@blogger.comtag:blogger.com,1999:blog-5209778108692585660.post-68923553207765578082007-08-22T16:04:00.000+05:302007-08-22T16:41:53.666+05:30Contact Me<br/>Your feedback on this site is most welcomed and needed. Please send in your queries and suggestion to anoopengineer[AT]gmail[DOT]com. I usually reply to all mails that I receive. But if I am taking time, it means I am currently engaged in something more important. Please be patient, I will eventually find time for you. Alternatively, you can leave your comments on any blog post, and I will do my best to answer them. Thanks, Anoop KS.<br /><br/><br/><br/>Anoop Engineernoreply@blogger.comtag:blogger.com,1999:blog-5209778108692585660.post-22371458832915662812007-08-20T15:05:00.000+05:302007-08-21T18:01:26.956+05:30Java ME Beginners Tutorial: Part Two<span style="font-size:180%;">The Build Procedure</span><p class="MsoNormal">There are six steps in the creation of a MIDlet. These are:</p> <br /><span id="fullpost"><br /><h3><span style="font-size:130%;">Design</span></h3> <p class="MsoNormal">This is essential for even the smallest of the projects. A good design can eliminate most of the roadblocks you are going to face with “jumping into the code” style of programming. You need to keep in mind some of the elemental features of a mobile application. The User Interface in a mobile phone is substantially different from a user interface available in Microsoft Windows or Linux Gnome/KDE. In windows forms, a large amount of data can be provided to the application through a wide range of widgets available like text fields, radio buttons, combo boxes etc. due to the large screen size. In a mobile phone, the screen real estate is limited and hence you may want to limit the widgets in each screen to a minimum and take the user through a sequence of screens to get the needed data (much like a wizard in Windows). In usual commercial production environment it is always better to design the application UI in Flash first and then code it accordingly.</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <h3><span style="font-size:130%;">Code</span></h3> <p class="MsoNormal">Every MIDlet must extend the abstract class MIDlet in javax.microedition.midlet package. Then you have to override three methods of this abstract class:</p> <p class="MsoNormal" style="margin-left: 0.25in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-family:Symbol;">·<span style=""> </span></span><!--[endif]-->startApp()</p> <p class="MsoNormal" style="margin-left: 0.25in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-family:Symbol;">·<span style=""> </span></span><!--[endif]-->pauseApp()</p> <p class="MsoNormal" style="margin-left: 0.25in; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-family:Symbol;">·<span style=""> </span></span><!--[endif]-->destroyApp()</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal">We will come to these methods later when we discuss the MIDlet life cycle.</p> <p class="MsoNormal">Remember that there will NOT be a “public static void main()” method anywhere in our program.</p> <h3><span style="font-size:130%;">Compile</span></h3> <p class="MsoNormal">Similar to Java SE technique, the code has to be compiled to byte code form. This is done using the javac compiler.</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <h3><span style="font-size:130%;">Preverify</span></h3> <p class="MsoNormal">Before running any class file the JVM performs a verification of the byte code to ensure that it is structurally and conceptually correct as per the JVM specification. If the class file fails this check, it is rejected and the JVM shuts down. This is done by all JVMs including our CLDC JVM. But there is a problem. Verification is a costly process, both in turns of memory and processor cycles. And hence a normal mobile phone won’t be able to verify class files. As a solution to this, the verification process itself was divided into two: a preverification which is done in the desktop development station and a simple verification by the mobile phone JVM which checks whether preverification was done earlier or not. The preverification process adds special information to the class files that identified them as preverified. This makes the process on the device more efficient.</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <h3><span style="font-size:130%;">Package</span></h3> <p class="MsoNormal">The java application that we developed is then send to the customers in the form of two files – the JAD file and the JAR file.</p> <p class="MsoNormal">The JAD (Java Application Descriptor) file is a text file, which describes the application. It contains the name of the application, the version of the application, the version of CLDC and MIDP required to run the application, the location of the jar file, the jar file size etc.</p> <p class="MsoNormal">The JAR (Java Archive) file is a compressed zip file, which contains all the preverified class files together with any other resources that the application requires like audio, images etc. This JAR file can be opened with any zip file handler like winzip and studied. The JAR file contains an important file called Manifest.mf. This file also contains information about the application similar to the jad file.</p> <h3><span style="font-size:130%;">Test</span></h3> <p class="MsoNormal">We can test the application using the emulator available in WTK or using a real mobile device.</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <h2 style="font-weight: normal;"><span style="font-size:180%;">Using the Wireless Toolkit</span></h2> <p class="MsoNormal">Since we have studied the build process, we will see how to perform these steps using the Wireless Toolkit. It would be a good idea now, to learn bit more about the WTK.</p> <p class="MsoNormal">If you installed the WTK to C:\WTK25 then these are the folders you will find there:</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <table style="" border="1" cellpadding="0" cellspacing="3"> <tbody><tr> <td style="padding: 0in 5.4pt; width: 0.95in;" valign="top" width="91"> <p class="MsoNormal">appdb</p> </td> <td style="padding: 0in 5.4pt; width: 5.2in;" valign="top" width="499"> <p class="MsoNormal">This directory is the root for the emulators file system.</p> </td> </tr> <tr> <td style="padding: 0in 5.4pt; width: 0.95in;" valign="top" width="91"> <p class="MsoNormal">apps</p> </td> <td style="padding: 0in 5.4pt; width: 5.2in;" valign="top" width="499"> <p class="MsoNormal">The project directory. All project are created here.</p> </td> </tr> <tr> <td style="padding: 0in 5.4pt; width: 0.95in;" valign="top" width="91"> <p class="MsoNormal">bin</p> </td> <td style="padding: 0in 5.4pt; width: 5.2in;" valign="top" width="499"> <p class="MsoNormal">Contains the binaries for the WTK itself and for other need like the compiler, emulator etc</p> </td> </tr> <tr> <td style="padding: 0in 5.4pt; width: 0.95in;" valign="top" width="91"> <p class="MsoNormal">docs</p> </td> <td style="padding: 0in 5.4pt; width: 5.2in;" valign="top" width="499"> <p class="MsoNormal">The documentation for the WTK along with API reference for CLDC and MIDP.</p> </td> </tr> <tr> <td style="padding: 0in 5.4pt; width: 0.95in;" valign="top" width="91"> <p class="MsoNormal">lib</p> </td> <td style="padding: 0in 5.4pt; width: 5.2in;" valign="top" width="499"> <p class="MsoNormal">Contains the jar files for MIDP, CLDC and a large number of optional packages.</p> </td> </tr> <tr> <td style="padding: 0in 5.4pt; width: 0.95in;" valign="top" width="91"> <p class="MsoNormal">sessions</p> </td> <td style="padding: 0in 5.4pt; width: 5.2in;" valign="top" width="499"> <p class="MsoNormal">Folder where the networking and profiling sessions are saved.</p> </td> </tr> <tr> <td style="padding: 0in 5.4pt; width: 0.95in;" valign="top" width="91"> <p class="MsoNormal">wtklib</p> </td> <td style="padding: 0in 5.4pt; width: 5.2in;" valign="top" width="499"> <p class="MsoNormal">Contains the library files (jar files) used by the WTK itself.</p> </td> </tr> </tbody></table> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal">Now run the Wireless ToolKit<span style=""> </span>as mentioned in the <a href="http://www.blogger.com/post-create.g?blogID=5209778108692585660#_Installation">Installation</a> section and select “New Project” from the menu bar.</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal" style="text-align: center;" align="center"><!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600" spt="75" preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> <v:stroke joinstyle="miter"> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0"> <v:f eqn="sum @0 1 0"> <v:f eqn="sum 0 0 @1"> <v:f eqn="prod @2 1 2"> <v:f eqn="prod @3 21600 pixelWidth"> <v:f eqn="prod @3 21600 pixelHeight"> <v:f eqn="sum @0 0 1"> <v:f eqn="prod @6 1 2"> <v:f eqn="prod @7 21600 pixelWidth"> <v:f eqn="sum @8 21600 0"> <v:f eqn="prod @7 21600 pixelHeight"> <v:f eqn="sum @10 21600 0"> </v:formulas> <v:path extrusionok="f" gradientshapeok="t" connecttype="rect"> <o:lock ext="edit" aspectratio="t"> </v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" style="'width:6in;"> <v:imagedata src="file:///C:/DOCUME~1/anoopks/LOCALS~1/Temp/msoclip1/01/clip_image001.jpg" title="wtk-screenshot_newProj"> </v:shape><![endif]--><!--[if !vml]--><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_B0CuCDv4i18/Rslg53fcnnI/AAAAAAAAABI/02Z5YMM_pPY/s1600-h/wtk-screenshot_newProj.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 455px; height: 193px;" src="http://bp2.blogger.com/_B0CuCDv4i18/Rslg53fcnnI/AAAAAAAAABI/02Z5YMM_pPY/s320/wtk-screenshot_newProj.jpg" alt="" id="BLOGGER_PHOTO_ID_5100714600238456434" border="0" /></a><!--[endif]--></p> <p class="MsoNormal" style="text-align: center;" align="center"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal">You will get a window as shown below:</p> <p class="MsoNormal" style="text-align: center;" align="center"><!--[if gte vml 1]><v:shape id="_x0000_i1026" type="#_x0000_t75" style="'width:240pt;height:115.5pt'"> <v:imagedata src="file:///C:/DOCUME~1/anoopks/LOCALS~1/Temp/msoclip1/01/clip_image003.jpg" title="new_project"> </v:shape><![endif]--><!--[if !vml]--><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp1.blogger.com/_B0CuCDv4i18/RslhJnfcnoI/AAAAAAAAABQ/GZnLhtkjED4/s1600-h/new_project.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp1.blogger.com/_B0CuCDv4i18/RslhJnfcnoI/AAAAAAAAABQ/GZnLhtkjED4/s320/new_project.jpg" alt="" id="BLOGGER_PHOTO_ID_5100714870821396098" border="0" /></a><!--[endif]--></p> <p class="MsoNormal" style="text-align: center;" align="center"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal">Enter the project name as “AnoopKS” and Class Name as “HelloMidlet”; then press “Create Project”. The settings window should be displayed.</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal" style="text-align: center;" align="center"><!--[if gte vml 1]><v:shape id="_x0000_i1027" type="#_x0000_t75" style="'width:6in;height:458.25pt'"> <v:imagedata src="file:///C:/DOCUME~1/anoopks/LOCALS~1/Temp/msoclip1/01/clip_image004.jpg" title="settings"> </v:shape><![endif]--><!--[if !vml]--><br /><!--[endif]--></p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal">Use the default settings and click ok. You can see the various messages posted on the main window:</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal" style="text-align: center;" align="center"><!--[if gte vml 1]><v:shape id="_x0000_i1028" type="#_x0000_t75" style="'width:6in;height:183.75pt'"> <v:imagedata src="file:///C:/DOCUME~1/anoopks/LOCALS~1/Temp/msoclip1/01/clip_image006.jpg" title="main_window_new_project"> </v:shape><![endif]--><!--[if !vml]--><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp3.blogger.com/_B0CuCDv4i18/RslhhHfcnqI/AAAAAAAAABg/pCXEkreST2w/s1600-h/main_window_new_project.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 456px; height: 193px;" src="http://bp3.blogger.com/_B0CuCDv4i18/RslhhHfcnqI/AAAAAAAAABg/pCXEkreST2w/s320/main_window_new_project.jpg" alt="" id="BLOGGER_PHOTO_ID_5100715274548321954" border="0" /></a><!--[endif]--></p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal">If you go to C:\WTK25\apps\ you can see that a folder named AnoopKS have been created. All the .java files that you write should be put into the C:\WTK25\apps\AnoopKS\src folder.</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal">Now take Notepad and copy-paste the following code into it.</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal"></p><blockquote><p class="MsoNormal">import javax.microedition.midlet.*;</p> <p class="MsoNormal">import javax.microedition.lcdui.*;</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal">public class HelloMidlet extends MIDlet {</p> <p class="MsoNormal"><span style=""> </span>public void startApp() {</p> <p class="MsoNormal"><span style=""> </span>System.out.println("Hello World");</p> <p class="MsoNormal"><span style=""> </span>}</p> <p class="MsoNormal"><span style=""> </span></p> <p class="MsoNormal"><span style=""> </span>public void pauseApp() {</p> <p class="MsoNormal"><span style=""> </span>}</p> <p class="MsoNormal"><span style=""> </span></p> <p class="MsoNormal"><span style=""> </span>public void destroyApp(boolean unconditional) {</p> <p class="MsoNormal"><span style=""> </span>}</p> <p class="MsoNormal">}</p></blockquote><p class="MsoNormal"></p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal">Save it as HelloMidlet.java in the folder C:\WTK25\apps\AnoopKS\src. This code doesn’t do anything fancy. All it does is print “Hello World” on the WTK’s message area and exit.</p> <p class="MsoNormal">Now select “Build” from the tool bar:</p> <p class="MsoNormal" style="text-align: center;" align="center"><!--[if gte vml 1]><v:shape id="_x0000_i1029" type="#_x0000_t75" style="'width:6in;height:183.75pt'"> <v:imagedata src="file:///C:/DOCUME~1/anoopks/LOCALS~1/Temp/msoclip1/01/clip_image008.jpg" title="main_window_build"> </v:shape><![endif]--><!--[if !vml]--><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://anoopengineer.googlepages.com/wtk_main_win_build.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 454px; height: 192px;" src="http://bp1.blogger.com/_B0CuCDv4i18/Rslh0nfcnrI/AAAAAAAAABo/OIAdWgyUZOs/s320/main_window_build.jpg" alt="" id="BLOGGER_PHOTO_ID_5100715609555771058" border="0" /></a><!--[endif]--></p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal">If you have typed the program correctly build should be success. Now you can run the application in an emulator by selecting “Run” from the tool bar.</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal" style="text-align: center;" align="center"><!--[if gte vml 1]><v:shape id="_x0000_i1030" type="#_x0000_t75" style="'width:6in;height:183.75pt'"> <v:imagedata src="file:///C:/DOCUME~1/anoopks/LOCALS~1/Temp/msoclip1/01/clip_image010.jpg" title="main_window_run"> </v:shape><![endif]--><!--[if !vml]--><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_B0CuCDv4i18/Rslh93fcnsI/AAAAAAAAABw/onyB3JlsoOo/s1600-h/main_window_run.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 469px; height: 199px;" src="http://bp2.blogger.com/_B0CuCDv4i18/Rslh93fcnsI/AAAAAAAAABw/onyB3JlsoOo/s320/main_window_run.jpg" alt="" id="BLOGGER_PHOTO_ID_5100715768469561026" border="0" /></a><!--[endif]--></p> <p class="MsoNormal" style="text-align: center;" align="center"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal">The emulator will be displayed. Select “Launch” and you can see the string “Hello World” being displayed on the WTK messages area.</p> <p class="MsoNormal" style="text-align: center;" align="center"><!--[if gte vml 1]><v:shape id="_x0000_i1031" type="#_x0000_t75" style="'width:221.25pt;height:500.25pt'"> <v:imagedata src="file:///C:/DOCUME~1/anoopks/LOCALS~1/Temp/msoclip1/01/clip_image012.jpg" title="emulator1"> </v:shape><![endif]--><!--[if !vml]--><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_B0CuCDv4i18/RsliK3fcntI/AAAAAAAAAB4/UsGbGYIn8gI/s1600-h/emulator1.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 246px; height: 558px;" src="http://bp2.blogger.com/_B0CuCDv4i18/RsliK3fcntI/AAAAAAAAAB4/UsGbGYIn8gI/s320/emulator1.jpg" alt="" id="BLOGGER_PHOTO_ID_5100715991807860434" border="0" /></a><!--[endif]--></p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal">Go to C:\WTK25\apps\AnoopKS\bin directory and you can see that a JAD file have been created. But still there is no JAR file. To create JAR file select the menu: Project -> Package -> Create Package.</p></span>Anoop Engineernoreply@blogger.comtag:blogger.com,1999:blog-5209778108692585660.post-27002028969022131122007-08-20T14:27:00.000+05:302007-08-20T15:05:26.275+05:30Java ME Beginners Tutorial: Part OneThis tutorial aims in teaching you Java ME technology in the simplest possible way. Please send your feedback to anoopengineer[at]gmail[dot]com.<br /><!--[endif]--><o:p></o:p> <h2><span style="font-size:180%;">Prerequisites</span></h2> <ol><li><!--[if !supportLists]-->Good knowledge on Core Java a.k.a Java SE.</li><li>Sun Java Wireless Toolkit 2.5.1. See installation for details.</li><li>A Little grey matter.</li></ol> <p class="MsoNormal" style="margin-left: 0.25in; text-indent: -0.25in;"><!--[if !supportLists]--><br /><span style=""> </span><!--[endif]--></p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <h2><span style="font-size:180%;">What we are going to learn</span></h2> <p class="MsoNormal">Java ME (earlier known as J2ME) is for creating java programs for mobile phones (I'm lying here a bit, but it will help you). You use an ordinary Windows/Linux desktop computer to write your program, emulate its working using the toolkit, and then transfer it to a mobile phone for installing.</p> <p class="MsoNormal">For this, you need to install "Sun Java Wireless Toolkit" in your desktop. The current version of the toolkit as of writing this is 2.5.1. How to get the toolkit and install it is specified in the installation section. After going through this tutorial, you should be able to create all sorts of applications on your mobile.</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <h2><a name="_Installation"></a><span style="font-size:180%;">Installation</span></h2> <p class="MsoNormal">Prior to installing Java Wireless Toolkit (here forth called WTK), you should have Java Runtime Environment installed in your computer. The download page for <a href="http://java.sun.com/products/sjwtoolkit/download-2_5_1.html">WTK</a> gives more information on these.</p> <p class="MsoNormal">After installing WTK, you should get a start menu entry as shown below.</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal" style="text-align: center; page-break-after: avoid;" align="center"><!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600" spt="75" preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> <v:stroke joinstyle="miter"> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0"> <v:f eqn="sum @0 1 0"> <v:f eqn="sum 0 0 @1"> <v:f eqn="prod @2 1 2"> <v:f eqn="prod @3 21600 pixelWidth"> <v:f eqn="prod @3 21600 pixelHeight"> <v:f eqn="sum @0 0 1"> <v:f eqn="prod @6 1 2"> <v:f eqn="prod @7 21600 pixelWidth"> <v:f eqn="sum @8 21600 0"> <v:f eqn="prod @7 21600 pixelHeight"> <v:f eqn="sum @10 21600 0"> </v:formulas> <v:path extrusionok="f" gradientshapeok="t" connecttype="rect"> <o:lock ext="edit" aspectratio="t"> </v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" style="'width:375pt;"> <v:imagedata src="file:///C:/DOCUME~1/anoopks/LOCALS~1/Temp/msoclip1/01/clip_image001.jpg" title="menu-entry"> </v:shape><![endif]--><!--[if !vml]--><br /></p><h2><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp1.blogger.com/_B0CuCDv4i18/RslZLnfcnjI/AAAAAAAAAAo/oS6pIOdFnkQ/s1600-h/menu-entry.JPG"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp1.blogger.com/_B0CuCDv4i18/RslZLnfcnjI/AAAAAAAAAAo/oS6pIOdFnkQ/s320/menu-entry.JPG" alt="" id="BLOGGER_PHOTO_ID_5100706109088112178" border="0" /></a></h2><p class="MsoNormal" style="text-align: center; page-break-after: avoid;" align="center"><!--[endif]--></p> <p class="MsoCaption" style="text-align: center;" align="center">Figure <span style="">1</span>: Start Menu entry after installing WTK</p> <p class="MsoNormal">Select the option ‘Wireless Toolkit 2.5’ (in older version it is called ktoolbar) and you should see the following windows coming up:</p> <p class="MsoNormal" style="text-align: center;" align="center"><!--[if gte vml 1]><v:shape id="_x0000_i1026" type="#_x0000_t75" style="'width:6in;height:183.75pt'"> <v:imagedata src="file:///C:/DOCUME~1/anoopks/LOCALS~1/Temp/msoclip1/01/clip_image002.jpg" title="wtk-screenshot"> </v:shape><![endif]--><!--[if !vml]--><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp1.blogger.com/_B0CuCDv4i18/RslZinfcnkI/AAAAAAAAAAw/3Vq02nqmN9Q/s1600-h/wtk-mainwin.JPG"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 440px; height: 188px;" src="http://bp1.blogger.com/_B0CuCDv4i18/RslZinfcnkI/AAAAAAAAAAw/3Vq02nqmN9Q/s320/wtk-mainwin.JPG" alt="" id="BLOGGER_PHOTO_ID_5100706504225103426" border="0" /></a><!--[endif]--></p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal">OK, now we have everything we need to get some Java ME gyan. Let’s start.</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <h2><span style="font-size:180%;">Java ME Basics</span></h2> <p class="MsoNormal">By saying Java ME, we refer to a number of classes, interfaces and a JVM that is needed to run a Java application on mobiles. To make things simple and to bring little peace to this chaotic world, these classes, interfaces and JVM are put into two layers: <b>Configuration</b> and <b>Profile. </b>Memorize these two jargon words; you will not regret doing it when you become ‘the el33t Java ME guru’.</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal" style="text-align: center;" align="center"><!--[if gte vml 1]><v:shape id="_x0000_i1027" type="#_x0000_t75" style="'width:174pt;height:124.5pt'"> <v:imagedata src="file:///C:/DOCUME~1/anoopks/LOCALS~1/Temp/msoclip1/01/clip_image004.jpg" title="javamelayers"> </v:shape><![endif]--><!--[if !vml]--><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp0.blogger.com/_B0CuCDv4i18/RslZ0XfcnlI/AAAAAAAAAA4/CCH8xpOH1Is/s1600-h/javamelayers.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 216px; height: 155px;" src="http://bp0.blogger.com/_B0CuCDv4i18/RslZ0XfcnlI/AAAAAAAAAA4/CCH8xpOH1Is/s320/javamelayers.jpg" alt="" id="BLOGGER_PHOTO_ID_5100706809167781458" border="0" /></a><!--[endif]--></p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <h3><span style="font-size:130%;">Configuration</span></h3> <p class="MsoNormal">This is the most underlying layer of Java ME and not surprisingly, it contains the “special” JVM also. Now why do we need a special JVM? Why can’t we reuse the existing JVM that we use in our desktops? The reason is simple: your mobile phone has less computational muscle as compared to a desktop computer. So it simply can’t run the bulky and mighty JVM from the desktop world.</p> <p class="MsoNormal">I said I was lying when I defined Java ME in the introduction. I said that Java ME is for creating java programs for mobile phones. Sure you can use Java ME technology to develop application for mobile phones, but its scope is not just limited to mobile phones. Java ME is currently used on a multitude device like pagers, set-top boxes, car navigation systems and a number of embedded systems. The only requirement to use Java ME is that the device should have some sort of connectivity: a powerful Ethernet connection or a weak wireless connection.</p> <p class="MsoNormal">There are two types of configuration:</p><ul><li><!--[endif]-->CDC and</li><li>CLDC</li></ul> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal">CDC stands for ‘Connected Device Configuration’ and CLDC for ‘Connected Limited Device Configuration’.</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal">CDC aims at devices that are a little bit more powerful than a mobile phone; devices like a Set-top box or a Car Navigation system. I have mentioned that configuration contained the JVM. The virtual machine in CDC is called CVM (Compact Virtual Machine). </p> <p class="MsoNormal">Mobile phones use CLDC as the configuration. The VM used in CLDC is termed KVM (K because it runs on Kilobytes of memory).</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <h4>CVM</h4> <p class="MsoNormal">This VM is a complete clone of the desktop Java JVM. It contains all the power, all the abilities of the former. Only difference is that it can run in a much-restricted environment: restricted memory, restricted computational power, restricted storage facility.</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <h4>KVM</h4> <p class="MsoNormal">This is a stripped down version of the desktop VM. It is designed for smaller device like a mobile phone and for a smaller memory footprint. It doesn’t support all features of conventional JVM like the object serialization, finalization etc.</p> <p class="Heading4"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal">In addition to the JVM the configuration also contains all the classes, interfaces and exceptions that Java ME subsets from Java SE. A list of all classes contained in CLDC can be obtained <a href="http://java.sun.com/javame/reference/apis/jsr139/index.html">here</a>.</p> <p class="MsoNormal">The configuration used in mobile phones is CLDC, and hence this will be our area of interest.</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <h4>CLDC</h4> <p class="MsoNormal">Some of the limitations of the CLDC are given below. A programmer need to be aware of such limitations to avoid serious trouble later on.</p> <ul><li>No floating point support.</li><li>No object finalization.</li><li>No JNI support.</li><li>No reflection.</li><li>No thread groups and daemon threads.</li><li>No application defined class loaders.</li><li>Implementation defined error handling.</li><li>Different form of class verification.</li></ul><p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <h3><span style="font-size:130%;">Profile</span></h3> <p class="MsoNormal">A profile extends the configuration. It adds domain specific classes to the core. It is geared towards a specific use of the device. For example, not every device need to have a screen. For devices that have one, the APIs to manage the screen is included in a profile.</p> <p class="MsoNormal">There are different types of profiles like MIDP, Foundation Profile, Personal Profile, Personal Basis Profile etc. The profile used in mobile phones is MIDP, and hence this will be our area of interest.</p> <p class="MsoNormal"><!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p></p> <p style="font-weight: bold;" class="Heading4">MIDP</p> <p class="MsoNormal">Mobile Information Device Profile extends the CLDC configuration. JSR 37 introduced MIDP 1.0, while JSR 118 introduced MIDP 2.0.</p> <p class="MsoNormal">MIDP 1.0 contained APIs for UI creation, local persistence mechanism, networking and MIDlet life-cycle management. (An application written using MIDP APIs is called a MIDlet). In addition to these, MIDP 2.0 added APIs for a robust security policy, APIS for sound and gaming and extended the networking APIs to include TCP socket streams, UDP datagrams, serial, push-initiated and secure connections.</p> <p class="MsoNormal">You may not know a lot of things said above. Don’t worry just read along. You will catch up in no time.</p>Anoop Engineernoreply@blogger.comtag:blogger.com,1999:blog-5209778108692585660.post-73636416412989567082007-08-13T11:50:00.000+05:302007-08-13T11:52:40.548+05:30How to make OpenOffice run faster in Ubuntu<p><strong><span style=";font-family:Verdana;font-size:85%;" > Some simple steps make OpenOffice snappier.</span></strong></p> <ul><li> <p><span style=";font-family:Verdana;font-size:85%;" >Go to <strong>Applications </strong>> <strong>Office </strong>> <strong>OpenOffice.org Word Processor</strong><br /> </span></p> </li></ul> <span style=";font-family:Verdana;font-size:85%;" > <img src="http://www.zolved.com/UserFiles/Image/28209/jpgspeedoff1.jpg" alt="" height="356" width="419" /><br /></span><br /><ul><li><span style=";font-family:Verdana;font-size:85%;" > The <strong>OpenOffice.org Word Processor</strong> is launched. Go to the <strong>Tools </strong>menu and select <strong>Options</strong>.<br /> </span></li></ul> <span style=";font-family:Verdana;font-size:85%;" > <img src="http://www.zolved.com/UserFiles/Image/28209/jpgspeedoff4%281%29.jpg" alt="" /><br /></span> <ul><li> <p><span style=";font-family:Verdana;font-size:85%;" >The <strong>Options </strong>window is opened.<br /> </span></p> </li><li> <p><span style=";font-family:Verdana;font-size:85%;" >Highlight <strong>Memory </strong>on the left panel, change the setting as shown below.</span></p> </li></ul> <span style=";font-family:Verdana;font-size:85%;" > <img src="http://www.zolved.com/UserFiles/Image/28209/jpgspeedoff3%282%29.jpg" alt="" height="402" width="468" /></span><br /><ul><ul><li> <p><span style=";font-family:Verdana;font-size:85%;" >Reduce the number of <strong>Undo</strong> steps to a figure lower than 100. Adelstein suggests <strong>20 or 30 </strong>steps.</span></p> </li><li> <p><span style=";font-family:Verdana;font-size:85%;" >Under <strong>Graphics cache</strong>, set <strong>Use for OpenOffice.org </strong>to <strong>128 MB </strong>(up from the original 6MB).</span></p> </li><li> <p><span style=";font-family:Verdana;font-size:85%;" >Set <strong>Memory per object</strong> to <strong>20MB</strong> (up from the default .5MB).</span></p> </li><li> <p><span style=";font-family:Verdana;font-size:85%;" >Set the number of objects under <strong>Cache for inserted objects</strong> at <strong>20</strong>.</span></p> </li><li> <p><span style=";font-family:Verdana;font-size:85%;" >Check <strong>OpenOffice.org Quickstarter</strong>.</span></p> </li></ul></ul> <ul><li><span style=";font-family:Verdana;font-size:85%;" >Now highlight <strong>Java </strong>on the left panel, uncheck <strong>Use a Java runtime environment</strong><br /> </span></li></ul> <img src="http://www.zolved.com/UserFiles/Image/28209/jpgspeedoff2.jpg" alt="" height="379" width="468" /><br /><ul><li> <p><span style=";font-family:Verdana;font-size:85%;" > Click the <strong>OK </strong>button and close <strong>OpenOffice.org. </strong>Start it up again to experience the change in speed!</span></p></li></ul>Taken from http://www.zolved.com/synapse/view_content/28209/How_to_make_OpenOffice_run_faster_in_UbuntuAnoop Engineernoreply@blogger.comtag:blogger.com,1999:blog-5209778108692585660.post-48197098521935484382007-08-09T09:41:00.001+05:302007-08-09T11:28:26.481+05:30Hacking OOo 2.0<a style="left: 0px ! important; top: 0px ! important;" title="Click here to block this object with Adblock Plus" class="abp-objtab visible" href="https://s3.amazonaws.com/slideshare/ssplayer.swf?id=15028&doc=hacking-ooo-20-14232"></a><object type="application/x-shockwave-flash" data="https://s3.amazonaws.com:443/slideshare/ssplayer.swf?id=15028&doc=hacking-ooo-20-14232" height="348" width="425"><param name="movie" value="https://s3.amazonaws.com:443/slideshare/ssplayer.swf?id=15028&doc=hacking-ooo-20-14232"></object>Anoop Engineernoreply@blogger.comtag:blogger.com,1999:blog-5209778108692585660.post-49893672470688150222007-08-08T16:27:00.003+05:302008-03-21T15:38:22.372+05:3010 things your IT guy wants you to know<div class="alert">Interested in posts like this? Head over to <a href="http://www.dailygyan.com">DailyGyan.com</a>. Much action is happening there now. <p style="margin-top:10px; margin-bottom:0; padding-bottom:0; text-align:center; line-height:0"><a href="http://www.dailygyan.com"><img src="http://feeds.feedburner.com/DailyGyan.1.gif" alt="Daily Gyan" style="border:0"></a></p></div><br />Note: This article was not penned by me. I found it <a href="http://thinksmarter.wordpress.com/2007/08/04/10-things-your-it-guy-wants-you-to-know/">here</a>. But, that blog has been deleted by the author. So I am recreating the post here. If anyone know the name of the actual author, please do let me know. I would be happy to give credits to him/her.<br /><br /><ol><li>If you ask me technical questions please don’t argue with me because you don’t like my answer. If you think you know more about the topic, why ask? And if I’m arguing with you…it’s because I am positive that I am correct, otherwise I’d just say “I don’t know” or give you some tips on where to look it up, I don’t have the time to just argue for the sake of it.</li><li>Starting a conversation by insulting yourself (i.e. “I’m such an idiot”) will not make me laugh, or feel sorry for you; all it will do is remind me that yes, you are an idiot and that I am going to hate having to talk to you. Trust me; you don’t want to start a call that way.</li><li>I am ok with you making mistakes, fixing them is my job. I am not ok with you lying to me about a mistake you made. It makes it much harder to resolve and thus makes my job more difficult. Be honest and we can get the problem resolved and continue on with our business.</li><li>There is no magic “Fix it” button. Everything takes some amount of work to fix, and not everything is worth fixing or even possible to fix. If I say that you just need to re-do a document that you accidentally deleted 2 months ago, please don’t get mad at me. I’m not ignoring your problem, and it’s not that I don’t like you, I just cant always fix everything.</li><li>Not everything you ask me to do is “urgent”. In fact, by marking things as “urgent” every time, you almost ensure that I treat none of it as a priority.</li><div class="alert">Interested in posts like this? Head over to <a href="http://www.dailygyan.com">DailyGyan.com</a>. Much action is happening there now. <p style="margin-top:10px; margin-bottom:0; padding-bottom:0; text-align:center; line-height:0"><a href="http://www.dailygyan.com"><img src="http://feeds.feedburner.com/DailyGyan.1.gif" alt="Daily Gyan" style="border:0"></a></p></div><li>You are not the only one who needs help, and you usually don’t have the most urgent issue. Give me some time to get to your problem, it will get fixed.</li><li>Emailing me several times about the same issue in the same day is not only unnecessary, it’s highly annoying. Emails will stay until I delete them, I won’t delete them until I’m done with them. I will typically respond as soon as I have a useful update. If it is an urgent issue, let me know (see number 5).</li><li>Yes, I prefer email over telephone calls. It has nothing to do with being friendly, it’s about efficiency. It is much faster and easier for me to list out a set of questions that I need you to answer than it is for me to call and ask you them one by one. You can find the answers at your leisure and while I’m waiting I can work on other problems.</li><li>Yes, I seem blunt and rude. It’s not that I mean to, I just don’t have the time to sugar coat things for you. I assume we are both adults and can handle the reality of a problem. If you did something wrong, I will tell you. I don’t care that it was a mistake, because it really makes no difference to me. Don’t take it personal, I just don’t want it to happen again.</li><li>And finally, yes, I can read your email, I can see what web pages you look at while you are at work, yes, I can access every file on your work computer, and I can tell if you are chatting with people on an instant messenger or chat room (and can also read what you are typing). <strong>But no, I don’t do it</strong>. It’s unethical, I’m busy, and in all reality you aren’t all that interesting. So unless I am instructed to specifically monitor or investigate your actions, I don’t. There really are much more interesting things on the internet than you.</li></ol><br /><div class="alert">Interested in posts like this? Head over to <a href="http://www.dailygyan.com">DailyGyan.com</a>. Much action is happening there now. <p style="margin-top:10px; margin-bottom:0; padding-bottom:0; text-align:center; line-height:0"><a href="http://www.dailygyan.com"><img src="http://feeds.feedburner.com/DailyGyan.1.gif" alt="Daily Gyan" style="border:0"></a></p></div><br /><a href="http://thinksmarter.wordpress.com/2007/08/04/10-things-your-it-guy-wants-you-to-know/">http://thinksmarter.wordpress.com/2007/08/04/10-things-your-it-guy-wants-you-to-know/</a>