Home | Book Resources | The Keyboard Class

The Keyboard Class

Some of the examples in the textbook use a class called Keyboard to facilitate reading text input from the keyboard. Its purpose is to simplify the program examples presented early in the book.

The Keyboard class was designed by the authors of the textbook. It is not part of the Java standard class library.

The Keyboard class is a classic abstraction: hiding potentially confusing details until they are needed. Chapter 5 of the textbook explores some of the internal details of the Keyboard class, and Chapter 8 explores them even further.

The Keyboard class is declared to be part of the cs1 package. That's cs-one, not cs-el. In fact, the Keyboard class is the only member of the cs1 package. Instructors and students may choose to add other support classes to the cs1 package as desired.

Keyboard.java Download (or view) the source code of the class.
keyboard.doc Download a description of the class. (pdf format)
cs1jar.zip Download the compressed file containing the cs1 package.

The file keyboard.doc is a one-page Word document that describes the methods of the Keyboard class in a manner similar to Appendix M. The description is also available in pdf format.

Installing the cs1 Package

Because the cs1 package is not part of the standard class library, it must be installed as an optional package (in previous Java releases this kind of package was called a standard extension or just an extension).

Note: Students, you should install the cs1 package only on your own personal computer. Your instructor or school system administrator will have already installed the cs1 package on the school's computers.

The following instructions apply if you are using the Java Software Development Kit (SDK), also called the Java Development Kit (JDK). If you are using another development environment, consult your instructor or the development environment's documentation to find out how to install optional packages. The cs1 package is already installed as an optional package in the jGrasp development environment available on the book's CD.

The following instructions also assume that the version of the SDK you are using is 1.4.0 and that the default directory structure was used when the SDK was installed. If not, the locations into which the cs1.jar file is stored must be adjusted accordingly.

To install the cs1 package:

1. Download the cs1jar.zip file. This file is compressed.
2. Extract the cs1.jar file. This is a Java Archive (JAR) file containing the cs1 package.
3.

Store the cs1.jar file in the following directory:
C:\j2sdk1.4.0\jre\lib\ext

4. Copy the cs1.jar file and store the copy in:
C:\Program Files\Java\j2re1.4.0\lib\ext

Once you have the JAR file stored in the correct locations, the compiler and interpreter should be able to find and use the Keyboard class when imported.