What is the best way to run Java code on the RP? Does installing the OpenJDK from the Debian/Fedora repos work OK? Are there tweaks one should use for improved performance? Also, is there a "light weight" JVM available for the RP which runs better/faster than the standard JVM from OpenJDK? If so, how is this obtained and installed?
-
1Note that OpenJDK does not have an ARM JIT yet, making it slow. – Thorbjørn Ravn Andersen Jul 28 '12 at 16:22
-
It appears that the ARM JIT by Oracle is not part of the OpenJDK. – Thorbjørn Ravn Andersen Dec 28 '12 at 11:20
7 Answers
For the "lightweight" part of your question, there are a number of smaller JVMs that you might want to consider.
For instance JamVM was originally designed to work in small systems like the RP and both it and Cacao (another smaller JVM) are available as packages in debian:
icedtea-7-jre-jamvm
icedtea-7-jre-cacao
though both use the open-jdk class libraries AFAIK, and its the class libraries that are the huge part (disk footprint wise) of installing a JRE.

- 286
- 1
- 4
Installing from the repositories should work fine on Debian:
sudo apt-get clean
sudo apt-get update
sudo apt-get install openjdk-6-jre
Java doesn't seem to be available on the Arch repo.
Can someone please edit with information for Fedora, I have no knowledge of that distro.

- 22,538
- 11
- 90
- 139
I've seen a lot of interest in running various cut down JVMs running on raspberry pi but few people have looked into compiling java straight to machine code. http://gcc.gnu.org/java/ hosts a compiler that can give you machine code from java or from java byte code. The project that I was going to get to use gcj for ended up being scrapped before it got off the ground but the compiler is billed as a good fit for embedded systems so it should suit the raspberry pi just fine.
Half way down the page in this forum there is a very nice graph somebody made comparing the relative performance of various JVMs as well as gcj http://www.raspberrypi.org/phpBB3/viewtopic.php?t=6330&p=124107. Keep in mind these benchmarks were made before the drastic performance increase included in the latest raspbian distro.

- 2,907
- 2
- 20
- 20
-
Now, six months later, do you have hands-on experience with doing this on the Raspberry? – Thorbjørn Ravn Andersen Dec 28 '12 at 11:20
There's no special lightweight JDK that I know of, but the normal openjdk from the repo seems to work ok-ish for me.
I say ok-ish - there's no problem with functionality per-se, at least none that I've found. That includes headful applications, Swing / AWT also seems to work well (haven't tried JavaFX.) Performance on the other hand isn't anything to right home about due to a lack of JIT (see this question.)
Oracle has graciously ported a version of Java 7 SE headless to the ARM for the Raspberry PI. I copied over class files from some of my non-EE console based code and it runs fine - but about 9 times slower than a Pentium IV at 3GHz. see http://eclipsejpa.blogspot.ca/2012/10/java-se-7-embedded-on-raspberry-pi.html
http://www.oracle.com/technetwork/articles/java/raspberrypi-1704896.html

- 31
- 2
I don't how it works with a JVM, but I know the ARM SoC on the Raspberry Pi can run the Java bytecode itself.
I don't have the Raspberry Pi to test JRE. So I speculate.
Use: cat /proc/cpuinfo/
and see if java could support the Raspberry Pi.

- 1,435
- 12
- 35

- 21
-
1This
java
flag in/proc/cpuinfo
means that the CPU support Jazelle extension. You can read about this on wikipedia. – Krzysztof Adamski Oct 05 '12 at 12:27 -
The problem with Jazelle is that none of the open source JVMs can use it. – Alex Chamberlain Oct 06 '12 at 09:30