Send data to arduino from PC in java over Serial (RXTXlib)

Yes, I agree.

In my sketches I use the cast statement in this way:

/*
  SerialEvent occurs whenever a new data comes in the
 hardware serial RX.  This routine is run between each
 time loop() runs, so using delay inside loop can delay
 response.  Multiple bytes of data may be available.
 This is general code you can reuse.
 */
void serialEvent() {
    
  while (Serial.available() && !stringComplete) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
}

This is the row you are interested in: char inChar = (char)Serial.read();

Note: serialEvent works with Arduino UNO but not with Leonardo or Micro. If you use Leo or Micro you should move this code into loop() func.

www.ardulink.org