Overview — Memory v.s. Disk & Files System & I/O Operation (Java)

Hanwen Zhang
2 min readJun 23, 2022
Photo by Sigmund on Unsplash

Memory v.s. Disk

  • Memory: fast access, small size, temporary storage
  • Disk: slow access, large size, permanent storage

Performing an operation inside memory is very fast but very expensive due to its limited memory. Accessing disk and performing I/O is a slow process, but is used as permanent storage of the data.

Why File and Database

Memory is temporary storage for data, and after the power shuts off or gets disconnected, its content will fade away => we can store data in a file as a long-term place to keep our data on the disk)

Stream

  • A never-ending dataset, e.g. log files, financial transactions, sensor data.
  • Stream processing allows applications to access only a small portion of data.

High-Level v.s. Low-Level

  • Low-level streams connect directly to the file on the disk.
  • High-level stream built on top of another stream using wrapping (passes an instance of a class to a constructor of another class, like BufferedReader)

Buffered Reader

  • Buffered classes are reading or writing data in a chunk and not byte per byte or character per character.
  • Performance Improvement in the sequential file system since disk access operations are getting less.

Serialization and Deserialization

  • serialization — is the process of converting an in-memory object to a stored data format
  • deserialization — is the reciprocal process of converting stored data into an object

Relative Path v.s. Absolute Path

  • A relative path is a path relative to another directory.
  • An absolute path is a path that we use to access the file in the operating system.

Files in Java

  • Java treats a file as a sequential stream of bytes.
  • Two main types of files: Text files and binary files (image, audio, video).
  • InputStream OutputStream— reading or writing binary data
  • Reader Writer— reading or writing character or string data

--

--

Hanwen Zhang

Full-Stack Software Engineer at a Healthcare Tech Company | Document My Coding Journey | Improve My Knowledge | Share Coding Concepts in a Simple Way