Worked on conversion from C++ to java.

Had a friend help me check if conversion is correct. Still some unclear
points.