title: When using ObjectOutputStream/ObjectInputStream to transfer a custom object the variables are reset
body: <p>I have created a server-client chat room style application and I'm trying to transfer a custom object which I have created containing the message and the username of the person using client/server application. To do this I have created a separate class called <code>message</code> which contains two static variables, one called <code>username</code> and one called <code>messageText</code>:</p>
  
  <pre><code>public class message implements Serializable{
  
      static String username = "";
      static String messageText = "";
  
      public message(String message, String user){
          System.out.println("Setting username and messageText");
          username = user;
          messageText = message;
      }
  
      public message(Object recievedObject){
          username = ((message) recievedObject).getUsername();
          messageText = ((message) recievedObject).getMessageText();
      }
  }
  </code></pre>
  
  <p>I send an object of this class from my server to a client as follows:</p>
  
  <pre><code>message sendMessage = new message(enteredText, "SERVER");
  output.writeObject(sendMessage);
  </code></pre>
  
  <p>It is accepted by the client as follows:</p>
  
  <pre><code>message recievedMessage = (message) input.readObject();
  cw.say(recievedMessage.getMessageText(), recievedMessage.getUsername());
  </code></pre>
  
  <p>However both methods above <code>getMessageText()</code> and <code>getUsername()</code> will return whatever the variable was initialized with on the receiving end, and return the correct values on the sending side.</p>
  
  <p>A few hours of trying to fix this problem has provided no solution, so any help that you guys can give me is very, very appreciated! Thanks.</p>