Today Oracle has released the first JavaSE 8 + JavaFX Developer Preview. This is really exciting for anybody who’s wanted to try out the $35 Raspberry PI ARM mini-computer (and I do mean mini!). Incidentally, anybody who picks one up really needs to get the Pi-Bow enclosure for the PI — I got one yesterday and highly recommend it!
JavaSE is a HotSpot based VM, so it is really quite zippy. I did some timing calculations on my PI this morning based on the prime number test provided in this Raspberry PI Java forum posting. Yes, there is a new Java category on the Raspberry PI forums, do visit and leave your experiences there :-). Anyway, I ran both Java and GCC version 4.6.3 with -O2 performance optimization enabled.
|JavaSE 8 (build 1.8.0-ea-b36e)||0m7.830s||0m4.970s||0m2.840s|
|GCC 4.6.3 (Debian 4.6.3-12+rpi1)||0m7.716s||0m4.990s||0m2.700s|
|GCC 4.6.3 (Debian 4.6.3-12+rpi1) -O2||0m6.361s||0m3.940s||0m2.400s|
I find the results really impressive, because basically the difference seen between Java and native is just due to the startup costs. Which means that Java is a really great choice for developing applications that will run on the Raspberry PI. Java also represents (to my knowledge) the first VM stack to optimize for hard float on ARM v6.
I couldn’t help myself though, I cranked up the test to find all prime numbers below 50,000 to see if the startup costs in fact are the difference between the JVM and native code. Below are the results. As you can see, HotSpot is faster than native code!
|JavaSE 8 (build 1.8.0-ea-b36e)||1m37.808s||1m25.570s||0m12.000s|
|GCC 4.6.3 (Debian 4.6.3-12+rpi1)||2m18.875s||2m7.390s||0m11.1300s|
|GCC 4.6.3 (Debian 4.6.3-12+rpi1) -O2||1m42.166s||1m31.206s||0m10.580s|
I wrote a quick JavaFX application this morning and tried it out. A couple things to make sure you note!
- jfxrt.jar is not on the classpath by default (yet). So be sure to include it!
- -Djavafx.platform=eglfb must be specified. If not, it won’t run.
- Ahem. There appears to be no way to kill an FX app, unless you can SSH into your box or switch to another terminal. Or have your app make sure it has an exit button. But then, when playing BrickBreaker, who’d ever want to stop?
None of the flags used in javaFX on the command line are “public API” and may go away in the future, but this particular flag is likely to be around for a while. It lets you choose which version of glass to run with. On Raspberry PI, right now, the only option is eglfb (which makes you wonder why we require you to specify it on the command line. There are some questions that we just shouldn’t ask ;-)). Basically EGLFB runs OpenGL on the frame buffer directly, meaning that it wants to own the entire screen. This is great for Kiosks and media centers and such, but not so good for normal X11 usage. Hopefully the X11 usage shows up sometime soon, but in the meantime, JavaFX will own the display.
You should go read the developer preview documentation and also Stephen Chin’s blog on PI. JFokus has a Raspberry PI hands on lab, which is already fully booked, but I’m betting you can get Simon Ritter to give you some material if you want to try at home :-).
Have fun hacking over the holidays!
Excellent news. Hard-float Java with JavaFX. I can’t wait to try it out. 🙂
Is there any support for GPIO? Or is it planned?
We’re not doing anything special with GPIO, I wouldn’t be surprised if there were a Java library around though for it.
i think pi4j is the lib you are search for…
Just to make sure, having jdk8 in Mac OS X Mountain Lion wouldn’t conflict with current JDK7 ?
It will install side-by-side with it, and you ought to be able to which JDK you want to use via the control panel. YOu can always remove a JDK by removing it from /Library/Java/JavaVirtualMachines
Is this running on the Raspbian Distro of Debian ?
Yes. I was running off the latest Raspbian as of two days ago.
FYI, I followed the instructions at the url below & do not have to add jfxrt.jar to the classpath.
Where is the video that demonstrates the great performance on Pi? I’d really like to see the actual proof that this is going to be viable.