Java Streams | Types of Java streams

Here, we have discussed about what is Java streams and types of Java streams. In Java, streams is a sequence. In order to execute different .....

In this article we will discuss about what is Java streams and different types of Java streams. 

Java Streams | Types of Java streams

What is Java Streams?

In Java, streams is a sequence. In order to execute different operations in Java, these streams supports all types of data types, files, objects, characters, etc. In simple words we can say that, Stream is a sequence which includes different methods that can be executed in order to get desired results.

Types of Java streams

Java streams are categorised into two types that are discussed as follows;

Depends on the type of operations: 

On the type of operations, stream is divided into two main classes;

1. Input Stream 

It includes those streams that are used to read data that is taken from a input device or source of array or file. 

2. Output Stream

This class includes those streams that are used to write data as output on the output device, file or array.

Depends on the type of file: 

On the type of file, stream bis divided into two main classes;

1. ByteStream

ByteStream is a class which is used to process data byte by byte. In this class, FileInputStream and FileOutputStream are the mostly used streams. The FileInputStream is used to read from a file and the FileOutputStream is used to describe stream output. Following is the list of different ByteStream classes;

S.No Stream Class Description
1. DataInputStream To read Java primitive data type, this class is used.
2. BufferedInputStream To read bytes from the buffer, this class is used.
3. InputStream To describe stream input.
4. FileInputStream To read from a file.
5.
PrintStream This class includes print() and printIn() methods.
6.
DataOutputStream To write Java standard data type, this class is used.
7. BufferedOutputStream For buffered output stream, this class is used.
8. OutputStream To describe stream output.
9. FileOutputStream To write a file.

2. CharacterStream

CharacterStream is a class which is used to process data character by character. In this class, FileReader and FileWriter are the mostly used streams. The FileReader is used to read character of a file and the FileWriter is used to write character to a file. Following is the list of different CharacterStream classes;

S.No Stream Class Description
1. FileReader Include methods to read the character of a file.
2. BufferedReader Include methods to read the character from the buffer.
3. Reader Defines the stream output of character.
4. InputStreamReader Include methods to convert byte into character.
5.
OutputStreamReader Include methods to convert character into byte.
6.
Writer Defines the stream input of character.
7. PrintWriter This class includes print() and printIn() methods.
8. FileWriter To write characters to a file, this class is used.
9. BufferedWriter To write characters to a buffer, this class is used.

Conclusion

Above we have discussed about what is Java streams and types of Java streams. In Java, streams is a sequence. In order to execute different operations in Java, these streams supports all types of data types, files, objects, characters, etc. Java streams are categorised into two types i.e., depends on the type of operation and depends on the type of file.