Send Integers From Ardunio to Java Program Using Serial Port

the data in the unused fields is just garbage.

This would be true if everything in the union was not the same size. If, for instance, you created one union to handle floats and integers, it would look like this:
union
{
int i;
float f;
byte b[4];
} u;
Now, if you set i, b[0] and b[1] have valid values, but f, b[2], and b[3] do not.

By creating a float union and an integer union, you can assure that there are no unused fields.

Also in my java program at the other end I am reading a byte array of 4 bytes from the serial port. When I try to convert the byte array to a integer I don't get the correct values.

That is because an int, in the Arduino world, is two bytes.

How can I store in u.b when I am reading in a java program?

Good question. Your bit shifting approach will certainly work for ints (when you perform it the correct number of times). I'm not sure if it will work for floats. Be sure to let us know.