Main Content

Keyboard reader for Java programming newcomers

Archive - Originally posted on "The Horse's Mouth" - 2014-12-12 01:00:37 - Graham Ellis

I've added a new class of Keyboard Reader for our Java courses [here], for the earlier examples and exercises just after "Hello World". We want to be able to teach people to write a read - calculate - write program early on, but Java inputs require exception handling, and exceptions are objects, and those objects use inheritance, and there's a lot to learn if you wait to read user input until you have learned all these things. Much better to use a function or two. So here's how we open keyboard access and read a line:

  KeyRead source = new KeyRead();
  String said = source.readline();


Previously, we've used static methods to provide a keyboard reader, but we've updated the course now to use an object (a KeyRead) and a method on that object. It means a slightly more complex instruction session early in the course, but it gives us the advantage of being able to refer back to this use in a ouple of chapters when we first introduce objects properly to our delegates.