Sunday, January 4, 2009

Java for the iPhone (without jailbreaking)

I bet you must be thinking, "What???, How is this is possible." I too was thinking the exact same thing when I came across this project. Running Java on the iPhone, or rather, building apps for the iPhone using Java is part of a larger project known as XMLVM (http://www.xmlvm.org) that utilizes XML as an intermediate language for cross-compiling at the byte-code level. Note that this cross-compilation is NOT at the source level. XMLVM cross-compiles byte code instructions from Sun Microsystem's virtual machine and Microsoft's Common Language Runtime. XMLVM can be used to cross compile .NET CIL, Ruby YARV and Java Byte Code to JavaScript, Python and Objective-C/C++


Details on Java for iPhone:
XMLVM operation begins with the byte code outputted from a regular Java compiler. Then, an XML version of the byte code is produced. This is then transformed into Objective-C using transformations on the original XML with the help of XSLT. What results is the same, functionally equivalent code in Objective-C. This can then be linked with libraries for UI (Cocoa) etc. to produce a native iPhone app.


XMLVM goes one step further. They have implemented Java counterparts of the Cocoa library components. This makes it possible to develop apps for the iPhone on Windows. The XMLVM project offers an iPhone emulator which is actually a Java Applet.


Example of the classic Hello, World app for the iPhone using Java:


public class HelloWorld extends UIApplication
{
public void applicationDidFinishLaunching(NSNotification aNotification)
{
CGRect rect = UIHardware.fullScreenApplicationContentRect();
UIWindow window =
new UIWindow(rect);
window.orderFront
(this);
window.makeKey
(this);
window._setHidden
(false);
rect.origin.x = rect.origin.y =
0;
UIView mainView =
new UIView(rect);
window.setContentView
(mainView);
UITextLabel _title =
new UITextLabel(rect);
_title.setText
("Hello World!, This is Earlence");
_title.setCentersHorizontally
(true);
mainView.addSubview
(_title);
}

public static void main(String[] args)
{
UIApplication.main(args, HelloWorld.class);
}
}


(adapted from XMLVM project site)

As you can see, development for the iPhone just got a little easier.

1 comment:

  1. Hi, there is another solution to develop in Java for iPhone, and it's called iSpectrum (!, yeah almost like your blog)
    It has garbage collection, an eclipse plugin and a debugger. More infos about features on their website : http://www.flexycore.com

    ReplyDelete