Java Streams  «Prev  Next»

Lesson 1

Classic Java Streams for Input and Output

This module introduces streams, the foundation of input and output in Java. Anytime you read data
  1. from a file,
  2. a network connection,
  3. System.in
you are using streams. Similarly, anytime you write data to a file, a network connection, or System.out, you will use streams. In this module, you will learn the following:
  1. What streams are
  2. Where streams come from
  3. When you should use streams

What is a Stream?

A stream is an ordered sequence of bytes of undetermined length. Input streams move bytes of data into a Java program from an external source. Output streams move bytes of data from Java to an external target. (In special cases streams can also move bytes from one part of a Java program to another.)

Java I/O
Sequence, Piped, Object, File, Filter, ByteArray InputStream
Sequence, Piped, Object, File, Filter, ByteArray InputStream


Using Streams to Read and Write Files

What are streams? Streams are ordered sequences of data. Java deals with input and output in terms of streams. For example, when you read a sequence of bytes from a binary file, you are reading from an input stream; similarly, when you write a sequence of bytes to a binary file, you are writing to an output stream. Note how we referred to reading or writing bytes from binary files, but what about reading or writing characters from text files? Java differentiates between processing text and binary data. Before delving deeper into streams and reading or writing data from files, you must first understand the difference between the character streams and byte streams, which is essential for understanding the rest of the module.

JRMP, or Java Remote Method Protocol is the Java technology-specific protocol for looking up and referencing remote objects. It is a wire level protocol running at the level under Remote Method Invocation (RMI) and over TCP/IP. JRMP is a Java-specific, stream-based protocol. RMI-IIOP which exposes Java objects to CORBA ORBs is an alternative for JRMP. However, many application server vendors have developed their own protocols for use with RMI which claim to offer advantages over both IIOP and JRMP.
JRMP is a Java-specific, stream-based protocol similar to RMI-IIOP. The RMI-IIOP which exposes Java objects to CORBA ORBs is an alternative to JRMP. In contrast to the RMI-IIOP, the JRMP is a protocol for Java-to-Java remote calls, which makes it language dependent and means that both client and server must use java objects. However, many application server vendors have developed their own protocols for use with RMI which claim to offer advantages over both IIOP and JRMP.