java.nio · java.base · since Java 1.4
ByteBuffer
public abstract class ByteBuffer extends Buffer
implements Comparable<ByteBuffer>The NIO byte container with the position/limit/capacity state machine: fill → flip() → drain → clear. Heap or direct; typed getters/putters with configurable byte order.
Key methods
static ByteBuffer allocate(int) / allocateDirect(int) | Heap vs off-heap (direct: no copy for I/O, pricier to create). |
Buffer flip() | Switch from writing to reading — the forgotten call behind half of NIO bugs. |
Buffer clear() / compact() | Reset for refilling (clear discards; compact keeps unread bytes). |
int getInt() / putInt(int) | Typed access at the position (all primitives). |
ByteBuffer order(ByteOrder bo) | Endianness — default BIG_ENDIAN; most native formats are little. |