An implementation of a checksum varies, however its goal is always the same: To determine if data has been transported without errors or not.
To show the the basic idea of a checksum, i've written a simple example which uses a very basic "summation" checksum, which computes the checksum based on the sum of all the payload bytes. Via the comments, assume this data array is transferred across a socket or whatever.
public static void main(String[] args){
//SENDER
final byte[] data = new byte[4];
data[0] = 1;
data[1] = 2;
data[2] = 3;
//calculate checksum
for(int i = 0; i < data.length-1; i++){
data[data.length-1] += data[i];
}
//RECEIVER
final byte[] received = data;
//calculate checksum
byte checksum = 0;
for(int i = 0; i < data.length-1; i++){
checksum += received[i];
}
//CHECKSUM DOESNT MATCH! DATA CORRUPTED!
if(checksum != received[4]){
System.out.println("An error occured");
}
}