Q:

What is the sigificance of 0 in the parameters--String message=new String(recievepacket.getData(),0,recievepacket.getLength());

If I use any other number instead of 0, I am not able to see any message. Why to use 0 while converting the received packet to string?
public class UdpClient {

public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub
    DatagramSocket cs=new DatagramSocket();
    byte [] recievedata=new byte[512];
    String message=null;
    byte [] senddata=new byte[512];
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    System.out.println("client created");
    InetAddress addr=InetAddress.getByName("127.0.0.1");
    int port=9003;

    while(true) {

        System.out.println( "client says");
        message=br.readLine();

        senddata=message.getBytes();
        DatagramPacket sendpacket=new DatagramPacket(senddata, senddata.length, addr, port);
cs.send(sendpacket);        

DatagramPacket recievepacket=new DatagramPacket(recievedata, recievedata.length);
cs.receive(recievepacket);
message=new String(recievepacket.getData(), 0,recievepacket.getLength());
System.out.println("server says"+message);

    }

}
 }

A:

See the javadoc of String class:
String(byte[] bytes, int offset, int length)

Parameters:
bytes - The bytes to be decoded into characters
offset - The index of the first byte to decode
length - The number of bytes to decode

