Within a writeObject() method, you can use the methods of ObjectOutputStream like writeInt(), writeLong(), etc. But if you're only writing primitives, then don't use serialization -- use DataOutputStream/DataInputStream instead to efficiently tranfer primitives.