Zaurus Java FAQ
From OESF
Main
Where did this Java FAQ come from?
- This FAQ has been contributed by Gerald J. Normandin Jr.
It has been found at http://adorphuye.com/zaurus/java/faq.jsp
The original author of this FAQ is Steph Meslin-Weber, mailto:twiun@adorphuye.com. A fair number of people have also contributed in various ways by providing information, links or criticism:
- All the fine folks on the [zaurus-java] mailing list
- Andrew Girow
- Gurminder Khamba
- Jim Huang
- John Barrus
- Pierre MÈ tras
- Rehana Ramzan
- Steve Weyer
- Steve Yegge
- didge
- Leticia Golubov
- Peter Harverson
Java Extensions
What extensions?
- Java language extensions provide added functionality to the core Java api.
When Java 1.1 was released, additional extensions (Swing, Collections) were also released to make up for gaps in the api coverage.
As each new Java version ships, these extensions get included into the core api. Currently on the Zaurus, only PersonalJava 1.2 - equivalent to Java 1.1 - is available, and so we start looking at the api extensions for extra functionality
Can I use Secure Sockets on the Zaurus?
- Thanks to Steve Weyer for providing this answer. So, at the expense of a bulky library, we can indeed use JSSE on the Zaurus.
From Steve Weyer:
(non JSSE things snipped)
regarding extensions, Sun's JSSE (Java Secure Socket Extensions) 1.0.2 works fine with PJ on Z. this allows https: connections among other things. I've used with my CrozzWord app for secure login to NYTimes subscription area. downside: it's ~420K
Can I use SVG on the Zaurus?
- Yes, it is now possible to use SVG on the Zaurus and indeed, on any J2ME/PersonalJava VM. I have tested TinyLine 1.2 on the Zaurus using the demo kindly sent to me by Andrew Girow and can say that it performs very well. Downloads for this latest version of TinyLine are available from the TinyLine website.
Here are a few screenshots to give you an idea of the demo:
Can I use Swing?
- Before reading the answer consider this: Swing uses floating point coordinate systems and transformations - the Zaurus is based on the ARM SA-1100 chipset which does not have a floating point unit. The net result is that any floating point operation has to be emulated and that's very slow.
Short answer: No.
Long answer: Swing can be used on the Zaurus with the Jeode VM but you must use the unbundled Swing distribution1 and you must edit SwingUtilities.java in that distribution. This is due to a Swing bug2 that will not be fixed by Sun. Also note that certain parts of Swing use native code which is currently unavailable for the ARM platform; this means parts of Swing will not work.
Note: Because of the Sun License, I cannot redistribute modified Swing sources or jar files.
Instructions taken from the bugparade report2:
1. Extract the src.zip (from the swing-1.1.1fcs distribution). 2. in javax/swing you'll find the SwingUtilities.java file. 3. Open it your favorite editor 4. Comment out line 677:
Method m = Class.class.getMethod ("getProtectionDomain", null);
5. Insert the line
Method m = Class.class.getMethod ("getPackage", null);
just after the old one.
6. Save and compile (javac -classpath swingall.jar:. javax/swing/SwingUtilities.java)
7. Backup the Swingall.jar archive in the root of the exstracted src.zip (ie the same level of the javax and com dirs).
8. Jarize it (jar uvf swingall.jar javax/swing/SwingUtilities.class)
11Unbundled JFC 1.1 with Swing 1.1.1 (http://java.sun.com/products/jfc/download.archive.html)
2Bug Id #4309057 (http://developer.java.sun.com/developer/bugParade/bugs/4309057.html)
Can I use JDBC?
- At the present time, it's not certain wether PersonalJava can be used in conjunction with the [http://java.sun.com/products/jdbc/download.html#specJDBC 2.0 standard extension from Sun...
More info as it comes in!
Miscellaneous
What Classes can I use?
- Jeode supports the PersonalJava 1.2 Specification (http://java.sun.com/products/personaljava/). As this specification is compatible with jdk1.1.8, you can make/port your program using the jdk1.1 classes.
(It is apparently still possible to use JNI, obviously, use at your own discretion)
NOTE: This excludes all the J2SE Classes (Swing, JMF, JAI, etc)
What graphic file formats does Jeode support?
- The PersonalJava spec only requires gif, jpg and png support for compliance and so those formats are supported to some degree.
GIF | JPG | PNG | |
Paletted | |||
TrueColour | |||
Lossless | |||
Transparency |
Can I develop ON the Zaurus?
- Absolutely!
The build-in keyboard makes this an ideal use for the Zaurus, although you'd probably be faster on a desktop machine. The keyboard on the Zaurus is not, in my opinion, intended for writing novels ;-)
Because of the limited memory footprint of the Zaurus you shouldn't expect to be able to run, say, NetBeans, but with an editor and a compiler you should be set to go!
So far, compilers that run on the Zaurus include Kopi and Jikes.
Editors can include:
- EIDE (http://www.javaconsultants.net/eide/) a small Java ide for the Zaurus
- Built-in Text editor
- Built-in VI
- tkcEditor (http://www.thekompany.com/embedded/)
- kVim (not available yet)
Additionally, Pierre MÈ tras has written a HOWTO based on MinIDE+Kopi at http://www.alterna.tv/jsearch/ (http://www.alterna.tv/jsearch/). As this HOWTO is in French, I'm in the process of translating it into English - should be finished in a few days. (Current translation at here (http://adorphuye.com/~twiun/D%e9veloppement%20Java%20sur%20le%20Sharp%20Zaurus.html))
Can I play sounds using Java?
- Previously, people did not seem to have had any success using the normal Applet.play() methods, having limited success using the undocumented and unsupported sun.audio and writing directly to the /dev/dsp device using a FileOutputStream (thanks Ralph Curtis, John McDonnell and Henry Gunst).
This is now changing, with thanks to didge for the information:
I have been able to use the Java Media Frameworks to play sounds on my SL5500. Here are instructions:
Using JMF2.1.1b (the cross-platform version) to play .wav files on the Zaurus can be achieved by doing the following:
Create your own custom.jar (using JMFCustomizer w/ jdk1.4). Check the following items:
- Media Source: Media Files, RTP Receive
- Media Sink: Play
- Optional Component: Player bean
- Protocol: file, rtp
- Source Media Formats: Wav
- Decoder/Audio Decoders: none
- Decoder/Video Decoders: none
- Encoder/Audio Encoders: none
- Decoder/Video Encoders: none
- DePacketizer/Audio DePacketizers: none
- DePacketizer/Video DePacketizers: none
- Packetizer/Audio Packetizer: PRTP_MP3/2
- Packetizer/Video Packetizer: none
- Audio Renderer: SunAudio
- Video Renderer: none
Make sure that custom.jar and jmf.properties are located in your classpath. Additionally, you will need to start Jeode with the following arguments:
- -Djeode.evm.memory.overallSize=5m
- -bootclasspath #SYSTEM#:$CLASSPATH
The first increase the memory for jeode. The second ensures that the JMF custom.jar is loaded correctly. #SYSTEM# is a standin for Jeode's class libraries and the s ensure that the shell does not consume the #s before evm gets the argument.
Any caveats or things I should watch out for?
- There are a few things to watch out for when developing or releasing for the Zaurus...
- Watch that ipk filename! It should be all lowercase and follow the naming conventions that ipkg-build warns you about.
- Images in memory are in 16bpp... bear that in mind when loading them for display. Use tiling and progressive loading to save on memory as images such as (one screen full) 320x240x16bpp = 153kb, (digital camera resolution) 1600x1200x16bpp = 3,840kb!
- Ensure that the control file in an ipk has the all the required fields, it won't show up otherwise!
- Use unix newline characters to terminate lines in control/.desktop/script files! (unix='n', windows='nr') (thanks to Ralph Curtis)
What class libraries are available for the Zaurus?
- There are a few class libraries available for the Zaurus, and indeed for PersonalJava and J2ME. As a rule of thumb, the majority of Java 1.1 libraries will work without problem - this is of course not taking performance or size into consideration.
Lightweight AWT GUI toolkits (or why be stuck with AWT?)
- Thinlets (http://thinlet.com/) (~24k, slow, attractive)
- ICEToolkit (http://icesoft.com/) (~120k, slow)
- Dog.Gui (http://dog.net.uk/knife/gui.html) (~356k, fast)
- [1] (http://www.cc.gatech.edu/gvu/ui/sub_arcticSubArctic) (sluggish)
- KFC (http://openlab.ring.gr.jp/kyasu) (~570k, fast)
- Zaval lwvcl (http://www.zaval.org/products/lwvcl) (~130k, fast)
XML Parsers (or why make do with properties files?)
- kXML (http://kxml.org/)
- nanoXML (http://nanoxml.n3.net/)
- microParser (http://sourceforge.net/projects/microbrowser/)
- TinyXML4J (http://sourceforge.net/projects/tinyxml4j/)
- Xparse-J (http://sourceforge.net/projects/xparse-j/)
- XMLtp (http://mitglied.lycos.de/xmltp/)
- MinML (http://www.wilson.co.uk/xml/minml.htm)
- MinML2 (http://www.wilson.co.uk/xml/minml2.htm)
- ASXMLP (http://www.alsutton.com/software/xmlparser/)
- TinyXML (http://www.gibaradunn.srac.org/tiny/)
Databases (or why settle for flat files?)
- Hypersonic SQL (http://hsqldb.sourceforge.net/) aka hsqldb (~110k, Java1.1/1.2, JDBC)
- SQLite (http://www.ch-werner.de/sqliteodbc/) (native ODBC bindings)
Cryptography (or why keep things simple?)
- LBC Crypto library (http://www.bouncycastle.org/)
Problems with java.util.Date & Co.
- I recently got some questions regarding this, and here are some snippets from the ZaurusZone forums, from the user kevinlong - when the forums are back online, I'll also provide a direct link:
Posted: April 21 2002,19:21
It appears there maybe a problem accessing the time on the device. I've tried using both the Date() and the GregorianCalendar() classes.
This problem appears to be dependent on which city you select. For example, if you select Chicago or Los Angeles, the time appears to return correctly. However, if you select a city such as Kansas City, Oslo, Hong Kong, the time returned is the GMT time instead of the local time. In other words, the GMT time and local time are the same. When you query the time zone offset, it is 0.
I should note that the time always appears correctly in the sytem tray on the device.
Any ideas?
Posted: April 25 2002,03:19
I have been exchanging emails with Sharp (Japan). They have located the problem in the Insignia code. They are waiting on a fix or work around from Insignia.
In short, Java supports a much smaller list of cities than the Zaurus. When a city isn't found, it defaults to GMT for the time zone. Oooops!
I will post an update when I get a final response from Sharp and Insignia.
Posted: May 11 2002,23:58
I have heard back from Sharp regarding this problem. Insignia has stated they only support the following cities: Africa/Casablanca Europe/Paris Africa/Cairo Asia/Riyadh Asia/Tehran Asia/Yerevan Asia/Karachi Asia/Calcutta Asia/Dacca Asia/Bangkok Asia/Shanghai Asia/Tokyo Australia/Darwin Australia/Sydney Pacific/Guadalcanal Pacific/Fiji Pacific/Apia Pacific/Honolulu America/Anchorage America/Los_Angeles America/Denver America/Chicago America/New_York America/Caracas America/St_Johns America/Buenos_Aires America/Sao_Paulo Atlantic/Cape_Verde America/Costa_Rica Asia/Beirut Africa/Johannesburg Asia/Jerusalem Europe/Moscow Asia/Vladivostok Australia/Hobart
Sharp has told me that Insignia does not plan to fix it. Even though they are under contract to Sharp, Sharp is not going to press Insignia to fix it.
If you would like this fixed, I would recommend that email is sent to both Sharp and Insignia. The developer support email for Sharp is kpda_pt@pda.nara.sharp.co.jp. I could not find a support email for Insignia.
Hopefully, if enough people complain, they will get this problem fixed.
I agree that this is an issue that should be resolved. The Zaurus is after all an international device.
Can I learn Java on the Zaurus?
- Like all things, this is of course possible BUT:
One thing I'd like to make clear is that I don't think any PDA is suitable for learning Java (and quite likely other languages).
You need a flexible environment and be able to debug, type and browse documentation easily and fast. You won't be able to do all that on a PDA.
The Java tutorial at Sun isn't a 400-page book, it has valid examples for you to work with and very good explanations, as well as instructions on getting Java working on the desktop OS of your choice: http://java.sun.com/docs/books/tutorial/index.html (http://java.sun.com/docs/books/tutorial/index.html)
Java on the Zaurus is still pretty much stuck at version 1.1, this means that once you've learnt the Java syntax, get hold of a 1.1 Java sdk and use this for development on your desktop. It's of course possible to use later versions for this, but doing so may lead to more headaches further on.
I, like most others, do my Java development on the desktop in any case - the compiled code will (should) run without modification on the Zaurus if you work within the Java 1.1 specs. So there isn't a dire need for tools for use on the Zaurus. This is not to say there aren't any - there are quite a few: 2 compilers, 2 virtual machines (2 more on the way), 3 IDEs and countless class libraries that work perfectly fine on the small form factor.
So with regards to development tools for use on the Z, I'd say hold on, learn Java first :-)
I heartily recommend the #java channel on irc.freenode.net for help with learning Java, make sure you've read the Java tutorial first though - you'll get flak if you don't ;-)
Packaging
How do I arrange sources/classes prior to packaging?
- Your sources can be packaged pretty much any way you fancy, hopefully keeping to the Sun naming convention (http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html#367) for packages and classes ;-) Be sure to include all dependencies which aren't covered by the PersonalJava specification.
Compiling your classes should be done with a pre-Java 1.4 sdk, or using the -target 1.1 command line argument for the compiler to specify that compiled classes should follow the Java 1.1 class file structure (and version).
Your compiled classes should be contained in one or more jar files to save on space and filesystem clutter.
How do I package using the .ipk format?
- Packaging applications/applets for distribution and eventual use on a Zaurus is a painless task, using the ipkg-build tool1. Packaging your program starts by populating a predetermined directory tree structure with the appropriate files:
CONTROL
_ <-- package control files
opt
_QtPalmtop |_bin <-- application start script |_apps | |_Applications <-- application .desktop entry2 | |_Games | _Settings |_java | _myapp <-- application jar (+html file for applets) |_etc | _myapp <-- application configuration files |_pics <-- application icon | _myapp <-- application image resources _help _en <-- application help files (english)
Please read this document to learn how to make an .ipk file package.
The java application start script cannot be passed command line arguments from the .desktop file and so must be self contained. It can be conceivably called anything you want. The current convention is to use the run prefix, eg: runSomeCommand
IMPORTANT Your application does not have be installed in RAM, it could be installed on CF or SD media - this means that paths to resources must not be hard-coded. Thankfully, the Qtopia environment provides a means to find out where installation took place so that we can find our resources.
Your application image should be a 32x32 png file. Although you are free to name it anything, try to use a name which will associate it with your application. Qtopia will resize it as necessary for the taskbar.
Application configuration files are usually stored in a subdirectory of the etc directory such as etc/myapp.
Example .desktop file myapp.desktop
[Desktop Entry] Comment=This is MY program Exec=runmyapp Icon=myappicon Type=Application Name=MyApplication
Example start script runmyapp
#!/bin/sh # # Change to the java directory where we're installed cd ${PKG_ROOT}/opt/QtPalmtop/java # # Populate classpath with our application jar CLASSPATH=somejar.jar # # Launch the virtual machine (using the -Xappname argument so that we appear # on the tasklist - see Qtopia Integration section) evm -cp $CLASSPATH -XappName=runmyapp mainClass
if launching an applet, substitute the last command with:
$QPEDIR/bin/evm -appletviewer myHtmlpage.html
Qtopia Integration
How well is Java integrated into Qtopia?
- In terms of looks, rather well... components look like they belong, they change shape dynamically on theme changes, but unfortunately don't change colour. Theme changes that occur before the Java VM starts will take effect without problem.
Can I use the full screen area?
- The Jeode VM provided on the Zaurus implements the PersonalJava 1.2 spec (equivalent to jdk1.1.8). It is therefore not possible to achieve the following aims through 100% Java methods and purely programmatic means:
- Fullscreen rendering (Java 1.4)
- Maximised Frames/Windows (Java 1.4)
- Iconised Frames (Java 1.4)
How do I get the button to show?
- Helpfiles can be written in normal html, taking care to keep the small screen format in mind.
To have the button show up on your application titlebar, all you need do is name your main html file the same name as your application, so with an application named runmyapp your main html file would be called runmyapp.html.
The reason for this naming convention is that when your script calls the virtual machine, the -Xappname argument is used with your application name as the parameter, this name is then used for the taskbar icon and... you guessed it, the main helpfile.
This html file (and all the others you need) should be placed in the
/opt/QtPalmtop/help/en/html
directory, replacing en with any other language code as necessary.
If your html pages require images, you should link to them using relative URLs. You can place your images in subdirectories, as long as the url is relative.
Can I run my application maximized?
- The only way to run apps maximized is to set their size to the size of the screen.
Note that the application can unfortunately still be dragged and moved! Using a Window and sizing to the size of the screen is not a solution as it is not possible to programmatically position the Window at 0,0 in the Jeode VM. The Jeode VM will shift your Window down by the height of a titlebar even if none is present.
Why doesn't my application have a taskbar icon?
- The taskbar icon (white icon highlight added for emphasis) which is visible for all applications under Qtopia doesn't use any of the normal JAva API or extensions. To get this icon to appear, you must provide a (non-standard, as indicated by the X prefix) commandline argument to the VM.
evm -XappName=myAppName
When called from a script, as is necessary for Java applications, the following shorthand can be used:
#!/bin/sh evm -XappName=$0
Where the $0 refers to the zeroth commandline argument, namely your script name.
User Interfaces
What should I consider when making a GUI for the Zaurus?
- Writing GUIs for the Zaurus must take three important aspects into consideration. The lack of a mouse, the small screen size and the very limited amount of memory available.
The lack of a mouse means that you will get no MouseEntered or MouseExited events and therefore no Tooltips or rollover effects.
The small screen size is perhaps the more important factor when designing an application for the Zaurus. Information that could have fitted on one screen on a normal sized screen now has to be distributed amongst several forms. You can achieve this using CardLayouts or TabbedPanes, bearing in mind that with each additional component you add will increase your memory footprint. </ul>
Any tips for creating my application's icon?
- Certainly! To begin with, some requirements:
- Size: 32x32, with convention insets being top=2,left=2,bottom=3,right=3
- Shadow: Icons provided by default have a 3 pixel SE drop shadow (within the insets)
- Depth: 24bpp
- Format: png with alpha channel
The insets usually contain the drop-shadow in the south-eastern direction. The drop-shadow is a black underlay with an alpha gradient - easily obtained in Gimp.
How can I make use of the button in my application?
- This button is equivalent to the close window button on all other platforms, and as such it requires the same handling. Thanks to didge for the really constructive comments and information:
Since memory is expensive, creating a listener to close a frame is wasteful. Instead, I would suggest creating a subclass of Frame with the desired behavior:
public class MyFrame extends Frame { public MyFrame() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); } protected void processWindowEvent(WindowEvent e) { if(e.getID() == WindowEvent.WINDOW_CLOSING) System.exit(0); } }
The above raises the point that too often listeners are used when subclassing and using processEvent would eliminate extraneous object creation, not to mention would perform faster as well. Note that using a listener not only means you have to have a the listener, but AWT use the AWTEventMulticaster which incurs additional overhead. But of course, this is an optimization for where it's appropriate.
Usual (desktop) way of doing things:
Frame myFrame = new Frame("SomeTitle");
myFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } });
What fonts can I use on the Zaurus?
- Qtopia as installed on the Zaurus does not support TrueType fonts, so only prerendered fonts in the .qpf format (See Font Issues) can be used.
Additionally, Jeode on the Zaurus has broken generic font support so that font names must be explicitly specified. For instance, using the smoothtimes font preinstalled on the Zaurus, one would create a font thusly:
Font f = new Font("smoothtimes", Font.PLAIN, 10);
Fonts that come preinstalled on the Zaurus are:
- fixed
- helvetica
- micro
- smallsmooth
- smoothtimes
You can also create your own fonts, or convert TTF fonts, see the Font Issues faq entry for more information.
(Font Issues) How can I use fonts on the Zaurus when using Jeode?
- You can get around the problem of the supplied Jeode VM on the Zaurus not recognising fixed width fonts by using the font's proper name, for example:
Font f = new Font("fixed", Font.PLAIN, 10);
TrueType font support isn't compiled into Qtopia for the Zaurus so you have to use what's already there in /opt/QtPalmtop/lib/fonts/*.qpf, or you have to provide your own by using the qpf build tools present in the Qtopia source distribution (Trolltech, qpf fonts defined).
Using the above for custom fonts, you would create your qpf font, place it in the /opt/QtPalmtop/lib/fonts directory on the Zaurus and use the following code:
// Assuming the font is named kanjifont_100_50_t10.qpf
Font f = new Font("kanjifont", Font.PLAIN, 10);
How can I use the GridBagLayout on the Zaurus?
- The multiple-argument consstructor of GridBagConstraints used by GridBagLayout only became public with Java 1.2. To make use of it under PersonalJava1.2/Java 1.1, you need to resort to the following ploy:
GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx=1; gbc.gridy=10; ... //access private fields directly SomeContainer.add(SomeButton,gbc); gbc.gridx++; SomeContainer.add(SomeLabel,gbc);
The GridBagLayout makes a copy of the constraints passed to it via the add method and uses that to layout the button/label or Component. Because a copy is used internally by the layout, you're free to keep on modifying your version for subsequent layout additions.
Please note that GridBagLayout uses floating-point math operations heavily1, is a complex layout and as such will be less performant than a simpler, integer-based one.
Virtual Machines
What virtual machines exist for the Zaurus?
- As the Zaurus is still an immature platform, there are currently only a few of publicly available virtual machines. Here are some virtual machine vendors in no particular order:
- Jeode from Insignia (PersonalJava1.2 only, bundled with Zaurus) Sold to Esmertec
- Blackdown from Blackdown (J2SE, ARM-platform, not Zaurus specific)
- (DEAD) XOE from Transvirtual (available from Kaffe.org ftp here)
- Intent from the Tao Group (PersonalJava1.2, ROM replacement)
- J9 from IBM (bundled with their J2ME sdk) No ARM gui libraries available at the moment
- J2ME from Sun Microsystems (J2ME, available on request)
- Wonka from Acunia (Java2, Source/Binaries, directfb/headless)
- PERC from NewMonics Inc.
- Kaffe from Kaffe.org.
- Waba from WabaSoft.
- Ewe from EweSoft.(based on Waba)
- JamVM from JamVM.(ARM port in progress)
Is J2ME supported on the Zaurus?
- The J2ME virtual machine is now available from Sun Microsystems, albeit with severe restrictions as it is not on general release:
Note that this software is for evaluation only; it is not supported and cannot be used in a product. This release is for you if you are interested in the leading edge of Personal Profile technology and would like to see a high-performance, optimized implementation.
Is J2SE available for the Zaurus?
- Although SavaJe provide a complete J2SE 1.3.1 implementation for the ARM platform and is available for the Compaq Ipaq, it has not been ported to the Zaurus.
Blackdown also seems to have an ARM port of its Java 1.3.0 virtual machine present on its mirrors. Note that this vm will most likely have the native peers working under X, not Qtopia.
Installation of Java on unsupported Zaurii
Installation of Java on the SL-C3000/C1000
Currently, it is not officially supported to install Java on the SL-C3000. However, some enterprising soul found a way to do it, but this includes getting your hands on a SL-C860. The whole process is not really difficult if one follows the instructions posted here (http://augustin.vidovic.org/pages/java_on_zaurus_sl_c3000/index.html).
Followed these instructions to also install Java on an SL-C1000, worked like a charm.