← Back to libraryQuestion 45 of 273
JavaAdvanced

Java I/O vs NIO (Blocking vs Non-blocking)

📖 Detailed Explanation:

Standard I/O (java.io) is stream-oriented and BLOCKING—one thread per connection. NIO (New I/O, java.nio) is buffer-oriented and NON-BLOCKING, using 'Selectors' and 'Channels' to handle thousands of connections with just a few threads. NIO enables high-performance servers (Netty, Tomcat).

🌍 Real-World Example:

Standard I/O: Each customer has a dedicated cashier (blocking). NIO: One cashier serves many customers, switching quickly between them (non-blocking).

🎯 Scenario-Based Interview Question:

When should you choose NIO over standard I/O? What are the trade-offs?