Additional Java SE Packages

PipedInputStream

PipedInputStream is used to read data written to a connected PipedOutputStream. It provides a communication pipe between two threads, enabling one thread to write data and another to read it.This class is part of Java’s inter-thread communication system and works in conjunction with PipedOutputStream. Commonly Used Constructors and Methods Simple Program – Inter-thread Communication Mahesh …

PipedInputStream Read More »

ObjectOutputStream

ObjectOutputStream is used to serialize Java objects—convert them into a byte stream so they can be written to files or sent over a network. It’s the counterpart of ObjectInputStream, which performs deserialization. Commonly Used Constructors and Methods The object being written must implement Serializable interface, or NotSerializableException is thrown. Simple Program – Serializing a Single …

ObjectOutputStream Read More »

ObjectInputStream

ObjectInputStream is used to deserialize objects—that is, to read objects previously written to a stream using ObjectOutputStream. It reconstructs objects, arrays, and primitive data types from an input stream. Commonly Used Constructors and Methods Simple Program – Reading an Object from File Mahesh wants to read a serialized Employee object from a file named employee.ser …

ObjectInputStream Read More »

DataOutputStream

DataOutputStream lets you write Java primitive data types (like int, float, double, char, boolean) to an output stream in a machine-independent way. It’s usually paired with an OutputStream like FileOutputStream or ByteArrayOutputStream. Commonly Used Constructors and Methods Simple Program – Writing Primitives to File Mahesh wants to store LotusJavaPrince‘s employee ID, name, and salary in …

DataOutputStream Read More »

DataInputStream

DataInputStream allows an application to read Java primitive data types (like int, float, char, etc.) from an underlying input stream in a machine-independent way. It’s commonly used with FileInputStream, ByteArrayInputStream, or any stream that provides raw bytes. Commonly Used Constructors and Methods Simple Program – Reading Primitives from File LotusJavaPrince stores his profile info using …

DataInputStream Read More »

ByteArrayOutputStream

ByteArrayOutputStream is a memory-based stream that collects output data in an internal byte array. It’s useful when you want to build a byte array dynamically (e.g., generating PDF content, processing images, etc.).It automatically resizes its internal buffer as data is written. Commonly Used Constructors and Methods Simple Program – Writing and Printing Byte Array LotusJavaPrince …

ByteArrayOutputStream Read More »

ByteArrayInputStream

ByteArrayInputStream allows an application to read data from a byte array as if it were an input stream. It is especially useful for simulating input for testing or for reading memory-stored data byte-by-byte. Commonly Used Constructors and Methods Simple Program – Reading from ByteArrayInputStream LotusJavaPrince wants to read a byte array “Hello, Mahesh” using ByteArrayInputStream …

ByteArrayInputStream Read More »

OutputStream

OutputStream is an abstract class for writing raw bytes to a destination (like a file, memory buffer, socket, etc.). Subclasses handle actual implementations, such as FileOutputStream, BufferedOutputStream, etc. Commonly Used Methods Simple Program – Write Data to File LotusJavaPrince wants to write the string “Hello, Mahesh!” to a file using FileOutputStream. Output: A file named …

OutputStream Read More »

Exploring java.nio package

The java.nio package, introduced in Java 1.4, provides a more flexible and efficient approach to I/O operations compared to java.io. It introduces the concept of buffers, channels, and selectors, which offer enhanced performance and functionality. Key components of java.nio include: Buffers: A buffer is a container for data of a specific type, such as ByteBuffer, …

Exploring java.nio package Read More »

Scroll to Top