Content |
---|
|
Installing JDK ... |
---|
Firstly, goto "http://java.sun.com" and grab a copy of the latest JDK (notice: only J2RE will only allow you to run java apps, if you are going to developement MUST use a JDK).
Unzip it and put it in a folder, here we use "c:/java/j2sdk" as a default directory!
Then you have to setup an environment variable in order to make work.
Setting up environment variable for Java ...
Right click on "My Computer", select "properties"->"Advanced"->"Environment Variables", and you will see stuff like below:JAVA_HOME=C:\java\jdk1.2.4_01 (refer to path where you install the Java sdk)
PATH= ... ;C:\java\jdk1.2.4_01\binInstalling J2ME Toolkit ... |
---|
This may be as simple as it seems, just goto j2me download site, pick a copy of " Sun Java Wireless Toolkit" ... install it and start coding. Note that you may have a few choice either using an IDE like NetBean, JBuilder, and so on; to the build-in code writing module with the WirelessToolkit that you just downloaded or even start off with a Notepad!
Well my personal favor, a Notepad will do, try compiling with command prompt also, had a better feel of the whole development process.
Testing ... |
---|
Six simple Steps for writing a J2ME:
- Code a Java file.
- Compile with CLDC and MIDP library.
- Preverify it with "preverify.exe".
- Write a manifest file, then package it with every classes and resources in a JAR file.
- Write a JAD file for deploying purposes.
- Test it on emulator or real device, do some performance tweaking and fine tuning for portability.
- Some assumption:
- %J2ME_HOME%=C:\WTK22\
- %JAVA_HOME%=C:\Program Files\Java\jdk1.5.0_04
Writing a simple CLDC app...
import java.io.*; |
Writing a simple MIDP app...
import javax.microedition.lcdui.*; |
To Compile your codes:
%JAVA_HOME%\bin\javac -bootclasspath %J2ME_HOME%\lib\midpapi20.jar;%J2ME_HOME%\lib\cldcapi.jar MyJ2MEApp.java
To Preverify your class:
%J2ME_HOME%\bin\preverify.exe -classpath %J2ME_HOME%\lib\midpapi20.jar;%J2ME_HOME%\lib\cldcapi.jar MyJ2MEApp
Writing a Menifest file:
MIDlet-Name: MyJ2MEApp |
To Package everything:
%JAVA_HOME%\bin\jar cvfm MyJ2MEApp.jar Manifest.mf MyJ2MEApp.class
Writing a Java Application Describtion (JAD) file:
MIDlet-1: MyJ2MEApp, , MyJ2MEApp |
*Important notes - remember to fill in the MIDlet-Jar-Size with a correct file size of your jar (e.g.:MIDlet-Jar-Size: 1469)*
To Test your application:
%J2ME_HOME%\bin\emulator.exe -Xdescriptor MyJ2MEApp.jad
Hooray, it is working!!!
Resources:
- Tutorial from java.net.
- Sample code from sun developer.
Comments