Java SE NIO

Print the objectives

Take the exam   Take a beta test

This exam covers non-blocking IO introduced since Java 1.4 in java.nio.* packages.
Topics about regular expressions and character sets are not covered.

Resources

Based on the "Java NIO" book by Ron Hitchens (published by O'Reilly), this exam covers Chapters 1 - 4:
  • Chapter 1. INTRODUCTION
    1.1 I/O Versus CPU Time
    1.2 No Longer CPU Bound
    1.3 Getting to the Good Stuff
    1.4 I/O Concepts
    1.5 Summary
  • Chapter 2. BUFFERS
    2.1 Buffer Basics
    2.2 Creating Buffers
    2.3 Duplicating Buffers
    2.4 Byte Buffers
    2.5 Summary
  • Chapter 3. CHANNELS
    3.1 Channel Basics
    3.2 Scatter/Gather
    3.3 File Channels
    3.4 Memory-Mapped Files
    3.5 Socket Channels
    3.6 Pipes
    3.7 The Channels Utility Class
    3.8 Summary
  • Chapter 4. SELECTORS
    4.1 Selector Basics
    4.2 Using Selection Keys
    4.3 Using Selectors
    4.4 Asynchronous Closability
    4.5 Selection Scaling
    4.6 Summary

See the Java NIO JavaDoc for more information.
  Released  Beta  Frozen  

NIO basic concepts  2 questions

Demonstrate the understanding of basic NIO ideology
  • Explain the differences in approaches between NIO and classical IO
  • Enumerate the main usages of NIO (like non-blocking IO)
5 9 9

Buffers  3 questions

Show ability to manipulate ByteBuffer (specific functions for HeapByteBuffer, DirectByteBuffer and MappedByteBuffer are not covered)
  • Be able to write code that uses buffers:
    • Create ByteBuffer
    • Add data to buffer
    • Remove data from buffer
  • Be able to use each buffer's parameter:
    • position
    • limit
    • capacity
  • Explain why 0 <= mark <= position <= limit <= capacity is true in all cases
5 47 9

Channels  4 questions

Display understanding of channels
  • Explain the purpose of using channels
  • Describe the purpose of basic channel interfaces and classes:
    • Channel
    • ReadableByteChannel
    • WritableByteChannel
    • ByteChannel
    • FileChannel
    • SocketChannel
    • DatagramChannel
  • Write code to construct and use FileChannel and SocketChannel:
    • Create channels:
      • RandomAccessFile.getChannel()
      • Socket.getChannel()
    • Write data to channel:
      • WritableByteChannel.write(ByteBuffer src);
      • Note that write operation might not write all the buffer during one writing loop.
    • Read data from channel:
      • ReadableByteChannel.read(ByteBuffer dst);
      • Note that read operation might not fill all the buffer during one reading loop.
    • Close channel
    • Handle channels' exceptions
8 15 7

Selectors  5 questions

This category covers questions about selectors - an approach to handle large number of reading/writing channels simultaneously.
  • Give usage description for basic classes:
    • Selector
      • Opening selector
      • Selecting keys:
        • Use Selector.select() to get ready selection keys
        • Explain difference between Selector.select() and Selector.select(int)
      • Be able to stop key selection process using wakeUp()
      • Closing selector
    • SelectableChannel
      • Bind channel to Selector in different modes:
        • SelectionKey.OP_ACCEPT
        • SelectionKey.OP_CONNECT
        • SelectionKey.OP_READ
        • SelectionKey.OP_WRITE
        • Be able to use the appropriate mode in a given situation
    • SelectionKey
      • Explain what SelectionKey is used for
      • Use SelectionKey.attach(Object) and SelectionKey.attachment() to manipulate SelectionKey's specific data
    • Be able to write code that uses them
  • Explain the difference SelectableChannel's blocking and non-blocking modes.
    Be able to choose the most appropriate mode in a given situation.
  • Explain why selectors can be scaled (no need to use a thread per connection)
8 7 4

Exam information

  • 21 minutes
  • 14 questions (133)
  • 80% required
  • +2 √
  • - 8  points
  • 15 day delay
  • status: released