While writing a code for a simple dotcom game on my own, I found few tips, which worked fine for my first code in java. I don't know whether they will work in future too.
They are -
1)Try to do things on your own first. Walking on unknown path with incomplete map, getting lost somewhere and finding back the way to home is fun rather than walking on a path told by someone else.
2)Don't implement the whole solution at the first step. Such code is hard to debug. Instead, write the simplest solution with least functionality and enhance it later. Make iterations.
3)Try to make it as flexible as possible. Show it to someone who will find bugs in it.
If you don't find anyone, think of the boss of Bob (or some other name) in first chapter of Head First Design Patterns.