Java code snippets and best practises