<< Brian Goetz: JavaFX Plugin For IntelliJ | Home | Friday C# Quiz: Know Your Closures >>

Friday Java Quiz: Incompatible Language Changes

The evolution of the Java programming language has been managed carefully (maybe too carefully) to avoid incompatible language changes. However, binary compatibility was given more consideration than source compatibility. In the words of one of the Java Posses, your class will continue to work as long as you don't recompile your code.

Q: Which of the following Sun JDK/JSDK/J2SDK/JDK upgrades contain code breaking language/library changes? Give an example snippet.

  • Beta ⇒ 1.0
  • 1.0 ⇒ 1.1
  • 1.1 ⇒ 1.2
  • 1.2 ⇒ 1.3
  • 1.3 ⇒ 1.4
  • 1.4 ⇒ 1.5
  • 1.5 ⇒ 1.6
Tags :


Re: Friday Java Quiz: Incompatible Language Changes

Is the addition of the assert keyword in 1.5 one of them?

Re: Friday Java Quiz: Incompatible Language Changes

Yes. But it's add not in 1.5, but in an earlier version.

Re: Friday Java Quiz: Incompatible Language Changes

Fun question, as always... Here's one example that breaks when going from 1.4 to 1.5


public class Test {
    int enum[] = { 0, 1, 2, 3 };
}

Re: Friday Java Quiz: Incompatible Language Changes

I had to look this one up. In theory this breaks from 1.1 to 1.2 though I certainly haven't tried it


public class Test {
    float strictfp = 3.1415f;
}

Re: Friday Java Quiz: Incompatible Language Changes

This one was not in my mind when I posted the quiz.

I wonder how many Java developers know the story about strictfp, and how many production lines of code makes use of strictfp math.

Re: Friday Java Quiz: Incompatible Language Changes

assert was added in 1.4 so
String assert = "assert";
would compile in 1.3, but not 1.4
enum was added in 1.5 as one of the other folks mentioned
I didn't know about strictfp introduced in 1.2 so I read up on it: http://en.wikipedia.org/wiki/Strictfp

Re: Friday Java Quiz: Incompatible Language Changes

Except that javac 1.4 defaulted to -source 1.3 (and -target 1.2), so assert still worked as an identifier until Java 5.

One change I found was that some of the new constructors on BigDecimal in Java 5 could cause differences in behaviour when recompiled, since int wasn’t converted to a double any more. I can’t remember precisely what trouble this caused us, though.

Re: Friday Java Quiz: Incompatible Language Changes

Another one I forgot about until I read about somebody migrating a 1.4 app: String.compareTo(Object obj) was removed in 1.5. So if you had something like List l = new ArrayList(1); l.add("foo"); String foo = "foo"; foo.compareTo(l.get(0)); This won't compile anymore.

Re: Friday Java Quiz: Incompatible Language Changes

The reason I put "Beta => 1.0" in the mix is that I seem to remember some major modifier changes around that time. The beta behavior was described in the first edition of Java In a Nutshell.

But I no long have that book. And couldn't remember the details.

Does anyone remember the episode?

Re: Friday Java Quiz: Incompatible Language Changes

Well all of our web services broke between 1.6.0_03 and 1.6.0_04. That should have been called 1.6.1, IMHO. If 1.6.0_10 really is called _10, that will be a travesty. Given the scope of changes, it should be 1.7.

Add a comment Send a TrackBack