Thanks to @angelatlarge for his suggestion.
The problem was that the java program did not have the permission to access /dev/rfcomm0
.
Command to provide permission : sudo chmod a+rw /dev/rfcomm0
So giving the permission to /dev/rfcomm0
solved the problem for me.
Now the java program can read the data from the rfcomm0 port.