Archive

Archive for November, 2009

Wave needs a decent client

November 23rd, 2009 5 comments

I successfully installed a wave (google) server on a windows box a few days earlier. It was a great feeling. Here are the components that made up the server

  • Open fire XMPP server
  • Postgres database to be used by XFire.
  • Wave related server jar which runs the server
  • Wave command line client that runs the simplistic console client.

I started the console client and typed in a few commands to go through the waves. New, open, view waves were some commands that the command line console allowed you to execute. This client was a simple RI provided by google. If you would like to install a server on your own, take a look at the installation instructions.

Wave console client:

wave-console-client

Categories: java Tags: , ,

Coding with JDK7

November 16th, 2009 14 comments

jdk7 codeThe JDK7 milestone 5 update is available for download. Developers now have a chance to try coding with the new language semantics and see for themselves what it is like. The 4 major changes that affect the way one codes in java as of JDK 7 are

  • Using underscores in numerals.
  • Diamond syntax used to work with collections + generics.
  • Using Strings in switch statements.
  • Making use of binary literals

Here is a short code sample that you can use to check the new features out. Use a plain text editor and your old friends javac and java, to test it out. IDEs will not support the new syntax and will most likely complain.

Sample JDK 7 Code:

public class Jdk7Tests {
 
    public static void main(String[] args) {
        Jdk7Tests jdk7Tests = new Jdk7Tests();
        jdk7Tests.integersWithUnderscores();
        jdk7Tests.stringSwitch();
        jdk7Tests.binaryLiteral();
        jdk7Tests.diamond();
    }
 
    private void integersWithUnderscores()
    {
        int i = 1_2;
        System.out.println(i);
        i*=10;
        System.out.println(i);
        int j=2_0;
        System.out.println(i-j);       
    }
 
    private void stringSwitch()
    {
        String key = "akey";
        switch (key)
        {
        case "":
        {
            System.out.println("Nothing");
            break;
        }
 
        case "akey":
        {
            System.out.println("Matched akey");
            break;
        }
        default:
        break;
        }
    }
 
    private void binaryLiteral()
    {
        byte aByte = (byte)0b001;
        short aShort = (short)0b010;
        System.out.println(aByte + " " + aShort);
    }
 
    private void diamond()
    {
        Set<String> set = new TreeSet<>();
        set.add("c");
        set.add("b");
        set.add("a");
        for (String val : set)
        {
            System.out.println(val);
        }
    }
}

Underscores and numerals:

Categories: java Tags:

Interview filter question

November 9th, 2009 2 comments

Developers interview candidates every now and then. There are days when you need to interview 4 candidates, and finish your work too. Then there are times you go to work on a Saturday to support an interview drive. Whatever the case, it really pays to have a few filter questions that should tell you whether a candidate is full of gas or if they are worth their salt. These questions can be a real time saver. Here are 2 questions that many developers use.

1. Class hierarchy:

class A
{
    public void doSomething()
    {
        System.out.println("A");
    }
}
 
class B extends A
{
    @Override
    public void doSomething()
    {
        System.out.println("B");
    }
}

Give a candidate a class hierarchy like the one above and ask them something like, ‘How should you instantiate these objects so the output is ‘A’ / ‘B”. The you can drill down and ask them about the different instantiation combination. Anyone that says B b = new A(); will instantiate, is out of here.

2. Name them:

Categories: java Tags:

Commons email

November 3rd, 2009 No comments

There are many apache commons projects out there that save your time either directly or indirectly. Some of the well known commons projects are

  • Commons beanutils – Services wrapped around java beans.
  • Commons digester – XML to java mappings
  • Commons lang – Helper utilities for the java.lang API
  • Commons logging – A generic logging implementation

There are other commons implementations that can save your time, but you are probably not using them. One of them is commons email. Commons email provides a facade to the underlying java mail services that come from mail.jar. Sending an email using mail.jar is not that difficult, but when you use commons email it is downright simple

Check out a sample program that sends a simple email

SimpleEmail email = new SimpleEmail();
email.setHostName("mail.myserver.com");
email.addTo("jdoe@somewhere.org", "John Doe");
email.setFrom("me@apache.org", "Me");
email.setSubject("Test message");
email.setMsg("This is a simple test of commons-email");
email.send();

Thats it. Use the HTMLEmail class to send HTML based emails. You can read more about the commons email API from their user guide. The project is active and should simplify the parts of your application that send email.

Categories: java Tags: , ,