467,926 Members | 1,439 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,926 developers. It's quick & easy.

what is stream in java?

what is stream in java? can someone help?
Mar 25 '20 #1

✓ answered by dev7060

In C, a program is directly connected to the i/o device. It requires context switching, again and again, using loops and hence results in degraded performance. Even a file size of MBs takes hours to get the work done.

C++ uses streams. Stream is like a buffer (imagine it like a truck to carry data). It works as: Data to prg. -> stream -> destination. Here no context switching is required for every byte. The data from the stream to the destination is delivered whenever the stream is full. On a site like youtube also, buffered data can be seen with the white line in the progress bar.

In the same way, java supports stream too. Data flows as follow:
java prg. -> o/p stream -> o/p device (e.g. monitor)
i/p device (e.g. keyboard) -> i/p stream -> java prg.
The conversion of objects to stream is called serialization and conversion of the stream to objects is called deserialization. Streams are characterized into two parts in java: 1) Byte streams that use ASCII code system (for desktop applications) and 2) Character streams that use Unicode system (used on the internet in JSP servlets). Many classes are available in the API to work with both types. To enhance the performance even more, mini streams are used like Buffered i/o stream.

  • viewed: 3766
Share:
6 Replies
Expert 256MB
What specific part are you having difficulty understanding?
Mar 25 '20 #2
am familiar with C. I am reading Java book and file handling looks confusng since the start.
Mar 25 '20 #3
Expert 256MB
In C, a program is directly connected to the i/o device. It requires context switching, again and again, using loops and hence results in degraded performance. Even a file size of MBs takes hours to get the work done.

C++ uses streams. Stream is like a buffer (imagine it like a truck to carry data). It works as: Data to prg. -> stream -> destination. Here no context switching is required for every byte. The data from the stream to the destination is delivered whenever the stream is full. On a site like youtube also, buffered data can be seen with the white line in the progress bar.

In the same way, java supports stream too. Data flows as follow:
java prg. -> o/p stream -> o/p device (e.g. monitor)
i/p device (e.g. keyboard) -> i/p stream -> java prg.
The conversion of objects to stream is called serialization and conversion of the stream to objects is called deserialization. Streams are characterized into two parts in java: 1) Byte streams that use ASCII code system (for desktop applications) and 2) Character streams that use Unicode system (used on the internet in JSP servlets). Many classes are available in the API to work with both types. To enhance the performance even more, mini streams are used like Buffered i/o stream.
Mar 25 '20 #4
hello dev7060 that is really helpful work thank you.
Mar 29 '20 #5
64KB
A stream can be defined as a sequence of data. there are two kinds of Streams

InPutStream: The InputStream is used to read data from a source.

OutPutStream: the OutputStream is used for writing data to a destination.

Java provides strong but flexible support for I/O related to Files and networks but this tutorial covers very basic functionality related to streams and I/O.
May 1 '20 #6
Good thread helped me. Thanks for this.
May 22 '20 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

By using this site, you agree to our Privacy Policy and Terms of Use.