From JavaDoc
public final Buffer flip()
Flips this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded.
Before you read anything from the buffer, position == 0, limit ==0. So after the flip, position == 0, limit == 0.
When you getInt()
, position increments by 4. So position == 4, limit == 0. Then flip()
does what the JavaDoc says: position == 0, limit == 4.