Indeed as Etan pointed out, you're creating a string from the entire buffer--all 512 bytes--instead of a string of the correct length, so the string that is created has lots of zero bytes at the end.
A simple fix would be to use the String
constructor that cuts off the buffer at the position and length you specify, along with the number of bytes received from the packet from DatagramPacket.getLength
Change the line assigning received
to
String received = new String(incomingBytes, 0, incomingPacket.getLength());