Java Reference
In-Depth Information
Chapter 18
I/O Programming
Java Input and Output
Comparedtootherprogramminglanguages,Javahaslittlebuilt-insupport
for input and output operations. This is not due to deficiencies in the lan-
guage's design, or to omissions of implementation, but because Java is
basedonadifferentmodel.Forexample,CandC++assumethatthecom-
putersysteminterfaceconsistsofatext-basedconsoleandakeyboardwith
charactersinawesternEuropeanalphabet.Java,ontheotherhand,makes
noassumptionaboutinputcharactersordevicesandcontainsminimalsup-
portforatext-basedconsoledeviceandacommand-lineinterface.There-
sult of this design is that the application must provide its own input and
outputroutines,oftennotatrivialtask.
Obtaining and Transmitting Data
ThetwolimitationsmostoftenmentionedregardingJavainputandoutput
functions relate to the difficulty in obtaining alphanumeric data from the
keyboard and in formatting output to the console device. So far you have
beenusingtheKeyinclasstoobtainkeyboardinput.Inthissessionweex-
ploreJavainputanddeveloptheroutinesforobtainingalphanumericdata
fromthekeyboard,includingtheKeyinclass.
Keyboardprocessingfunctionsthatarecommoninotherlanguagesdo
not exist in Java. Most notably missing are functions to implement a live
keyboard since there is no Java primitive to detect a single, rawkey -
stroke.Thesamecanbesaidaboutalphanumericoutputformattingoper-
ations,alsounavailableinJava.
Search WWH ::




Custom Search