title: Java String encoding (UTF-8)
body: <p>I have come across this line of legacy code, which I am trying to figure out:</p>
  
  <pre><code>String newString = new String(oldString.getBytes("UTF-8"), "UTF-8"));
  </code></pre>
  
  <p>As far as I can understand, it is encoding &amp; decoding using the same charSet.</p>
  
  <p>How is this different from the following?</p>
  
  <pre><code>String newString = oldString;
  </code></pre>
  
  <p><strong>Is there any scenario in which the two lines will have different outputs?</strong> </p>
  
  <p>p.s.: Just to clarify, yes I am aware of the <a href="http://www.joelonsoftware.com/articles/Unicode.html" rel="noreferrer">excellent article on encoding by Joel Spolsky</a> !</p>