title: Compiling (javac) a UTF8 encoded Java source code with a BOM
body: <p>Hello and thank you for reading my post.</p>
  
  <p>My problem is the following: I want to compile a Java source file with "javac" with this file being UTF-8 encoded with a BOM (the OS is WinXP).</p>
  
  <p>Below is what I do:</p>
  
  <p>1) Create a file with "Notepad" and choose the UTF-8 encoding</p>
  
  <pre><code>dos&gt; notepad Test.java
  "File -&gt; Save as..."
  File name   : Test.java
  Save as type: All Files
  Encoding    : UTF-8
  Save
  </code></pre>
  
  <p>2) Create a Java class in that file and saved the file like in 1)</p>
  
  <pre><code>public class Test
  {
      public static void main(String [] args)
      {
          System.out.println("This is a test.");
      }
  }
  </code></pre>
  
  <p>3) Visualize the hexadecimal version of the file (first line)</p>
  
  <pre><code>dos&gt; xxd Test.java | head -1
  0000000: efbb bf70 7562 6c69 6320 636c 6173 7320  ...public class
  </code></pre>
  
  <p>Note:
  <strong>ef bb bf</strong> is the UTF-8 encoded BOM (the UTF-16 encoded BOM being <strong>FE FF</strong>).</p>
  
  <p>4) Try to compile this code with "javac"</p>
  
  <pre><code>dos&gt; javac -encoding utf8 Test.java
  Test.java:1: illegal character: \65279
  ?public class Test
  ^
  1 error
  </code></pre>
  
  <p>Note: <strong>65279</strong> is the decimal version of the BOM.</p>
  
  <p>My question is the following: how can I make this compiling work with:</p>
  
  <ul>
  <li>keeping it UTF-8 encoded  </li>
  <li>and keeping the BOM?</li>
  </ul>
  
  <p>Thank you for helping and best regards.</p>
  
  <p>Léa</p>