I’ve been coding a network project for my high school AP programming class, and have been debating whether to use byte/short as the datatype for variables in the code before sending it across a network, or using int then typecasting it before sending across a network. I could use a little advice in the matter :
byte/short:
I know that according to the Java VM specification, byte, short, char, and int all occupy 4 bytes in memory, but the shorter data-types are type-casted to int before arithmethetic operations are performed. I assume this takes some time to perform, however I do not know if it is small enough to worry about, or not.
int:
My concern here is that when typecasting to byte/short to pass to ByteBuffer to convert to network endianness, that the variable’s “contents” may be different when read on the other side of the connection.
Speed is important to me for this project, so I would enjoy any and all suggestions. Thanks in advance.