Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

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?

share|improve this question
1  
Note 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 7

up vote 14 down vote accepted

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer
    
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.)

share|improve this answer

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

share|improve this answer

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.

share|improve this answer
1  
This java flag in /proc/cpuinfo means that the CPU support Jazelle extension. You can read about this on wikipedia. –  Krzysztof Adamski Oct 5 '12 at 12:27
    
The problem with Jazelle is that none of the open source JVMs can use it. –  Alex Chamberlain Oct 6 '12 at 9:30

Oracle released Java 8 (and Java 7) for ARM. Use the Link from this Page to get the currently best Java version for your Raspberry Pi.

This should also work:

sudo apt-get update
sudo apt-get install oracle-java8-jdk
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.