Sunday, December 22, 2024
Riffs from an overheated mind

Tags


Blogroll


Categories



Java Interview Puzzler

June 18th, 2009 by hashbrown

This is a puzzler we created at my work to use as an interview problem. I had a fun time taking it myself, and got it wrong the first time! It was designed to mimic some bad legacy code you might encounter when working on a large aging system, that has passed through many hands. Terrible coding practices, no javadocs or comments, etc. You are tasked to figure out what the heck it does.
First – does it compile? If not, how do you fix it?
Second – If it compiles, what is the output?

I’ll answer questions and post the solution in the comments.

package crazy;

public class Timing extends R {
    public static final Integer t = new Integer("4");


    public static void main(String[] args) {
        Timing t = new Timing(11);

        System.out.print(t.foo);
        bat(t);
    }

    void fob() { fod(); }

    public Timing(int value) {

        super();
        foo = foo % value;
        bar();
    }

    static {
        System.out.print("6");

    }

    private void bar() {
        new Baz().bar(5);
        tr = "2";
    }

    private int foo = 25;


    static void r() { System.out.println("1"); }
}

abstract class R {

    String tr = "9";

    static void bat(R r) {
        r.fob();
        System.out.print(r.tr);

    }

    private int negate(int bam) {
        return bam * -1;
    }


    public R() {
        System.out.print("7");
    }

    void fod() { System.out.print((int)Math.floor(.99)); }


    protected final int t() {
        return 5;
    }

    class Baz {

        void bar(int fob) {
            if (fob == 9)
                System.out.print(String.valueOf(fob++));

                System.out.print(String.valueOf(negate(fob++)));
            if (fob == 5)
                System.out.print(String.valueOf(fob+=2));

        }
    }

    static {
        System.out.print("8");
    }

    abstract void fob();

}

Posted in geek stuff, programming | Comments Off on Java Interview Puzzler

My Week At JavaOne

June 5th, 2009 by hashbrown

I just returned home from a week in San Francisco at the JavaOne conference, I mean literally like 2 hours ago. This is the first time I’ve been to any conference like this, and I had a great time! The scale of this thing is really impressive, I mean it’s huge. The planning and logistics that go into putting on a conference of this size just amazes me. It felt like they really went all out, all the small details were handled, and you could see the effort they put into making it a special experience.

I had originally registered for tech sessions Tuesday – Thursday, but Thursday night I just wasn’t ready for it to end, and ended up cramming 2 more sessions in on Friday morning before jumping in a cab for the airport. I literally was in a cab 15 minutes after my final session.
Overall, I attended 19 technical sessions over 3 1/2 days, plus the general session keynotes.

I attended sessions on the different dynamic scripting languages that run on the JVM, many on concurrency, and then some on how to use those dynamic languages to solve concurrency problems. I had sessions on Spring, and REST using JAX-RS, sessions on unit testing and some of the tools available. I had a session on defective java with the man behind FindBugs, and a session on Effective Java (2nd Edition)
with one of the absolute rock-stars of the java world, Joshua Bloch. My session on Spring 3.0 was given by THE man behind Spring, Rod Johnson. My sessions on Lift and Clojure were both given by the creators of the language, and the session on JAX-RS was given by the writers of the specification. When I went to hear about how the Google App Engine now supports java, it was directly from the 3 guys responsible for it. I mean, talk about getting it from the source! That google session led to a very late night with my co-worker as we sat in the bar playing with the new sdk until 1am! Read the rest of this entry »

Posted in geek stuff, programming | Comments Off on My Week At JavaOne