In UART based serial communication, these two methods: Serial.read() and Serial.write() are used to exchange data with the remote devices.
1. When a data byte (technically – a 10-bit wide asynchronous frame) arrives to the Arduino UNO, it is automatically saved (in the background through interrupt process and beyond the knowledge of the user) into an unseen FIFO (first-in first-out) Buffer. The user first checks if the Buffer has accumulated any data byte, and then he executes this code: char x = Serial.read() to bring the arrived data byte from the Buffer into user variable x.
byte n = Serial.available(); //checking if Buffer contains at least 1-byte data
if (n !=0 )
char x = Serial.read();
2. When we have a data byte (say: 0x35) to transfer via Transmit Section (TX) of UART Port, we execute this code: Serial.write(0x35); as a result, the data byte enters into a FIFO Buffer (different buffer from Step-1); the Buffer interrupts the MCU; the MCU reads the data byte from the Buffer, convert it into an async frame, and then puts onto actual TX Register/Section. The process continues until all the data bytes (in case of multi bytes data: Serial.write(myData, sizeof myData)) of the Buffer get written onto TX Register.