I don't actually know what's up here, but I am writing server-client application and client sends a string to the server. I need to send the string "x" to the server, so it starts running code1, but when I do it, server runs code3. The funniest thing is System.out.println(x);
prints "a" in the console.
Here is a fragment of server code(runs on win7, javac compiler):
sInput = new ObjectInputStream(socket.getInputStream());
sOutput = new ObjectOutputStream(socket.getOutputStream());
String x = (String) sInput.readObject();
System.out.println(x);
if (x == "a") {
/*
* code1
*/
} else if (x == "b") {
/*
* code2
*/
} else {
/*
* code3
*/
}
And this is what client does(runs osx, javac compiler):
sInput = new ObjectInputStream(socket.getInputStream());
sOutput = new ObjectOutputStream(socket.getOutputStream());
String x = "a";
sOutput.writeObject(x);
How should I sort it out?
P.S. I know about exception declaration, they are removed to make the code shorter.