title: Why will byte not take 0xff in java?
body: <p>Why will java compiler not let me put <code>0xff</code> into a <code>byte</code>, <code>0xff</code> is 8 bits long which is just the size of <code>byte</code> datatype.
  <br><br> <em>Can someone explain why 1 works and why 2 does not ?</em></p>
  
  <pre><code>class a
  {
          public static void main(String[] args)
          {
                  // 1 :: results in error
                  byte a = 0xff;          
                  System.out.printf("%x\n",a);
  
                  //2 :: works fine
                  byte a = (int)0xff              
                  System.out.printf("%x\n",a);
          }
  }
  </code></pre>
  
  <p><strong>EDIT</strong> I read the answer claiming that 0xff is 255, how so ? Is it not <code>1111 1111</code>, What makes 0xff, -128 or 255 or anything for that matter. Why will it not just treat it as <code>1111 1111</code> and not the 8 bits of that byte to 1.</p>