Add the java code for Chapter 2.1