Latest Posts »
Latest Comments »
Popular Posts »

How to sneak easter eggs past the pointy haired boss

Written by Toomas Römer on April 15, 2009 – 1:22 pm

I’m part of a small team that is developing a cool Java product. We’ve been afloat for more than a year and we’re doing better every month. We’ve grown quite a bit during this time. There used to be only one developer, then I joined the team and now we already have 4 devs.

Until now we’ve got away with most of the jokes we’ve pulled but we have matured over the period and we’re not the same young naive happy hackers anymore (right!). We still do like to throw a joke in every now and then.

We released a XML configuration file schema with our last product release and we had to pick a schema location for that. Remembering the Mozilla Ghostbusters reference we also had to reference something. And so we did.

But last week we got an email from our pointy haired boss. He had made a memo with 5 points about the documentation we have. The last point read: Why is there an alderaan in the namespace? It should be our product name!

I guess this marks a landmark in our small team, we’re not small anymore and we’ll have to figure out a way to keep the pointy haired occupied with something (Google Analytics usually does the trick). Luckily for us, we could still play the founder card, but later we may not be so lucky. What jokes have you managed to sneak by your boss and how did you hide them?

PS. We did not have to change our schema but it came quite close.


Posted in humour, meme, opinion | No Comments »

Caricature: JavaRebel winning the JOLT Productivity Award

Written by Jevgeni Kabanov on March 17, 2009 – 6:26 pm

jolt_eng

Thanks to Risto for making it. I’m the dude on the left :) Oh, and download JavaRebel!


Posted in meme | No Comments »

JavaRebel wins JOLT productivity award

Written by Jevgeni Kabanov on March 12, 2009 – 5:35 am

JavaRebel wins JOLT productivity award — awesome!


Posted in meme | No Comments »

The Ultimate Java Puzzler

Written by Jevgeni Kabanov on February 16, 2009 – 6:01 pm

Why is this particular one the ultimate? Two reasons:

  • It’s at the very core of the Java language, not some obscure piece of API.
  • It melted my brain when I hit it.

UPDATE 2: If you want to test yourself before reading the post take this test. Results are not saved (it’s a paid feature apparently and I just don’t care enough), but you can post them in the comments.

Let’s start by setting up the puzzler environment. We’ll have three classes in two packages. Classes C1 and C2 will be in package p1:

JAVA:
  1. package p1;
  2. public class C1 {
  3.   public int m() {return 1;}
  4. }
  5. public class C2 extends C1 {
  6.   public int m() {return 2;}
  7. }

Class C3 will be in a separate package p2:

JAVA:
  1. package p2;
  2. public class C3 extends p1.C2 {
  3.   public int m() {return 3;}
  4. }

We will also have the test class p1.Main with the following main method:

JAVA:
  1. public static void main(String[] args) {
  2.   C1 c = new p2.C3();
  3.   System.out.println(c.m());
  4. }

Note that we’re calling the method of C1 on an instance of C3. The output for this example is “3″ as you’d expect. Now let’s change the m() visibility in all three classes to default:

JAVA:
  1. public class C1 {
  2.   /*default*/ int m() {return 1;}
  3. }
  4. public class C2 extends C1 {
  5.   /*default*/ int m() {return 2;}
  6. }
  7. public class C3 extends p1.C2 {
  8.   /*default*/ int m() {return 3;}
  9. }

The output will now be “2″!

Why is that? The Main class that invokes the method does not see the m() method in the C3 class, it being in a separate package. As far as it cares the chain ends with C2. But as C2 is in the same package it overrides the m() method in C1. This does not seem too intuitive, but that’s the way it is.

Now let’s try something different, let’s change the modifier of C3.m() back to public. What will that do?

JAVA:
  1. public class C1 {
  2.   /*default*/ int m() {return 1;}
  3. }
  4. public class C2 extends C1 {
  5.   /*default*/ int m() {return 2;}
  6. }
  7. public class C3 extends p1.C2 {
  8.   public int m() {return 3;}
  9. }

Now Main can clearly see the C3.m() method. But amazingly enough output is still “2″!

Apparently C3.m() is not considered to override C2.m() at all. One way to think about it is overriding methods should have access to the super methods (via super.m()). However in this case C3.m() wouldn’t have access to its super method, as it it not visible to it, being in another package. Therefore C3 is considered to be in a completely different invocation chain from C1 and C2. Were we to call C3.m() directly from Main the output would actually be “3″.

Now let’s look at one last example. Protected is an interesting visibility. It behaves like default for members in the same package and like public for subclasses. What will happen if we change all of the visibilities to protected?

JAVA:
  1. public class C1 {
  2.   protected int m() {return 1;}
  3. }
  4. public class C2 extends C1 {
  5.   protected int m() {return 2;}
  6. }
  7. public class C3 extends p1.C2 {
  8.   protected int m() {return 3;}
  9. }

My reasoning goes like this: as Main is not a subclass of any classes protected should behave as default in this case and output should be “2″. However that is not the case. The crucial thing is that C3.m() has access to super.m() and thus the actual output will be “3″.

Personally, when I first encountered this accessibility issue I got thoroughly confused and couldn’t get it until I did all of this examples through. The intuition I got from this is that if and only if you can access super.m() the subclass is a part of the invocation chain.

UPDATE: Apparently even though the whole thing is obvious to anyone, the intuition I came up with was wrong. A mysterious commenter know only as “C” has provided the following example:

JAVA:
  1. public class C1 {
  2.   /*default*/ int m() {return 1;}
  3. }
  4. public class C2 extends C1 {
  5.   /*default*/ int m() {return 2;}
  6. }
  7. public class C3 extends p1.C2 {
  8.   /*default*/ int m() {return 3;}
  9. }
  10. public class C4 extends p2.C3 {
  11.   /*default*/ int m() {return 4;}
  12. }

Note that C4 is in the package p1. If we now change the Main code as follows:

JAVA:
  1. public static void main(String[] args) {
  2.   C1 c = new C4();
  3.   System.out.println(c.m());
  4. }

Then it will output “4″. However super.m() is not accessible from C4 and putting @Override on the C4.m() method will stop the code from compiling. At the same time if we change the main method to:

JAVA:
  1. public static void main(String[] args) {
  2.   p2.C3 c = new C4();
  3.   System.out.println(c.m());
  4. }

The output will be “3″. This means that C4.m() overrides C2.m() and C1.m(), but not C3.m(). This also makes the issue even more confusing, and the amended intuition is that a method in a subclass overrides a method in a superclass if and only if the method in the superclass is accessible from the subclass. Here superclass can be any ancestor, not necessarily the direct parent and the relation has to be transitive.

For the kicker try reading all of this out from the JVM specification that selects the method to be invoked:


Let C be the class of objectref. The actual method to be invoked is selected by the following lookup procedure:

  • If C contains a declaration for an instance method with the same name and descriptor as the resolved method, and the resolved method is accessible from C, then this is the method to be invoked, and the lookup procedure terminates.
  • Otherwise, if C has a superclass, this same lookup procedure is performed recursively using the direct superclass of C; the method to be invoked is the result of the recursive invocation of this lookup procedure.
  • Otherwise, an AbstractMethodError is raised.


Posted in Featured, meme | 54 Comments »

SpringSource is not the devil?

Written by Jevgeni Kabanov on October 8, 2008 – 12:07 am

SpringSource is not the devil? — apparently the community outcry was strong enough to revoke the most outrageous part of the new policy: now the latest stable branch will have maintenance releases even after the three month stoppoint. The funny part is that now the “three months” don’t have any value whatsoever, as the space between Spring branch releases is at least half a year. I get that SpringSource needs to shake the money out of the enterprise, but if JBoss somehow managed to do that without resorting to the outright extortion, so should they.


Tags: ,
Posted in meme | No Comments »