Java to Arduino Serial Communication

How to use serial communication from a java application to arduino in order to set a value of a variable and also upload the sketch onto the arduino board? I am using Arduino Micro Pro to clear things up.

I don't know Java, but for receiving data on the Arduino have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino and Arduino to PC communication.

You can send data in a compatible format with code like this (or the equivalent in any other programming language)

Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker

This Simple Python - Arduino demo should give you the general idea about the PC-Arduino communication. You should be able to replace the Python code with equivalent functionality in any other programming language.

...R