Here's the thing: There are about a million ways to do stuff like that in Java (maybe more).

What reference material are you using to learn Java from? Class notes? Textbook? Online tutorials? ...