Solutions for writing Palm OS programs using Java

Source: Internet
Author: User
Tags arrays garbage collection

The realm of writing programs using the Java language for Palm OS is not completely unified, and there are a number of differences, and there are several different application interfaces available on the market, each of which provides varying degrees of access to the current Palm OS application. Perhaps the most familiar of these are the products produced by Sun Microsystems, but this is not the only product that can write programs for Palm OS.

One, Sun solution: KVM, Configuration and profile

The KVM is the kilobyte virtual Machine (Thousand-byte VM), and is named because its memory size is measured in kilobytes rather than megabytes as required by the Java Virtual machine. Because of such demanding memory requirements, KVM functionality is only a subset of the full JVM. You can find all the information from the JavaSoft site, but it is noteworthy that it omits mappings (reflection), JNI and custom class loaders, and a variable security mechanism.

Sun has developed a plan to provide configuration and profile to meet the needs of device programming. Configuration is an application interface designed to provide a foundation for a wide range of generic devices, all of which have similar characteristics, such as limited memory, occasional strong network connectivity, low power consumption and can run on batteries, so J2ME is designed to be both general and abstract. Now the Configuration available for Java 2 Micro Edition (J2ME) is CLDC (connected,limited Device Configuration) and CDC (Connected Device Config Uration, which is used for devices that are more powerful than palm, is beyond the scope of our discussion, and the former, which represents a limited-connection device configuration, is like a PDA, dual-channel pager, and a mobile phone. CLDC includes a subset of the classes in a j2se, but there are important differences, for example, because the garbage collection mechanism used by virtual machines in small devices, CLDC Java.lang.Object does not contain a Finalize method, you should remember that A particular class in this application interface may appear but one of its methods does not appear. Refer to the Application interface documentation, so you will know when to use the configuration.

For many friends who just started using the CLDC development program, it is strange that CLDC does not support floating-point numbers. This is the KVM default implementation, the KVM is written in C, it can be ported to many platforms, it does not support floating-point operations, because we are faced with hardware is generally small devices, and some use 8-bit processors, these processors may not support floating-point operations.

Profile is specifically specific, and its goal is a more specific device than configuration class, including user interface and event handling elements, which are not present in configuration. Now, the Palm OS or PDA has no publicly available profile.

The Java Community process has a PDA profile that has been developed for some time, and developers are still waiting for a new PDA profile version. At the same time, what should you do to follow the Kvm/sun solution Developer? The CLDC version includes a minimal set of classes that can be used as the most primitive profile for Palm OS, and it is learnt that sun does not approve of using these classes to develop any business programs, nor does it plan to make any updates to the application interface. But without PDA profile, developers can also use these libraries. Usually what we know is Kjava, which contains a lot of GUI classes: CheckBox, RadioButton, list, and so on. In addition to these, there is the Spotlet class, which is used to handle events and the Palm OS captures stylus input and keyboard press events, and so on.

The following is a class that uses Kjava to display simple text strings and buttons:

import com.sun.kjava.*;
public class HelloKjava extends Spotlet
{
  private static Button OKButton;
  public static Graphics g = Graphics.getGraphics();
  file://取得Graphics对象
  public static void main(String args[])
  {
HelloKjava hk = new HelloKjava();
  }
  public HelloKjava() file://HelloKjava类的构造方法
  { OKButton = new Button("OK", 84, 140);
register(NO_EVENT_OPTIONS);
drawScreen();
  }
  public void penDown(int x, int y) {
if (OKButton.pressed(x,y)) {
  System.exit(1);
}
  }
  public void drawScreen()
  {
g.clearScreen(); file://清除屏幕
g.drawString("Hello KJava",20, 10); file://把字符串画在屏幕上
OKButton.paint();
  }
}

There is also a class com.sun.kjava.Database, which is a way to reach the Palm database application interface. This means that it is very primitive and does not provide access to the full permissions of any content that exists in the Palm database. It only allows you to set and get a byte array; it does not allow you to type access except through the record identification number (an integer). Because the database can only understand byte arrays, giving your data means you need to parse these byte arrays into meaningful fields.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.