tags:

views:

6982

answers:

7

I recently purchased a new laptop and made my old one into a Linux box, running Ubuntu. I started to download the tools that I need, and I'm getting my Java development environment set up now. I have a choice between the Sun Java 6 JDK and the OpenJDK.

What advantages does one have over the other? Can I run both side by side?

A: 

OpenJDK will give you new features faster, Sun JDK should give you more stability.

fuzzy lollipop
Citation needed.
Dave Jarvis
+9  A: 

Get Sun JDK. It's the most robust/stable of the two. The OpenJDK may expose bugs which may cause "unexplainable" behaviours in the code as opposed to the Sun JDK. You don't want to have that. You can run them side by side, but that would not make much sense, unless you intend to develop with/for a specific JDK.

BalusC
This is what I have done - installed the Sun JDK. However, if someone presents compelling reasons as to why I should use the OpenJDK, I might switch and change accepted answers.
Thomas Owens
OK, come back after a year or so. OpenJDK has a long way to go yet.
BalusC
OpenJDK is something like 99% identical to Sun Java 1.6 (I think its more actually). Really, you can't compare GCJ and OpenJDK.
Pascal Thivent
Are GNU JDK and OpenJDK two different JDK's? At least, I've seen enough weird problems in particularly the JDBC and networking area when someone was developing in Ubuntu with the "other than Sun" JDK installed and those problems went away when the Sun JDK was installed/used.
BalusC
6-open is actually a backport of an early build of JDK7. Some libraries had to be replaced due to license issues, so it is, I believe, somewhat less than 99% identical. (GCJ and CLASSPATH are quite different.)
Tom Hawtin - tackline
To me, GNU JDK (not sure it even exists BTW) sounds like http://gcc.gnu.org/java/ and OpenJDK like... OpenJDK. So this may just be a misunderstanding on my side. Regarding bugs, some OpenJDK builds were indeed buggy but things are moving so fast that its IMHO hard to claim that yesterday's problems still apply today.
Pascal Thivent
Okay, but it is moving so fast with years because the kind of bugs it has really needs to be fixed "asap". Sun is solid and doesn't need much "high prio" bugfixing and is therefore also not much "moving". It however comes with fairly regular updates, about once a month, which is imho just enough. Although I am an Open Source fan, I would rather prefer the constructor's own JDK above any "3rd party" JDK.
BalusC
OpenJDK is not the same as the GNU JDK/Classpath. OpenJDK is not third-party, it is backed by Sun. Sun open-sourced a lot of the Java libraries, but couldn't release all of the code due licensing issues. OpenJDK is currently trying to replace the proprietary, privately-licensed parts of the Sun JDK with open source code. Sun's JDK still has the proprietary parts and so it may perform better in certain areas.
Matt
I got the point. Thanks, Matt. Was there any chance that GNU JDK was used in Ubuntu before OpenJDK? I really recall it like that. Maybe that was the source of my confusion with OpenJDK.
BalusC
I believe Ubuntu did at one time ship with GNU Classpath, because I remember replacing it with Sun's JDK due to performance, especially when running Eclipse.
Matt
GNU Java is gcj plus the Classpath project. The problem is that Classpath does not have a TCK license to check that everything works as Sun intends, hence the subtle differences.
Thorbjørn Ravn Andersen
+11  A: 

What advantages does one have over the other?

OpenJDK works rather well, is very stable and is the default VM on many GNU/Linux distros (because the code is under GPL I guess). In my opinion there aren't much differences from a technical (~99% of their code is shared1) and from an end user point of view but, if you don't mind using licensed software, I'd still go for Sun JDK. It's not that OpenJDK is not stable (IcedTea is the JVM of RHEL and RedHat is supporting it) but you might face little more bugs with OpenJDK than with Sun JDK (as the former is moving faster). Some packages will require OpenJDK though (even if Sun JDK is installed, I don't know, this must be a bug). If you want to play with Java 7, OpenJDK is nice. About Java 7, note that JDK7 and OpenJDK7 will have (nearly) identical code base.

See Sun’s JDK7, OpenJDK & IcedTea: Disambiguation for more details. There are actually plenty of other interesting thread over the Internet, for example this one (read all pages). Googling on IcedTea should bring very interesting results too.

Can I run both side by side?

Yes, you can and you can tell the system which one to use by default (for the Java software).

To get a list of the installed JDK

$ sudo update-java-alternatives -l 

To set a new as default one (at the system level)

$ sudo update-java-alternatives -s <jname> 

I have both of them installed to do some testing from time to time and use java-6-sun as default.


1 As underlined by Tom Hawtin's comment to BalusC 's answer, this might be a bit less. According to Joseph Darcy's OpenJDK 6 Genealogy, many files are likely to have identical contents (pretty vague...) and my understanding is that the convergence might be bigger with OpenJDK 7 and Java 7. But this is another story.

Pascal Thivent
+2  A: 

If it is just a private project it does not matter really, I guess.

But if you develop for a public/commercial project ask the operations what the official supported environment is. Even if the environments (devel vs. production) are 99% identical you should always use the official supported and tested version.

In a real case the used jre vendor was not communicated correctly (ibm vs. sun). We developed/tested our software with sun. One day on production a jre-bug popped up, which never happened on development environment, because different jre-versions were used. aargh!

manuel aldana
A: 

One big difference is that the documentation is different. I don't know if Sun released the docs in a license that is compatible with OpenJDK, but they are using (from my experience) the GNU classpath documentation, which is nowhere near as good.

Sun has great documentation, and you can still use their docs if you want to use OpenJDK, but that could cause confusion if OpenJDK has implemented it differently.

Kristopher Ives
+3  A: 

With openjdk, you have the sound mixer working : i.e you won't have error like "the current audio device is currently in use" : with SunJdk, if your java program tries to play a sound while another program is already playing, it won't work, which is lame :/

Laurent Debricon
+2  A: 

The problem now is that with the recent suit by oracle over google's usage of java in its android operating system, is it even safe to use sun-java anymore? Wouldn't OpenJDK be a safer option should one want to develop java programs?

Gan Shun
What does one have to do with the other? The Google suit is because (simplified version) Google is using the Java name on a product that's not Java . OpenJDK has no such concerns.
Marc Paradise