Random (ugly? haha) Java code while making the switch to Java from C/C++