Java code for basic algorithm designs