Added java code for chapter 6