I recently stumbled across the Java Communication API, which is a javax
package meant for "serial communication" in pure Java. I have heard of serial communication many times before, but I guess I don't understand what "serial communication" exactly means, or what it implies.
According to Wikipedia:
In telecommunication and computer science, serial communication is the process of sending data one bit at a time, sequentially, over a communication channel or computer bus.
OK...so the Java Communication API allows me to read/write data one bit at a time. But what does that even mean?!? Can't I just do that on my own (pseudo-code here)?:
String str = "I want to send this bit by bit.";
byte[] strAsBytes = str.getBytes();
byte[] bits = new byte[strAsBytes.length * 8]; // For each byte we need 8 bits.
for(int i = 0; i < strAsBytes.length; i++) {
for(int j = 0; j < 8; j++) {
// Something like this (again this is just pseudo-code).
// Regardless, populate all elements in the bits array with the
// bit in the position of the current byte.
bits[i*j + j] = getBit(strAsBytes[i], j);
}
}
// Sends the array of bits over a network, maybe using Netty and TCP,
// or something. Sends each bit one by one.
networkManager.sendBitByBit(bits);
// Retrieves the value of a bit at any position in a byte (theByte).
public byte getBit(byte theByte, int position) {
return (theByte) & (0x01 << pos) ;
}
I feel like the term "serial communication" implies something more than just "sending one bit at a time". Does it mean that I can use it to read/write from serial ports on a machine? Something else?!?
I guess I'm looking for a plain-English, layman explanation of what the broader term "serial communication" is and what types of things you can do with it, and then put that into context of the Java Communications API. It would also be great to have an example or two of what you might use the API to accomplish.