Are Sun's Java 6 and OpenJDK 6 interchangeable? Check for yourself.

Printer-friendly versionPrinter-friendly version

Occasionally, when running Linux (and I'm doing this in the context of a 64-bit install of Ubuntu 10.04), you'll run across software that claims to officially support only Sun's Java, and not the standard OpenJDK that comes with Ubuntu (and, of course, other Linux distros). Do you need to take that warning seriously? Why not test it for yourself?

Again, working within the context of my Ubuntu system, install both the Sun Java 6 JDK and OpenJDK 6:

$ sudo add-apt-repository "deb lucid partner"
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk openjdk-6-jdk

now check which one is currently "active":

$ java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)

That's telling you that, at the moment, all invocations of Java will use Sun's JVM, but you can switch back and forth using the update-java-alternatives command.

First, list all of the JVM alternatives:

$ update-java-alternatives -l
java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
java-6-sun 63 /usr/lib/jvm/java-6-sun

At this point, you can switch to using OpenJDK and verify that that's the new active JVM:

$ sudo update-java-alternatives -s java-6-openjdk
update-alternatives: error: no alternatives for
update-alternatives: error: no alternatives for
update-java-alternatives: plugin alternative does not exist: \

And, yes, it's entirely possible that you'll get some errors since you might still need to install related packages to go along with whatever JVM you selected, but you can verify that you're now using your newly-selected JVM:

$ java -version
java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8) (6b18-1.8-4ubuntu3)
OpenJDK 64-Bit Server VM (build 16.0-b13, mixed mode)

At this point, resume running your software and, if it seems to work fine, you can continue using OpenJDK. If not, just switch back to Sun's Java.