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?
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:
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.
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.
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.
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
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
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.
cat /proc/cpuinfo/ and see if java could support the Raspberry Pi.