what is stream in java?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robert22
    New Member
    • Mar 2020
    • 5

    what is stream in java?

    what is stream in java? can someone help?
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 655

    #2
    What specific part are you having difficulty understanding?

    Comment

    • robert22
      New Member
      • Mar 2020
      • 5

      #3
      am familiar with C. I am reading Java book and file handling looks confusng since the start.

      Comment

      • dev7060
        Recognized Expert Contributor
        • Mar 2017
        • 655

        #4
        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.

        Comment

        • robert22
          New Member
          • Mar 2020
          • 5

          #5
          hello dev7060 that is really helpful work thank you.

          Comment

          • Sherin
            New Member
            • Jan 2020
            • 77

            #6
            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.

            Comment

            • scaler
              New Member
              • May 2020
              • 1

              #7
              Good thread helped me. Thanks for this.

              Comment

              • Riya Bajpai
                New Member
                • Feb 2023
                • 18

                #8
                Stream does not store elements. It simply conveys elements from a source such as a data structure, an array, or an I/O channel, through a pipeline of computational operations.
                Stream is functional in nature. Operations performed on a stream does not modify it's source. For example, filtering a Stream obtained from a collection produces a new Stream without the filtered elements, rather than removing elements from the source collection.
                The elements of a stream are only visited once during the life of a stream. Like an Iterator, a new stream must be generated to revisit the same elements of the source.

                Comment

                • vipulguptaseo
                  New Member
                  • Feb 2023
                  • 22

                  #9
                  A stream is an abstraction of a set of non-mutable functions that have been applied to data in a certain sequence. There are no items that may be stored in a stream. Java streams provide operations on streams of items in the functional style.

                  The fact that a stream lacks data storage is the key distinction between it and a structure. You cannot, for instance, point to a place in the stream where a specific element is present. Just the functions that use the data can be specified. Moreover, altering a stream will have an impact on the original stream.

                  Comment

                  • Rina0
                    New Member
                    • Jul 2023
                    • 13

                    #10
                    A stream in Java is a sequence of elements that can be processed in a declarative way. It is a new abstraction introduced in Java 8 that allows you to perform operations on data in a more efficient and concise way.

                    Streams are not data structures, but they can be used to process data structures. They can be created from collections, arrays, or I/O channels.

                    Streams are processed lazily. This means that elements are only processed when they are needed. This makes streams very efficient, especially when processing large amounts of data.

                    Streams can be used to perform a variety of operations, such as filtering, mapping, reducing, and collecting. They can also be used to parallelize operations. Answer reference from here.

                    Comment

                    Working...