c++/java pattern programming