Posts for

2008 March

Dive In: JSnake

Continuing on the Dive In series, we are going one step further and creating a small game using animation: a clone of the classic video game Snake. As always, this will be as small as possible and many many changes can be made (which I’ll once again try to point out). We’ll start from design all the way to implementing and testing it using the easy Water Fall model. You can run the game and download the source code at my JavaCorner.

So, without further ado, let’s start!

Continue reading…

Posted by Panagiotis Peikidis on 25 Mar 2008 - No Comments »

Playing with Try, Catch and Finally

I read a blog post (Greek) recently that described the path Java takes when executing a try, catch, finally block. But before I continue I would like you to consider the following code. What will be printed out?

public class ErrorClass {
    public static void main(String[] args) {
        System.out.println(getMessage());
    }
 
    private static String getMessage() {
        String toReturn = "Initializing";
        try {
            throwException();
            toReturn += "+No Exception";
 
            return toReturn;
        } catch (Exception e) {
            toReturn += "+Catch";
 
            return toReturn +" from Catch";
        } finally {
            toReturn += "+Finally";
 
            return toReturn +" from Finally";
        }
    }
 
    private static String throwException() throws Exception {
        throw new Exception("original exception");
    }
}

a) “Initializing+No Exception”
b) “Initializing+Catch from Catch”
c) “Initializing+Catch+Finally from Catch”
d) “Initializing+Catch+Finally from Finally”

Continue reading…

Posted by Panagiotis Peikidis on 16 Mar 2008 - No Comments »