Page 334 - computer science (868) class 11
P. 334
42 ob.read();
43 ob.printlong();
44 }
45 }
The output of the preceding program is as follows:
Enter a sentence
Saturn, Mars, and Earth are planets in our solar system.
Longest word is
planets
If more than one word has the highest length, which means two or more words have the same length, then the
preceding program would return all the words having the highest length.
11.3 INTRODUCING STREAMS
In Java, a sequence of data is called a stream. In other words, a stream can be defined as a path along which the data
travels from an input device to a program and from a program to an output device. It is a communication medium
through which the data is stored and retrieved. The stream used to read data from various input devices is known
as the input stream. The stream used to write data to various output devices is known as the output stream. These
streams are used to perform input/output operations on files. The java.io package provides all the classes to perform
these operations. Streams in Java are of two types:
Streams in Java
Byte Stream Character Stream
Let us learn about these in detail.
11.3.1 Byte Stream
Byte-oriented input/output is performed on binary files that store data in machine-readable form. Byte stream class
handles data in bytes. Java has two abstract classes which are the superclasses of all other classes used to read or write
a stream of bytes. These two classes are as follows:
Byte Stream Classes
InputStream OutputStream
FileInputStream DataInputStream FileOutputStream DataOutputStream
The InputStream Class
The InputStream is an abstract class which means it cannot be instantiated. Various classes inherit the InputStream
class and override its methods. Let us learn about two main classes - FileInputStream and DataInputStream which
inherit the InputStream class. These classes are used to read input from a standard input device like keyboard, mouse,
memory, and any other program.
332332 Touchpad Computer Science-XI

