Java IO and NIO
Guide for Beginner to Advanced Programmers
Table of Contents
Chapter 1: Introduction to Java IO and NIO
1
What is Java IO?
1
History and Evolution of Java IO
4
Overview of Stream-Based IO
6
Blocking vs Non-blocking IO
11
Synchronous vs Asynchronous IO
15
Chapter 2: Java IO Fundamentals
19
Byte Streams vs Character Streams
19
InputStream and OutputStream Classes
23
Reader and Writer Classes
27
File Handling Basics
32
Buffered Streams and Their Importance
36
Data Streams for Primitive Types
41
Chapter 3: File and Directory Operations
44
Working with Files: File Class Overview
44
Reading and Writing Files with FileInputStream and FileOutputStream
50
Reading and Writing Files with FileReader/FileWriter
54
File Permissions and Attributes
58
Listing Files and Directories
63
File Deletion, Renaming, and Creation
69
Chapter 4: Advanced Java IO Concepts
74
Object Serialization and Deserialization
74
Using ObjectInputStream and ObjectOutputStream
78
Externalizable Interface
83
Piped Streams for Inter-thread Communication
87
PushbackInputStream and Mark/Reset Methods
91
Chapter 5: Introduction to Java NIO (New IO)
96
Motivation Behind NIO
96
Core Concepts: Buffers, Channels, and Selectors
99
Differences Between IO and NIO
104
Non-blocking IO and Selectors Overview
109
Chapter 6: Buffers and Channels
114
ByteBuffer and Other Buffer Types
114
Buffer Operations: Read, Write, Flip, Clear, Compact
119
FileChannel for File Operations
124
SocketChannel and DatagramChannel
129
Memory-Mapped Files
134
Chapter 7: Selectors and Non-blocking IO
139
Understanding Selectors
139
Registering Channels with Selectors
144
Handling SelectionKeys and Events
148
Building a Simple Non-blocking Server
153
Performance Considerations
160
Chapter 8: Asynchronous IO
168
Introduction to Asynchronous IO in Java
168
AsynchronousFileChannel
172
CompletionHandler and Future
177
Using AIO for Network Communication
181
Chapter 9: Working with Character Sets and Encodings
190
Charset and CharsetDecoder/CharsetEncoder
190
Reading and Writing Text with Charset Support
194
Handling Unicode and UTF Variants
198
Charset Conversion Examples
203
Chapter 10: Practical Java IO and NIO Examples
208
File Copying and Moving
208
Implementing a File Watcher
213
Building a Simple HTTP Server with NIO
218
Logging and Debugging IO Operations
226
Best Practices for Efficient IO
231
Chapter 11: Performance and Tuning
236
Buffer Sizes and Their Impact
236
Direct Buffers vs Heap Buffers
241
Reducing Garbage Collection Overhead
245
Profiling and Monitoring IO Performance
250
Chapter 12: Security and IO
255
IO Security Basics
255
Secure File Access and Permissions
259
Secure Network Communication with NIO
264
Handling Sensitive Data Streams
274
Chapter 13: New Features and Future of Java IO/NIO
282
Updates in Java 11 and Later Versions
282
Project Loom and Virtual Threads Impact
286
Reactive Streams and IO
292
Upcoming Improvements and Alternatives
298
Related Books
Introduction
Java for Beginners
Learn to Code from Scratch
Introduction
Java Syntax
From Beginner to Expert
Introduction
Java Date and Time
A Systematic Approach
Introduction
Java Object-Oriented Design
Principles, Patterns, and Practices
Introduction
Java Collections
From Fundamentals to Advanced Applications
Introduction
Java Regex
From Basics to Advanced
Introduction
Java Functional Programming
From Lambdas to Reactive Streams
Introduction
Java Streams
From Fundamentals to Advanced Data Processing
More Books on Java