I’m writing an application which aims to centralize all data related to project management produced in a mysql database. The application can be divided in 3 parts/projects as it follows:
- Server Layer :
Act as a layer between several clients and keeps connected to the database (mysql). It listens to the protocol class and then perform operations like INSERT, UPDATE, DELETE, SELECT and such. It’s written in plain java 2SE instead of 2EE since it’s a very simple class and can be independent from a server.
- Communication Protocol:
A class which extends java.util.EventObject and implements the Serializable interface. It works to store the information related to a common protocol between client and server. This is the class which actually “travels” through the socket since it works kind like a protocol.
- Client Application:
Basicaly the gui. It’s written in javafx 2.1 and aims to provide a nice and beauty interface to collect information.
My question is, to improve readability through code I’ve created some static final fields on the Communication Protocol class and declared then as int and I would like to know if using byte can improve the code since (again) it will travel through a socket. I understand that the JVM will separate equivalent space to a word to bytes, shorts and ints variables but does this behavior occurs when sending data through a socket? So, in this context, which one is better:
/**
*
*/
private static final long serialVersionUID = 7530533341506425480L;
public static final int CLIENT_DISCONNECTED = -1;
public static final int NEW_INFO_INSERTED = 0;
public static final int SHUTDOWN_ORDER = 1;
public static final int INFO_NOT_INSERTED = 100;
public static final int CLIENT_CONNECT = 10000;
public static final int CLIENT_LOGIN = 10001;
public static final int SERVER_LOGIN_OK = 20001;
public static final int SERVER_LOGIN_FAILED = 20002;
public static final int SERVER_SAYS = 20003;
public static final int SERVER_IMAGE_INSERTED = 20004;
public final static int DB_WORKERS = 1001;
public final static int DB_PROJECTS = 1002;
public final static int DB_SECTORS = 1003;
public final static int DB_ACTIVITIES = 1004;
public final static int DB_SUBACTIVITIES = 1005;
public final static int DB_INSERTION = 1006;
public final static int DB_REL_COST = 1007;
public final static int DB_FUNCTIONS = 1008;
public final static int DB_INSERTION_ID = 1009;
public final static int DB_INSERTION_IMG = 1010;
public final static int DB_WORKER_INSERTED = 4010;
public final static int DB_ACTIVITY_INSERTED = 4011;
public final static int DB_SECTOR_INSERTED = 4012;
public final static int DB_SUBACTIVITY_INSERTED = 4013;
public final static int DB_FUNCTION_INSERTED = 4014;
public final static int DB_IMAGE_INSERTED = 4015;
public final static int DB_PARENTS_INSERTED = 4016;
or using bytes? Cheers
As ColeJohnson says, bytes are smaller than ints, so technically faster to send. however, unless you are sending 100 thousands or millions of these values at a time, the size difference will not matter.