Java Reference
In-Depth Information
Now that you have made sure the compiling environment is set up properly, you can start with the
sample application. Listing 1.1 contains the complete source code of the HelloCldc.java file.
Listing 1.1 Hello Cldc.java —The HelloCldc Sample Source Code
public class HelloCldc {
public static void main (String [] args) {
System.out.println("Hello CLDC.");
System.out.println("This application is running on a "
+ System.getProperty("microedition.configuration")
+ " JVM");
}
}
You now can compile the sample program using the following command:
Windows: j avac bootclasspath %CLDC_BCP% HelloCldc.java
Unix:
j avac bootclasspath $CLDC_BCP HelloCldc.java
The bootclasspath parameter is necessary because the program cannot be compiled with the
standard Java desktop libraries; it must access the CLDC and Kjava libraries.
If the compile command line does not produce any error message, you can perform the preverify
step:
Windows: preverify -classpath .;%CLDC_BCP% HelloCldc
Unix:
preverify -classpath .:$CLDC_BCP HelloCldc
This step is necessary to include verification hints in the class file, simplifying the class
verification on the target device. Future javac versions may have a switch to perform
preverification at compilation time, simplifying J2ME application development.
The preverify step creates a new subdirectory named output , where the preverified classes are
placed.
If the preverify step is successful, you can test the application with the command line kvm:
cd output
kvm HelloCldc
These commands change the current directory to the output directory containing the preverified
files and start the kvm with the new verified HelloCldc class. The following output will be
generated:
Hello CLDC.
This application is running on a CLDC-1.0 JVM
Hello MIDP
Similar to using the CLDC RI, the first step is to set up an environment variable pointing to the
MIDP library classes. The environment variable simplifies the following compilation steps and
helps avoid annoying problems resulting from typos in long path names:
 
Search WWH ::




Custom Search