title: Why can't I run this tcp client socket code without \n?
body: <p>I was trying this code. it works fine but if I remove <code>\n</code> in <code>String str</code> it doesn't work I mean It was able to compile without <code>\n</code> but it didn't give me output.</p>
  <pre><code>public class Test {
      // Use try-with-resources to close a socket.
      public static void main(String args[]) throws Exception {
          int c;
          // Create a socket connected to internic.net, port 43. Manage this
          // socket with a try-with-resources block.
          try (Socket s = new Socket(&quot;whois.internic.net&quot;, 43)) {
              // Obtain input and output streams.
              InputStream in = s.getInputStream();
              OutputStream out = s.getOutputStream();
              // Construct a request string.
              String str = (args.length == 0 ? &quot;MHProfessional.com&quot; : args[0]) + &quot;\n&quot;; // &lt;- herer
              // Convert to bytes.
              byte buf[] = str.getBytes();
              // Send request.
              out.write(buf);
              // Read and display response.
              while ((c = in.read()) != -1) {
                  System.out.print((char) c);
              }
          }
          // The socket is now closed.
      }
  }
  </code></pre>