Corrections and singleton pattern for java

Ops, I sent you broken code the last time. Sorry.
I Fixed that and also added the singleton pattern.