Java NIO server Selector loop
Iterator&lt;SelectionKey&gt; keyIterator = selectedKeys.iterator();

            while (keyIterator.hasNext()) {

                SelectionKey key = (SelectionKey) keyIterator.next();


This cast here is not needed; you already know that you're going to get SelectionKey out of the keyiterator.

Looking up a bit, you declare Set&lt;SelectionKey&gt; selectedKeys = selector.selectedKeys();, but only use it for the iterator. The variable name doesn't add anything to understanding the code, and you might just want to say Iterator&lt;SelectionKey&gt; keyIterator = selector.selectedKeys().iterator();



(key.readyOps() &amp; SelectionKey.OP_ACCEPT) == SelectionKey.OP_ACCEPT


This sort of statement, I'd wrap in a function. Bit manipulation tends to be very low level stuff and looks out of place in a function responsible for doing high level stuff.